generate 3 random (not same) numbers within 1 to 20
Posted: Thu Jan 08, 2009 1:30 am
i need to generate 3 number like 4,15,19 or 17,01,11 the numbers should not be same
can any one help me?
can any one help me?
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
function GetRandomNrs( $min=1, $max=20, $num=3 )
{
if ($num > $max-$min+1) $num = $max-$min+1;
$result = array();
for ($i=0; $i<$num; $i++)
{
do
{
$x = mt_rand($min,$max);
}
while (in_array($x,$result));
$result[] = $x;
}
return $result;
}