Okay, basically I am making a script that will search a random folder, find out how many MIDIs are in that folder (the MIDIs are named 01.mid, 02.mid etc) then generate a random number to decide which midi to play.
The problem is that some MIDIs are missing, so it will be like
01.mid
02.mid
04.mid
07.mid
08.mid
etc... so in this random number I have to take into account that there are some numbers I need to exclude. This is what I currently have:
srand(time());
$rancd = (rand()%4)+1;
$num = 0;
$end = 0;
do {
$num++;
if ($num < 10) $num = "0".$num;
if (file_exists("media/".$rootid."/music/midi/cd".$rancd."/".$num.".mid")) $last = $num;
else $end++;
} while ($end < 6);
$num = $num - 1;
do {
srand(time());
$random = (rand()%$last)+1;
if ($random < 10) $random = "0".$random;
} while (file_exists("media/".$rootid."/music/midi/cd".$rancd."/".$random.".mid") == FALSE);
$song = ("media/".$rootid."/music/midi/cd".$rancd."/".$random.".mid");
Basically this is taking way too long to load, and its not very efficient.
so I was thinking in my loop where it checks all the MIDIs in the folder, I could make a variable $file[$num] and set each slot to a boolean value of 1 if it exists, and 0 if it doesnt.
But then in the random I'd have to somehow figure out how to make it disclude all the values assigned to 0
Any help? any better ideas?