I'm working on code that should select randomly from a list of 20 stored videos (vidNum is the number video picked, and vidMax is the max number of possible videos), play that video, then select another random video from the list *that has not been played yet*. The way I'm trying to do this is: setup an array[20], set all status flags to 0 at the start (not played), pick randomly from the list, if the selected video has already been played, keep picking until you get one that hasn't been played. When all have been played, reset the array and start over.
It's not working. It's just playing the same video over and over, which is the exact opposite of what it's supposed to do. here's the relevant code:
func resetPlayed() // Reset the "played" status for all videos to 0
played[20] := [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
endfunc
func pickRandom() // Picks a random video but only plays each once until all in the sequence have been played
exitNow := 0;
while(exitNow := 0)
vidNum := ABS(RAND() % (vidMax-1));
vidNum := vidNum + 1;
if(vidNum >= (vidMax - 1))
vidNum := 0;
endif
if(played[vidNum] := 0) // This one hasn't ben played yet
exitNow := 1;
endif
wend
played[vidNum] := 1;
endfunc
In theory this looks to me like it should work-- any idea what's wrong here? FYI there is some funky code with the "vidMax-1" section-- long story but this is required to pick the correct video (working fine in another app). I don't understand why the loop isn't working.
Also, on a related note, I'm very frustrated with the GOLDELOX's inability to create true random numbers. Is there anything that can be done here? I start the code with a hard-coded 4-digit seed, but every time the board powers up, it picks the same numbers. Any help in this area would also be much appreciated.
Thank you!
It's not working. It's just playing the same video over and over, which is the exact opposite of what it's supposed to do. here's the relevant code:
func resetPlayed() // Reset the "played" status for all videos to 0
played[20] := [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
endfunc
func pickRandom() // Picks a random video but only plays each once until all in the sequence have been played
exitNow := 0;
while(exitNow := 0)
vidNum := ABS(RAND() % (vidMax-1));
vidNum := vidNum + 1;
if(vidNum >= (vidMax - 1))
vidNum := 0;
endif
if(played[vidNum] := 0) // This one hasn't ben played yet
exitNow := 1;
endif
wend
played[vidNum] := 1;
endfunc
In theory this looks to me like it should work-- any idea what's wrong here? FYI there is some funky code with the "vidMax-1" section-- long story but this is required to pick the correct video (working fine in another app). I don't understand why the loop isn't working.
Also, on a related note, I'm very frustrated with the GOLDELOX's inability to create true random numbers. Is there anything that can be done here? I start the code with a hard-coded 4-digit seed, but every time the board powers up, it picks the same numbers. Any help in this area would also be much appreciated.
Thank you!
Comment