I wrote this php code
<?php
echo "<pre>";
$rand=range(1,200);
$arr=array();
print_r($arr);
for($i=0;$i<20;$i++)
{ array_push($arr, array_rand*$rand));
}
print_($arr);
?>
this will print 20 numbers randomly. but now i want to make sure that the random numbers dont repeat themselves. please tell me how to write a function here which will check that the random numbers are not repeating.
please help me
thankyou.
Is this program correct,i wrote a function here to check that the values dont repeat. if its not correct then please help me with the function.
<?php
$rand=range(1,200);
$arr=array();
print_r($arr);
function call()
{
$x=random_nmbers;
if($arr!=$x)
{
array_push;
}
}
for($i=0;$i<20;$i++)
{
array_push($arr, array_rand($rand));
call();
}
echo"<pre>";
sort($arr);
print_r($arr);
?>
Helm me with a function
Moderator: General Moderators
Re: Helm me with a function
Code: Select all
function randomArray()
{
$numbers = array();
while (count($numbers) < 20)
{
$x = rand(1, 200);
if (!in_array($x, $numbers))
{
$numbers[] = $x;
}
}
return $numbers;
}Re: Helm me with a function
thankyou so much 