note 31579 added to function.rand
| From: | wicked_wesley at atari dot nl | Date: | Sat, 26 Apr 2003 20:17:35 +0000 |
| Subject: | note 31579 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47150@lists.php.net to get a copy of this message | ||
You can easy make a large random number, with a small function. Here it goes:
<?php
function randomNr($number)
{
if($number)
{
for($i=1;$i<=$number;$i++)
{
$nr=rand(0,9);
$total=$total.$nr;
}
return $total;
}
}
?>
Just call this function like this:
randomNr(some_number);
Example:
$random=randomNr(4);
returns a number between 0 and 9999
$random=randomNr(6);
returns a number between 0 and 999999
$random=randomNr(9999);
This does work and pretty fast too, too long to post :)
Hope it helps,
Wesley
--
http://www.php.net/manual/en/function.rand.php
http://master.php.net/manage/user-notes.php?action=edit+31579
http://master.php.net/manage/user-notes.php?action=delete+31579
http://master.php.net/manage/user-notes.php?action=reject+31579