note 56872 deleted from function.rand by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.