note 64106 added to function.array-rand
| From: | vitor dot mattos at gmail dot com | Date: | Fri, 07 Apr 2006 14:51:44 +0000 |
| Subject: | note 64106 added to function.array-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-107516@lists.php.net to get a copy of this message | ||
<?php
// generate randon number without repeating
function unique_rand($min, $max){
static $excessoes=array();
srand((float) microtime() * 10000000);
$num=rand($min, $max);
if(in_array($num, $excessoes)) $num = unique_rand($min, $max);
$excessoes[]=$num;
return $num;
}
// debuggin
for($i=0;$i<=5;$i++) {
echo unique_rand(0, 5)."<br>";
}
?>
----
Server IP: 200.185.109.101
Probable Submitter: 200.196.56.34
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/function.array-rand.php
Edit -- http://master.php.net/note/edit/64106
Del: integrated -- http://master.php.net/note/delete/64106/integrated
Del: useless -- http://master.php.net/note/delete/64106/useless
Del: bad code -- http://master.php.net/note/delete/64106/bad+code
Del: spam -- http://master.php.net/note/delete/64106/spam
Del: non-english -- http://master.php.net/note/delete/64106/non-english
Del: in docs -- http://master.php.net/note/delete/64106/in+docs
Del: other reasons-- http://master.php.net/note/delete/64106
Reject -- http://master.php.net/note/reject/64106
Search -- http://master.php.net/manage/user-notes.php