Changeset 34981 for trunk/src/wp-includes/pluggable.php
- Timestamp:
- 10/09/2015 04:27:41 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/pluggable.php
r34947 r34981 2139 2139 * 2140 2140 * @since 2.6.2 2141 * @since 4.4 Uses PHP7 random_int() or the random_compat library if avaialble. 2141 2142 * 2142 2143 * @global string $rnd_value 2143 2144 * @staticvar string $seed 2145 * @staticvar bool $external_rand_source_available 2144 2146 * 2145 2147 * @param int $min Lower limit for the generated number … … 2149 2151 function wp_rand( $min = 0, $max = 0 ) { 2150 2152 global $rnd_value; 2153 2154 // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats. 2155 $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff 2156 2157 // We only handle Ints, floats are truncated to their integer value. 2158 $min = (int) $min; 2159 $max = (int) $max; 2160 2161 // Use PHP's CSPRNG, or a compatible method 2162 static $use_random_int_functionality = true; 2163 if ( $use_random_int_functionality ) { 2164 try { 2165 $_max = ( 0 != $max ) ? $max : $max_random_number; 2166 // wp_rand() can accept arguements in either order, PHP cannot. 2167 $_max = max( $min, $_max ); 2168 $_min = min( $min, $_max ); 2169 $val = random_int( $_min, $_max ); 2170 if ( false !== $val ) { 2171 return absint( $val ); 2172 } else { 2173 $use_random_int_functionality = false; 2174 } 2175 } catch ( Throwable $t ) { 2176 $use_random_int_functionality = false; 2177 } catch ( Exception $e ) { 2178 $use_random_int_functionality = false; 2179 } 2180 } 2151 2181 2152 2182 // Reset $rnd_value after 14 uses … … 2173 2203 2174 2204 $value = abs(hexdec($value)); 2175 2176 // Some misconfigured 32bit environments (Entropy PHP, for example) truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them to floats.2177 $max_random_number = 3000000000 === 2147483647 ? (float) "4294967295" : 4294967295; // 4294967295 = 0xffffffff2178 2205 2179 2206 // Reduce the value to be within the min - max range
Note: See TracChangeset
for help on using the changeset viewer.