note 116830 added to function.mt-rand
| From: | Flashbond | Date: | Fri, 06 Mar 2015 08:34:31 +0000 |
| Subject: | note 116830 added to function.mt-rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-201869@lists.php.net to get a copy of this message | ||
A custom unique random generator class example:
<?php
class uniqueRandom {
private $rands = array();
function generate($i, $ii) {
while ($rand = mt_rand($i, $ii)) {
if (!in_array($rand, $this -> rands)) {
$this-> rands [] = $rand;
return $rand;
}
}
}
}
//Test
$myUnique = new uniqueRandom;
for ($i = 0; $i < 5; $i++) {
echo $myUnique -> generate(1, 10)." ";
}
//This will produce unique random numbers.
?>
----
Server IP: 72.52.91.14
Probable Submitter: 94.54.97.136
----
Manual Page -- http://php.net/manual/en/function.mt-rand.php
Edit -- https://master.php.net/note/edit/116830
Del: integrated -- https://master.php.net/note/delete/116830/integrated
Del: useless -- https://master.php.net/note/delete/116830/useless
Del: bad code -- https://master.php.net/note/delete/116830/bad+code
Del: spam -- https://master.php.net/note/delete/116830/spam
Del: non-english -- https://master.php.net/note/delete/116830/non-english
Del: in docs -- https://master.php.net/note/delete/116830/in+docs
Del: other reasons-- https://master.php.net/note/delete/116830
Reject -- https://master.php.net/note/reject/116830
Search -- https://master.php.net/manage/user-notes.php