I have an app that needs to play several videos when prompted, but I would like the videos to be random and not repeat.
My current plan is to make an NSMutableDictionary where the key is the number for the video, and the value is just a basic string to tell me if it has been played or not. Then, when the video is to be played, I would randomly choose one and see if it has been played. Like so:
int randomNumber;
randomNumber = (arc4random() % 150) + 1;
if ([[videoDictionary valueForKey:[NSString stringWithFormat:@"%d", randomNumber]] isEqual:@"Played"])
{
// This video has been played before. Make another random number and try again
} else {
// This video has not been played before. Set the dictionary value to 'Played' and play the video
}
Is there a better way to do this? With over 100 videos this could start to get a bit daft when 90% of them have already been played.