note 56872 deleted from function.rand by felipe

From: Date: Sun, 30 Dec 2007 18:44:10 +0000
Subject: note 56872 deleted from function.rand by felipe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-134430@lists.php.net to get a copy of this message
Note Submitter: nick at nerdynick dot com ---- Here is a function I wrote to generate an array with a unigue set of numbers in each place. You can enter the Min and the Max number to pick from and the number of array places to generate for. random_loop([# of Array Places], [Min], [Max]); <?php $cols = random_loop(9, 0, 9); function random_loop($num, $min, $max){ $rand[0] = mt_rand($min, $max); for($i = 1; $i<$num; $i++){ do{ $check = true; $rand[$i] = mt_rand($min, $max); for($ii = 0; $ii < (count($rand)-1); $ii++){ if($rand[$i] == $rand[$ii] && $check){ $check = false; break; } } }while (!$check); } return $rand; } ?> Enjoy and use at your will.

« previous php.notes (#134430) next »