note 49792 deleted from function.rand by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:42:12 +0000 |
| Subject: | note 49792 deleted from function.rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134406@lists.php.net to get a copy of this message | ||
Note Submitter: tech_niek at users dot sourceforge dot net
----
If you want to generate two +different+ random numbers in the same range:
<?
function fn_arrRandom($min, $max){
// generate two random numbers
$iRandom1 = rand($min, $max);
$iRandom2 = rand($min, $max);
// compare them
if ($iRandom1 !== $iRandom2){
// the numbers are different, great
} else {
// the numbers are equal, try again
return fn_arrRandom($min, $max);
}
return array($iRandom1, $iRandom2);
}
print_r(fn_arrRandom(3, 13));
?>
The above will output two different random numbers in an array:
Array ( [0] => 5 [1] => 7 )