note 33102 added to function.mt-rand

From: Date: Tue, 17 Jun 2003 00:14:51 +0000
Subject: note 33102 added to function.mt-rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-50449@lists.php.net to get a copy of this message
/* This function return a gaussian distribution of floating-point * numbers. This implementation is recommenden by D. Knuth, but due * originally to Marsaglia. * * Taken from the Comp.lang.c FAQ, maintained by Steve Summit. * ported to php from c by Joel De Gan * http://lucifer.intercosmos.net */ function gaussrand(){ #static double V1, V2, S; $phase = 0; #double X; if (phase == 0) { while ($S >= 1 || $S == 0){ $U1 = (double) rand() / 2147483647; $U2 = (double) rand() / 2147483647; $V1 = 2 * $U1 - 1; $V2 = 2 * $U2 - 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+33102 Delete Note -- http://master.php.net/manage/user-notes.php?action=delete+33102&report=yes Reject Note -- http://master.php.net/manage/user-notes.php?action=reject+33102&report=yes

« previous php.notes (#50449) next »