Hi all,
I´m making this PHP script for a client and have this problem. I need to make a script that randomly grabs 50 numbers from 1 to 150 without duplicate values. So I thought about something like this
The problem is that, although I receive randomly generated numbers, I always get the same number sequence (141 42 134 22 113...). Script can be found here. How can I solve this problem?. Thanks in advance.PHP Code:header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
function random($sel=50,$de=150){
$pregs=Array();
for($x=1;$x<=$sel;$x){
$pregnum=rand(1,$de);
while(!in_array($pregnum,$pregs)){
$pregs[]=$pregnum;
$x++;
}
}
for($x=0;$x<=count($pregs);$x++){
echo "$pregs[$x] ";
}
}
random();




Bookmarks