note 85099 added to function.rand
| From: | szczepan | Date: | Thu, 14 Aug 2008 13:55:18 +0000 |
| Subject: | note 85099 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143497@lists.php.net to get a copy of this message | ||
Heres another function to generate Random Unique numbers.
<?
class UniqueRand{
var $alreadyExists = array();
function uRand($min = NULL, $max = NULL){
$break='false';
while($break=='false'){
$rand=mt_rand($min,$max);
if(array_search($rand,$this->alreadyExists)===false){
$this->alreadyExists[]=$rand;
$break='stop';
}else{
echo " $rand already! ";
print_r($this->alreadyExists);
}
}
return $rand;
}
}
$rand=new UniqueRand();
echo"<b> ". $rand->uRand(0,5)."</b>";
echo"<b> ". $rand->uRand(5,5)."</b>";
echo"<b> ". $rand->uRand(10,5)."</b>";
?>
----
Server IP: 217.13.201.10
Probable Submitter: 85.179.30.122
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- https://master.php.net/note/edit/85099
Del: integrated -- https://master.php.net/note/delete/85099/integrated
Del: useless -- https://master.php.net/note/delete/85099/useless
Del: bad code -- https://master.php.net/note/delete/85099/bad+code
Del: spam -- https://master.php.net/note/delete/85099/spam
Del: non-english -- https://master.php.net/note/delete/85099/non-english
Del: in docs -- https://master.php.net/note/delete/85099/in+docs
Del: other reasons-- https://master.php.net/note/delete/85099
Reject -- https://master.php.net/note/reject/85099
Search -- https://master.php.net/manage/user-notes.php