note 23131 deleted from function.mt-rand by bjori

From: Date: Sun, 16 Apr 2006 12:09:27 +0000
Subject: note 23131 deleted from function.mt-rand by bjori
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-108249@lists.php.net to get a copy of this message
Note Submitter: rugby at flipp dot net ---- Just a small note for those zealots who want to avoid overseeding (which reduces randomness). I have this small function to solve to get the best of both worlds: (note the global variable) ---------------- $already_random = false; function mt_seed(){ global $already_random; if ($already_random) { list($usec, $sec) = explode(' ', microtime()); mt_srand((float) $sec + ((float) $usec * 100000);); } $already_random=true; } mt_seed(); $dice=mt_rand(1,6); ---------------- dead easy of course, but it might help some people. If you are not sure what everybody is on about on this page, you can use this funtion (+global variable!) instead of make_seed(). Its a little better.

« previous php.notes (#108249) next »