]> granicus.if.org Git - php/commitdiff
Remove RAND_RANGE() macro
authorTom Van Looy <tom@ctors.net>
Sun, 3 Dec 2017 21:35:50 +0000 (22:35 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 9 Dec 2017 16:24:17 +0000 (17:24 +0100)
The behavior of RANGE_RANGE() is 7.1 changed completely, from
rescaling an already generated number to generating a number
itself. Because of this str_shuffle() ended up generating two
random numbers on every iteration.

To avoid further misuse the function is dropped entirely. Extensions
for PHP >= 7.1 should directly call php_mt_rand_range().

UPGRADING.INTERNALS
ext/standard/array.c
ext/standard/php_rand.h
ext/standard/string.c

index 7dce0fb731fb4bfbce404356f29ccfad5a4d64e3..c5a41f2198833d9ef060946495a244b40b40e582 100644 (file)
@@ -9,6 +9,7 @@ PHP 7.3 INTERNALS UPGRADE NOTES
   f. GC_REFCOUNT()
   g. zend_get_parameters()
   h. zend_register_persistent_resource()
+  i. RAND_RANGE()
 
 2. Build system changes
   a. Unix build system changes
@@ -82,6 +83,9 @@ PHP 7.3 INTERNALS UPGRADE NOTES
      zend_register_persistent_resource_ex() should beused to register
      persistent resources, instead of manual insertion into EG(persistent_list).
 
+  i. The RANGE_RANGE() macro has been removed. php_mt_rand_range() should be
+     used instead.
+
 ========================
 2. Build system changes
 ========================
index dfeaef87475b1e2198b86fb0b54a95cb8e72ee88..05c89d901b0946d5b15b28b936edd489a92c6c4d 100644 (file)
@@ -2968,7 +2968,7 @@ static void php_array_data_shuffle(zval *array) /* {{{ */
                        }
                }
                while (--n_left) {
-                       RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
+                       rnd_idx = php_mt_rand_range(0, n_left);
                        if (rnd_idx != n_left) {
                                temp = hash->arData[n_left];
                                hash->arData[n_left] = hash->arData[rnd_idx];
@@ -2993,7 +2993,7 @@ static void php_array_data_shuffle(zval *array) /* {{{ */
                        }
                }
                while (--n_left) {
-                       RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
+                       rnd_idx = php_mt_rand_range(0, n_left);
                        if (rnd_idx != n_left) {
                                temp = hash->arData[n_left];
                                hash->arData[n_left] = hash->arData[rnd_idx];
index b4a6613bee02aa8a96dce34ef4d3155a69959d3e..497a539e4e9d6579c2ca7edd02139d30f26ff7d4 100644 (file)
@@ -63,9 +63,6 @@
 #define RAND_RANGE_BADSCALING(__n, __min, __max, __tmax) \
        (__n) = (__min) + (zend_long) ((double) ( (double) (__max) - (__min) + 1.0) * ((__n) / ((__tmax) + 1.0)))
 
-#define RAND_RANGE(__n, __min, __max, __tmax) \
-       (__n) = php_mt_rand_range((__min), (__max))
-
 #ifdef PHP_WIN32
 #define GENERATE_SEED() (((zend_long) (time(0) * GetCurrentProcessId())) ^ ((zend_long) (1000000.0 * php_combined_lcg())))
 #else
index 1ef96e9132c9a34fa1a94c1e7a7f670c827aef39..2526dae144f590327320771228d897e1d6cc6ff3 100644 (file)
@@ -5479,8 +5479,7 @@ static void php_string_shuffle(char *str, zend_long len) /* {{{ */
        n_left = n_elems;
 
        while (--n_left) {
-               rnd_idx = php_rand();
-               RAND_RANGE(rnd_idx, 0, n_left, PHP_RAND_MAX);
+               rnd_idx = php_mt_rand_range(0, n_left);
                if (rnd_idx != n_left) {
                        temp = str[n_left];
                        str[n_left] = str[rnd_idx];