note 54433 added to function.rand
| From: | CorryGellatlyncl dot ac dot uk at osu1 dot php dot net | Date: | Mon, 04 Jul 2005 15:17:16 +0000 |
| Subject: | note 54433 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-91426@lists.php.net to get a copy of this message | ||
I've used this script to generate an array of random numbers with a numeric key. I got an array
of over 200,000 on this system, and got <1000 using the examples submitted previously. I
haven't managed to return the array variable outside the function, but have written it to a
database.
<?php
function rand_array($start, $end, $rangemin, $rangemax)
{
$array = array_fill($start, $end, 1);
foreach($array as $key => $value)
{
$value = rand($rangemin,$rangemax);
print "$key: $value<br>\n";
}
}
$start = 1;
$end = 1000;
$rangemin = 1;
$rangemax = 20000;
rand_array($start, $end, $rangemin, $rangemax);
?>
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+54433
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54433&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54433&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54433&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54433&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54433&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54433&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+54433&report=yes
Search -- http://master.php.net/manage/user-notes.php