note 23131 added to function.mt-rand

From: Date: Wed, 10 Jul 2002 13:03:38 +0000
Subject: note 23131 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-32834@lists.php.net to get a copy of this message
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. -- http://www.php.net/manual/en/function.mt-rand.php http://master.php.net/manage/user-notes.php?action=edit+23131 http://master.php.net/manage/user-notes.php?action=delete+23131 http://master.php.net/manage/user-notes.php?action=reject+23131

« previous php.notes (#32834) next »