note 91531 added to function.rand

From: Date: Mon, 15 Jun 2009 16:30:49 +0000
Subject: note 91531 added to function.rand
Groups: php.notes 
Request: Send a blank email to php-notes+get-156899@lists.php.net to get a copy of this message
A very easy method for generating for generating an array of UNIQUE random numbers: <?php $rand = array(); while (count($rand) < $total ) { $r = mt_rand($min,$max); if ( !in_array($r,$rand) ) { $rand[] = $r; } } ?> whereby $total is the number of unique random numbers you want, $min is the lowest possible value and $max is the highest possible value. ---- Server IP: 92.48.74.199 Probable Submitter: 92.238.100.139 ---- Manual Page -- http://www.php.net/manual/en/function.rand.php Edit -- https://master.php.net/note/edit/91531 Del: integrated -- https://master.php.net/note/delete/91531/integrated Del: useless -- https://master.php.net/note/delete/91531/useless Del: bad code -- https://master.php.net/note/delete/91531/bad+code Del: spam -- https://master.php.net/note/delete/91531/spam Del: non-english -- https://master.php.net/note/delete/91531/non-english Del: in docs -- https://master.php.net/note/delete/91531/in+docs Del: other reasons-- https://master.php.net/note/delete/91531 Reject -- https://master.php.net/note/reject/91531 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156899) next »