note 39859 added to function.rand
| From: | greensleeves13 at hotmail dot com | Date: | Fri, 13 Feb 2004 05:00:05 +0000 |
| Subject: | note 39859 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-65078@lists.php.net to get a copy of this message | ||
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?
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+39859
Delete -- http://master.php.net/manage/user-notes.php?action=delete+39859&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+39859&report=yes
Search -- http://master.php.net/manage/user-notes.php