note 95420 added to function.rand

From: Date: Sat, 02 Jan 2010 19:24:34 +0000
Subject: note 95420 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-164538@lists.php.net to get a copy of this message
Another way to create an array of random numbers where there are no identical numbers. ($n = number of random numbers to return in the array $min = minimum number $max = maximum number) <?php function uniqueRand($n, $min = 0, $max = null) { if($max === null) $max = getrandmax(); $array = range($min, $max); $return = array(); $keys = array_rand($array, $n); foreach($keys as $key) $return[] = $array[$key]; return $return; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 72.208.240.199 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/95420 Del: integrated -- https://master.php.net/note/delete/95420/integrated Del: useless -- https://master.php.net/note/delete/95420/useless Del: bad code -- https://master.php.net/note/delete/95420/bad+code Del: spam -- https://master.php.net/note/delete/95420/spam Del: non-english -- https://master.php.net/note/delete/95420/non-english Del: in docs -- https://master.php.net/note/delete/95420/in+docs Del: other reasons-- https://master.php.net/note/delete/95420 Reject -- https://master.php.net/note/reject/95420 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#164538) next »