Hi, I am looking for a way to display two random images from the same directory, on the same page, but of course, I want them to be different.
I looked for random numbers not the same, and found this snippet by skiflyer.
I can determine the number of files in the directory, but cannot plug them into the snippet here.
eg $images = sizeof($filelist)-1;
and I tried putting $max=$images in as follows
function random_nums($x=10, $min=0, $max=$images) {
but it won't work. Can you explain why?
<?
function random_nums($x=10, $min=0, $max=10000) {
$list_of_nums = array();
for($i=0;$i<$x;$i++) {
$temp=mt_rand($min,$max);
while(in_array($temp, $list_of_nums)) {
$temp=mt_rand($min,$max);
}
$list_of_nums[]=$temp;
}
return $list_of_nums;
}
$list_of_nums = random_nums();
foreach($list_of_nums as $num) {
echo "$num<BR>";
}
?>
I looked for random numbers not the same, and found this snippet by skiflyer.
I can determine the number of files in the directory, but cannot plug them into the snippet here.
eg $images = sizeof($filelist)-1;
and I tried putting $max=$images in as follows
function random_nums($x=10, $min=0, $max=$images) {
but it won't work. Can you explain why?
<?
function random_nums($x=10, $min=0, $max=10000) {
$list_of_nums = array();
for($i=0;$i<$x;$i++) {
$temp=mt_rand($min,$max);
while(in_array($temp, $list_of_nums)) {
$temp=mt_rand($min,$max);
}
$list_of_nums[]=$temp;
}
return $list_of_nums;
}
$list_of_nums = random_nums();
foreach($list_of_nums as $num) {
echo "$num<BR>";
}
?>