|
Posted by Rik on 07/17/06 20:10
AP wrote:
> Hello
> Any suggestions on the most efficient way to generate a random number
> from a range that will not return values specified in an array?
Euhm, I am not really sure what you mean. Like this?
For integers:
function
rand_number_without_certain_values_for_some_reason($start,$end,$not){
$i = 0;
do{
$i++;
if($i > 5000) return false;
$int = mt_renc($start,$end);
} while (is_array($not) && in_array($int,$not));
return $int;
}
Had to build in safety (the $i) to avoid endless looping when using
something like (1,4,array(range(1,4)))
Grtz,
--
Rik Wasmus
Navigation:
[Reply to this message]
|