From: <var...@us...> - 2014-10-03 14:19:34
|
Revision: 9172 http://sourceforge.net/p/phpwiki/code/9172 Author: vargenau Date: 2014-10-03 14:19:30 +0000 (Fri, 03 Oct 2014) Log Message: ----------- As of PHP 4.2.0, there is no need to seed the random number generator with srand() or mt_srand() as this is now done automatically. Modified Paths: -------------- trunk/configurator.php trunk/lib/Captcha.php trunk/lib/WikiUser/HttpAuth.php trunk/lib/WikiUser/HttpAuthUpper.php trunk/lib/fortune.php trunk/lib/plugin/ModeratedPage.php trunk/lib/plugin/RandomPage.php trunk/lib/stdlib.php trunk/passencrypt.php trunk/themes/Hawaiian/lib/random.php Modified: trunk/configurator.php =================================================================== --- trunk/configurator.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/configurator.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -105,7 +105,6 @@ if (!isset($_SERVER)) $_SERVER =& $GLOBALS['HTTP_SERVER_VARS']; // maybe we should random the realm to really force a logout. but the next login will fail. - // better_srand(); $realm = microtime().rand(); header('WWW-Authenticate: Basic realm="' . WIKI_NAME . '"'); if (strstr(php_sapi_name(), 'apache')) header('HTTP/1.0 401 Unauthorized'); @@ -2518,7 +2517,6 @@ $valid_chars = "!#%&+-.0123456789=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"; $start = ord($valid_chars); $end = ord(substr($valid_chars, -1)); - better_srand(); $length = mt_rand($minlength, $maxlength); while ($length > 0) { $newchar = mt_rand($start, $end); Modified: trunk/lib/Captcha.php =================================================================== --- trunk/lib/Captcha.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/lib/Captcha.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -95,7 +95,6 @@ // Pick a Word $word = ""; - better_srand(); while (strlen(trim($word)) == 0) { $x = mt_rand(0, count($text)); return $text[$x]; Modified: trunk/lib/WikiUser/HttpAuth.php =================================================================== --- trunk/lib/WikiUser/HttpAuth.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/lib/WikiUser/HttpAuth.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -74,7 +74,6 @@ $_SERVER =& $GLOBALS['HTTP_SERVER_VARS']; // Maybe we should random the realm to really force a logout. // But the next login will fail. - // better_srand(); $realm = microtime().rand(); // TODO: On AUTH_TYPE=NTLM this will fail. Only Basic supported so far. header('WWW-Authenticate: Basic realm="' . WIKI_NAME . '"'); if (strstr(php_sapi_name(), 'apache')) Modified: trunk/lib/WikiUser/HttpAuthUpper.php =================================================================== --- trunk/lib/WikiUser/HttpAuthUpper.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/lib/WikiUser/HttpAuthUpper.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -78,7 +78,6 @@ $_SERVER =& $GLOBALS['HTTP_SERVER_VARS']; // Maybe we should random the realm to really force a logout. // But the next login will fail. - // better_srand(); $realm = microtime().rand(); // TODO: On AUTH_TYPE=NTLM this will fail. Only Basic supported so far. header('WWW-Authenticate: Basic realm="' . WIKI_NAME . '"'); if (strstr(php_sapi_name(), 'apache')) Modified: trunk/lib/fortune.php =================================================================== --- trunk/lib/fortune.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/lib/fortune.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -36,7 +36,6 @@ } } - srand((double)microtime() * 1000000); $index = rand(0, $amount); $i = 0; Modified: trunk/lib/plugin/ModeratedPage.php =================================================================== --- trunk/lib/plugin/ModeratedPage.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/lib/plugin/ModeratedPage.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -200,7 +200,6 @@ function generateId() { - better_srand(); $s = ""; for ($i = 1; $i <= 25; $i++) { $r = mt_rand(55, 90); Modified: trunk/lib/plugin/RandomPage.php =================================================================== --- trunk/lib/plugin/RandomPage.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/lib/plugin/RandomPage.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -77,7 +77,6 @@ $allpages = $dbi->getAllPages(false, $sortby, $limit, $exclude); $pagearray = $allpages->asArray(); - better_srand(); // Start with a good seed. if (($numpages == 1) && $pagearray) { $page = $pagearray[array_rand($pagearray)]; Modified: trunk/lib/stdlib.php =================================================================== --- trunk/lib/stdlib.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/lib/stdlib.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -67,7 +67,6 @@ can ($object, $method) function_usable ($function_name) wikihash ($x) - better_srand ($seed = '') count_all ($arg) isSubPage ($pagename) subPageSlice ($pagename, $pos) @@ -1616,29 +1615,8 @@ return false; } -/** - * Seed the random number generator. - * - * better_srand() ensures the randomizer is seeded only once. - * - * How random do you want it? See: - * http://www.php.net/manual/en/function.srand.php - * http://www.php.net/manual/en/function.mt-srand.php - */ -function better_srand($seed = '') -{ - static $wascalled = FALSE; - if (!$wascalled) { - $seed = $seed === '' ? (double)microtime() * 1000000 : $seed; - function_exists('mt_srand') ? mt_srand($seed) : srand($seed); - $wascalled = TRUE; - //trigger_error("new random seed", E_USER_NOTICE); //debugging - } -} - function rand_ascii($length = 1) { - better_srand(); $s = ""; for ($i = 1; $i <= $length; $i++) { // return only typeable 7 bit ascii, avoid quotes @@ -1653,7 +1631,6 @@ { // Pick a few random letters or numbers $word = ""; - better_srand(); // Don't use 1lI0O, because they're hard to read $letters = "abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"; $letter_len = strlen($letters); Modified: trunk/passencrypt.php =================================================================== --- trunk/passencrypt.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/passencrypt.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -26,38 +26,8 @@ <body> <h1>Password Encryption Tool</h1> <?php -/** - * Seed the random number generator. - * - * better_srand() ensures the randomizer is seeded only once. - * - * How random do you want it? See: - * http://www.php.net/manual/en/function.srand.php - * http://www.php.net/manual/en/function.mt-srand.php - */ -function better_srand($seed = '') -{ - static $wascalled = FALSE; - if (!$wascalled) { - if ($seed === '') { - list($usec, $sec) = explode(" ", microtime()); - if ($usec > 0.1) - $seed = (double)$usec * $sec; - else // once in a while use the combined LCG entropy - $seed = (double)1000000 * substr(uniqid("", true), 13); - } - if (function_exists('mt_srand')) { - mt_srand($seed); // mersenne twister - } else { - srand($seed); - } - $wascalled = TRUE; - } -} - function rand_ascii($length = 1) { - better_srand(); $s = ""; for ($i = 1; $i <= $length; $i++) { // return only typeable 7 bit ascii, avoid quotes @@ -78,7 +48,6 @@ $valid_chars = "!#%&+-.0123456789=@ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz"; $start = ord($valid_chars); $end = ord(substr($valid_chars, -1)); - better_srand(); $length = mt_rand($minlength, $maxlength); while ($length > 0) { $newchar = mt_rand($start, $end); Modified: trunk/themes/Hawaiian/lib/random.php =================================================================== --- trunk/themes/Hawaiian/lib/random.php 2014-10-03 14:11:26 UTC (rev 9171) +++ trunk/themes/Hawaiian/lib/random.php 2014-10-03 14:19:30 UTC (rev 9172) @@ -26,7 +26,6 @@ function pickRandom() { - better_srand(); // Start with a good seed. $this->filename = $this->imageList[array_rand($this->imageList)]; //trigger_error(sprintf(_("random image chosen: %s"), // $this->filename), This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |