note 39859 deleted from function.rand by didou
| From: | didou@php.net | Date: | Fri, 13 Feb 2004 08:51:17 +0000 |
| Subject: | note 39859 deleted from function.rand by didou | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-65084@lists.php.net to get a copy of this message | ||
Note Submitter: greensleeves13@hotmail.com
----
function frand ()
{
# returns a random 30-bit float
# workaround rand() which seems to manage only
# (0, 32767) on some systems
#
$onbitcount = rand(0, 30);
for ($i=0; $i<30; $i++) {
if ($onbitcount) {
if ((30-$i) > $onbitcount) {
$bit = rand(0, 1);
$onbitcount -= $bit;
$ranbits .= $bit;
} else {
$ranbits .= '1';
}
} else {
$ranbits .= '0';
}
}
return bindec($ranbits) / 1076741823;
}
think this will work out... any comments?