note 50015 deleted from function.rand by felipe

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
Note Submitter: phpdeveloper AT o2 DOT pl 

----

This is most simple random array generator, hope zo ;-)
Moreover it uses some PHP array features :-), and does not search through array haystack, just checks for data if its set :P.

<?php

function GetRandomArray($min,$max,$num) {
	
	#data check
	$range = 1 + $max + $min;
	if ($num > $range) return false;
	if ($num < 1) return false;
	
	#data prep
	$result = array();
	$a = rand($min,$max);
	$result[$a] = $a;
	
	#loop me baby ;-)
	while(count($result) < $num) {
		do {$a = rand($min,$max); } while(isset($result[$a]));
		$result[$a] = $a;
	}
	
	return $result;
}

var_dump(GetRandomArray(3,10,5));
?>

nice coding 4 U all :-)
[k3oGH]
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.