2006-10-30, 08:04 AM
Here's a nifty function that comes handy every now and then. It generates X number of random numbers, ranging from A to B, but with no duplicates. PHP's rand() produces more duplicates than anything
Quote:// php
// $vinoth = number of 'numbers' to generate
// $tikitiki = start of range
// $mybb = end of range
function get_rand($vinoth, $tikitiki, $mybb) {
$rand = array();
$rand_temp = array();
while(count($rand) < $vinoth) {
$temp = rand($tikitiki, $mybb);
if(!isset($rand_temp[$temp])) {
$rand_temp[$temp] = true;
$rand[] = $temp;
}
}
return $rand;
}