Ticket #55194: 55194.diff
File 55194.diff, 2.2 KB (added by , 3 years ago) |
---|
-
src/wp-includes/pluggable.php
2533 2533 * 2534 2534 * @global string $rnd_value 2535 2535 * 2536 * @param int $min Lower limit for the generated number 2537 * @param int $max Upper limit for the generated number 2538 * @return int A random number between min and max 2536 * @param int $min Optional. Lower limit for the generated number. 2537 * Accepts positive integers or zero. Defaults to 0. 2538 * @param int $max Optional. Upper limit for the generated number. 2539 * Accepts positive integers. Defaults to 4294967295. 2540 * @return int A random number between min and max. 2539 2541 */ 2540 function wp_rand( $min = 0, $max = 0) {2542 function wp_rand( $min = null, $max = null ) { 2541 2543 global $rnd_value; 2542 2544 2543 2545 // Some misconfigured 32-bit environments (Entropy PHP, for example) … … 2544 2546 // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats. 2545 2547 $max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff 2546 2548 2549 if ( null === $min ) { 2550 $min = 0; 2551 } 2552 2553 if ( null === $max ) { 2554 $max = $max_random_number; 2555 } 2556 2547 2557 // We only handle ints, floats are truncated to their integer value. 2548 2558 $min = (int) $min; 2549 2559 $max = (int) $max; … … 2552 2562 static $use_random_int_functionality = true; 2553 2563 if ( $use_random_int_functionality ) { 2554 2564 try { 2555 $_max = ( 0 != $max ) ? $max : $max_random_number;2556 2565 // wp_rand() can accept arguments in either order, PHP cannot. 2557 $_max = max( $min, $ _max );2558 $_min = min( $min, $ _max );2566 $_max = max( $min, $max ); 2567 $_min = min( $min, $max ); 2559 2568 $val = random_int( $_min, $_max ); 2560 2569 if ( false !== $val ) { 2561 2570 return absint( $val ); … … 2595 2604 $value = abs( hexdec( $value ) ); 2596 2605 2597 2606 // Reduce the value to be within the min - max range. 2598 if ( 0 != $max ) { 2599 $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); 2600 } 2607 $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); 2601 2608 2602 2609 return abs( (int) $value ); 2603 2610 }