note 16986 deleted from function.mt-srand by jimw
| From: | jimw@php.net | Date: | Fri, 14 Dec 2001 19:19:14 +0000 |
| Subject: | note 16986 deleted from function.mt-srand by jimw | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-22637@lists.php.net to get a copy of this message | ||
You can use a combination of mt_rand(), array_push() and in_array() to get few unique randum numbers
out of small range of numbers ( eg: 1-10 ). Otherwise you would get dups when dealing with small
ranges.
<?php
function random_number($min, $max) {
return mt_rand($min, $max);
}
$wins = array();
while ( count ( $wins ) < 3 ) {
$value = random_number(1,10);
if (in_array($value, $wins)) {
continue;
}
array_push($wins, $value);
}
echo $wins[0]." ". $wins[1]. " ".$wins[2];
?>