From 02ea7c378cddda5106669d10dbb657e654e2a99f Mon Sep 17 00:00:00 2001 From: Russell Smith Date: Fri, 22 Nov 2013 11:34:23 +1100 Subject: [PATCH] MDL-41198 lib: Allow PHP to generate random seed on script start Most srand instances are removed to allow PHP to do the work. srand was left for group randomization due to the method used. Conflicts: lib/tests/accesslib_test.php --- auth/mnet/auth.php | 1 - lib/adodb/adodb.inc.php | 5 ----- lib/cronlib.php | 1 - lib/moodlelib.php | 2 -- lib/tests/accesslib_test.php | 8 +++----- 5 files changed, 3 insertions(+), 14 deletions(-) diff --git a/auth/mnet/auth.php b/auth/mnet/auth.php index db7328bd9f8..d1923736afa 100644 --- a/auth/mnet/auth.php +++ b/auth/mnet/auth.php @@ -950,7 +950,6 @@ class auth_plugin_mnet extends auth_plugin_base { // run the keepalive client $this->keepalive_client(); - // admin/cron.php should have run srand for us $random100 = rand(0,100); if ($random100 < 10) { // Approximately 10% of the time. // nuke olden sessions diff --git a/lib/adodb/adodb.inc.php b/lib/adodb/adodb.inc.php index d0c2695f62e..11b5ef20d3a 100644 --- a/lib/adodb/adodb.inc.php +++ b/lib/adodb/adodb.inc.php @@ -169,11 +169,6 @@ die("Illegal path http:// or ftp://"); } - - // Initialize random number generator for randomizing cache flushes - // -- note Since PHP 4.2.0, the seed becomes optional and defaults to a random value if omitted. - srand(((double)microtime())*1000000); - /** * ADODB version as a string. */ diff --git a/lib/cronlib.php b/lib/cronlib.php index 0e7bbe148ac..e2c188a669e 100644 --- a/lib/cronlib.php +++ b/lib/cronlib.php @@ -67,7 +67,6 @@ function cron_run() { // Run cleanup core cron jobs, but not every time since they aren't too important. // These don't have a timer to reduce load, so we'll use a random number // to randomly choose the percentage of times we should run these jobs. - srand ((double) microtime() * 10000000); $random100 = rand(0,100); if ($random100 < 20) { // Approximately 20% of the time. mtrace("Running clean-up tasks..."); diff --git a/lib/moodlelib.php b/lib/moodlelib.php index a0d3bd352c3..041d3a3b7d9 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -9720,7 +9720,6 @@ function unformat_float($locale_float, $strict = false) { */ function swapshuffle($array) { - srand ((double) microtime() * 10000000); $last = count($array) - 1; for ($i=0;$i<=$last;$i++) { $from = rand(0,$last); @@ -9760,7 +9759,6 @@ function swapshuffle_assoc($array) { * @return array */ function draw_rand_array($array, $draws) { - srand ((double) microtime() * 10000000); $return = array(); diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index 442f9f09abc..4d431a5fcda 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2016,12 +2016,10 @@ class accesslib_testcase extends advanced_testcase { $userids = array_slice($userids, 0, 5); } - // Random time! - //srand(666); - foreach($userids as $userid) { // no guest or deleted - // each user gets 0-10 random roles + foreach ($userids as $userid) { // No guest or deleted. + // Each user gets 0-10 random roles. $rcount = rand(0, 10); - for($j=0; $j<$rcount; $j++) { + for ($j=0; $j<$rcount; $j++) { $roleid = $roles[rand(0, count($roles)-1)]; $contextid = $contexts[rand(0, count($contexts)-1)]->id; role_assign($roleid, $userid, $contextid);