Changeset 53473 for trunk/src/wp-includes/pluggable.php
- Timestamp:
- 06/06/2022 10:48:21 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r53472 r53473 2597 2597 * @since 2.6.2 2598 2598 * @since 4.4.0 Uses PHP7 random_int() or the random_compat library if available. 2599 * @since 6.1.0 Returns zero instead of a random number if both `$min` and `$max` are zero. 2599 2600 * 2600 2601 * @global string $rnd_value 2601 2602 * 2602 * @param int $min Lower limit for the generated number. 2603 * @param int $max Upper limit for the generated number. 2603 * @param int $min Optional. Lower limit for the generated number. 2604 * Accepts positive integers or zero. Defaults to 0. 2605 * @param int $max Optional. Upper limit for the generated number. 2606 * Accepts positive integers. Defaults to 4294967295. 2604 2607 * @return int A random number between min and max. 2605 2608 */ 2606 function wp_rand( $min = 0, $max = 0) {2609 function wp_rand( $min = null, $max = null ) { 2607 2610 global $rnd_value; 2608 2611 … … 2610 2613 // truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats. 2611 2614 $max_random_number = 3000000000 === 2147483647 ? (float) '4294967295' : 4294967295; // 4294967295 = 0xffffffff 2615 2616 if ( null === $min ) { 2617 $min = 0; 2618 } 2619 2620 if ( null === $max ) { 2621 $max = $max_random_number; 2622 } 2612 2623 2613 2624 // We only handle ints, floats are truncated to their integer value. … … 2619 2630 if ( $use_random_int_functionality ) { 2620 2631 try { 2621 $_max = ( 0 != $max ) ? $max : $max_random_number;2622 2632 // wp_rand() can accept arguments in either order, PHP cannot. 2623 $_max = max( $min, $ _max );2624 $_min = min( $min, $ _max );2633 $_max = max( $min, $max ); 2634 $_min = min( $min, $max ); 2625 2635 $val = random_int( $_min, $_max ); 2626 2636 if ( false !== $val ) { … … 2662 2672 2663 2673 // Reduce the value to be within the min - max range. 2664 if ( 0 != $max ) { 2665 $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); 2666 } 2674 $value = $min + ( $max - $min + 1 ) * $value / ( $max_random_number + 1 ); 2667 2675 2668 2676 return abs( (int) $value );
Note: See TracChangeset
for help on using the changeset viewer.