Changeset 8728 for trunk/wp-includes/pluggable.php
- Timestamp:
- 08/25/2008 05:52:28 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/wp-includes/pluggable.php
r8701 r8728 1352 1352 $password = ''; 1353 1353 for ( $i = 0; $i < $length; $i++ ) 1354 $password .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);1354 $password .= substr($chars, wp_rand(0, strlen($chars) - 1), 1); 1355 1355 return $password; 1356 } 1357 endif; 1358 1359 if ( !function_exists('wp_rand') ) : 1360 /** 1361 * Generates a random number 1362 * 1363 * @since 2.6.2 1364 * 1365 * @param int $min Lower limit for the generated number (optional, default is 0) 1366 * @param int $max Upper limit for the generated number (optional, default is 4294967295) 1367 * @return int A random number between min and max 1368 */ 1369 function wp_rand( $min = 0, $max = 0 ) { 1370 global $rnd_value; 1371 1372 $seed = get_option('random_seed'); 1373 1374 // Reset $rnd_value after 14 uses 1375 // 32(md5) + 40(sha1) + 40(sha1) / 8 = 14 random numbers from $rnd_value 1376 if ( strlen($rnd_value) < 8 ) { 1377 $rnd_value = md5( uniqid(microtime() . mt_rand(), true ) . $seed ); 1378 $rnd_value .= sha1($rnd_value); 1379 $rnd_value .= sha1($rnd_value . $seed); 1380 $seed = md5($seed . $rnd_value); 1381 update_option('random_seed', $seed); 1382 } 1383 1384 // Take the first 8 digits for our value 1385 $value = substr($rnd_value, 0, 8); 1386 1387 // Strip the first eight, leaving the remainder for the next call to wp_rand(). 1388 $rnd_value = substr($rnd_value, 8); 1389 1390 $value = abs(hexdec($value)); 1391 1392 // Reduce the value to be within the min - max range 1393 // 4294967295 = 0xffffffff = max random number 1394 if ( $max != 0 ) 1395 $value = $min + (($max - $min + 1) * ($value / (4294967295 + 1))); 1396 1397 return abs(intval($value)); 1356 1398 } 1357 1399 endif;
Note: See TracChangeset
for help on using the changeset viewer.