note 84734 added to ref.bc
| From: | vinni10 at gmx dot net | Date: | Mon, 28 Jul 2008 01:48:00 +0000 |
| Subject: | note 84734 added to ref.bc | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142837@lists.php.net to get a copy of this message | ||
Here is a better bcrand() version.
It uses the standart mt_rand() funktion and should work on other systems then unix ;-)
<?php
/**
* BCrand - Generates very big random numbers.
* string bcrand([mixed $min], mixed $max);
*/
function bcrand($min, $max=false)
{
if(!$max)
{
$max = $min;
$min = 0;
}
return bcadd(
bcmul(
bcdiv(
mt_rand(0, mt_getrandmax()),
mt_getrandmax(),
strlen($max)
),
bcsub(
bcadd($max,1),
$min
)
),
$min
);
}
echo bcrand("0", "9999999999999999999999999999999999999999999999999999999999");
?>
Hope i could help someone :-)
----
Server IP: 212.124.37.9
Probable Submitter: 92.193.14.76
----
Manual Page -- http://www.php.net/manual/en/ref.bc.php
Edit -- https://master.php.net/note/edit/84734
Del: integrated -- https://master.php.net/note/delete/84734/integrated
Del: useless -- https://master.php.net/note/delete/84734/useless
Del: bad code -- https://master.php.net/note/delete/84734/bad+code
Del: spam -- https://master.php.net/note/delete/84734/spam
Del: non-english -- https://master.php.net/note/delete/84734/non-english
Del: in docs -- https://master.php.net/note/delete/84734/in+docs
Del: other reasons-- https://master.php.net/note/delete/84734
Reject -- https://master.php.net/note/reject/84734
Search -- https://master.php.net/manage/user-notes.php