note 33803 added to function.mt-rand

From: Date: Tue, 08 Jul 2003 07:44:15 +0000
Subject: note 33803 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-51678@lists.php.net to get a copy of this message
This is a fixed version of the gaussrand() function defined in a note above. <?php function gaussrand() { static $V2, $V1, $S; static $phase = 0; if (phase == 0) { while ($S >= 1 || $S == 0) { $V1 = 2 * (rand() / getrandmax()) - 1; $V2 = 2 * (rand() / getrandmax()) - 1; $S = $V1 * $V1 + $V2 * $V2; } $X = $V1 * sqrt(-2 * log($S) / $S); } else $X = $V2 * sqrt(-2 * log($S) / $S); $phase = 1 - $phase; return $X; } ?> ---- Manual Page -- http://www.php.net/manual/en/function.mt-rand.php Edit Note -- http://master.php.net/manage/user-notes.php?action=edit+33803 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33803&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33803&report=yes

« previous php.notes (#51678) next »