note 73710 deleted from function.rand by felipe
| From: | felipe@php.net | Date: | Sun, 30 Dec 2007 18:45:36 +0000 |
| Subject: | note 73710 deleted from function.rand by felipe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-134450@lists.php.net to get a copy of this message | ||
Note Submitter: palmnet at gmail dot com
----
kurtubba's code was helpful, but didn't quite work for me.
Here's my version in case anyone has the same issue:
<?php
function UniqueRands($min, $max, $keys){
static $retval = array();
$x = rand($min,$max);
if(!in_array($x,$retval)){
array_push($retval, $x);
}
if($keys > count($retval)){
UniqueRands($min, $max, $keys);
}
return $retval;
}
$var = UniqueRands(1, 4, 4);
print_r($var);
?>
Bear in mind I'm not the best with php! But my version worked for me at least.