wp_rand [ WordPress Function ]
wp_rand ( $min = 0, $max = 0 )
| Parameters: |
|
| Returns: |
|
| Defined at: |
|
Generates a random number
Source
<?php
function wp_rand( $min = 0, $max = 0 ) {
global $rnd_value;
// Reset $rnd_value after 14 uses
// 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
if ( strlen($rnd_value) < 8 ) {
if ( defined( 'WP_SETUP_CONFIG' ) )
static $seed = '';
else
$seed = get_transient('random_seed');
$rnd_value = md5( uniqid(microtime() . mt_rand(), true ) . $seed );
$rnd_value .= sha1($rnd_value);
$rnd_value .= sha1($rnd_value . $seed);
$seed = md5($seed . $rnd_value);
if ( ! defined( 'WP_SETUP_CONFIG' ) )
set_transient('random_seed', $seed);
}
// Take the first 8 digits for our value
$value = substr($rnd_value, 0, 8);
// Strip the first eight, leaving the remainder for the next call to wp_rand().
$rnd_value = substr($rnd_value, 8);
$value = abs(hexdec($value));
// Reduce the value to be within the min - max range
// 4294967295 = 0xffffffff = max random number
if ( $max != 0 )
$value = $min + (($max - $min + 1) * ($value / (4294967295 + 1)));
return abs(intval($value));
}
?>
Examples [ wp-snippets.com ]
Google Arama Sonuçlarý
- Function Reference/wp rand « WordPress Codex
Function Reference/wp rand. Contents. 1 Description; 2 Parameters; 3 Return Values; 4 Change Log; 5 Source File. Description. Generates a random number ...
codex.wordpress.org - WordPress › wp_rand() for Entropy PHP « WordPress Plugins
Dec 15, 2011 ... On some 32bit hosts, the Entropy builds of PHP truncate integers larger than PHP_INT_MAX to PHP_INT_MAX rather than overflowing them as ...
wordpress.org - #19571 (wp_rand() can return a value outside the requested range ...
This can cause wp_rand() to return a value outside the requested range. That unexpected value in turn breaks wp_generate_password(), which can have ...
core.trac.wordpress.org - wp_rand (WordPress Function) - WPSeek.com
WordPress lookup for wp_rand, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com