note 50414 added to function.rand
| From: | ferconstantino at hotmail dot com | Date: | Sun, 27 Feb 2005 20:19:36 +0000 |
| Subject: | note 50414 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85644@lists.php.net to get a copy of this message | ||
RANDOM ARRAY (all different numbers)
This is a new version of a function published in this forum:
function GetRandomArray($min,$max,$num) {
#data check
$range = 1 + $max - $min;
if ($num > $range) return false;
if ($num < 1) return false;
#data prep
$result = array();
$count = 0;
$currentnum = 0;
#loop me baby ;-)
while(count($result) < $num) {
$currentnum = rand($min,$max);
if (!in_array($currentnum,$result)){
$result[$count] = $currentnum;
$count++;
}
}
return $result;
}
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50414
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50414&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50414&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50414&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50414&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50414&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50414&report=yes
Search -- http://master.php.net/manage/user-notes.php