Optimize wp_rand(), only check transient when needed. Fixes #12144.

git-svn-id: https://develop.svn.wordpress.org/trunk@13080 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Andrew Nacin 2010-02-13 03:33:33 +00:00
parent b154b4d604
commit 75a99f62cd
1 changed files with 1 additions and 2 deletions

View File

@ -1492,11 +1492,10 @@ if ( !function_exists('wp_rand') ) :
function wp_rand( $min = 0, $max = 0 ) {
global $rnd_value;
$seed = get_transient('random_seed');
// Reset $rnd_value after 14 uses
// 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value
if ( strlen($rnd_value) < 8 ) {
$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);