I have a database with 26 movies and 3 questions per movie.
What I have done is my program randomly selects a question from the database and it's displayed on the screen. What I'm having trouble with is recording this question so that it doesn't get selected again.
So far I have been playing with this:
usedMovie_id = [[NSMutableArray alloc] initWithCapacity:26];
usedQuestion_id = [[NSMutableArray alloc] initWithCapacity:4];
for (NSInteger i = 0; i < 26; ++i)
{
[usedMovie_id addObject:[NSNull null]];
}
for (NSInteger i = 0; i < 4; ++i)
{
[usedQuestion_id addObject:[NSNull null]];
}
while (i < 10) {
int ii = [self genRandomNumberForMovies];
int jj = [self genRandomNumberForQuestions:25];
NSLog(@"ii %d, jj %d", ii,jj);
[usedQuestion_id replaceObjectAtIndex:jj withObject:[NSNumber numberWithInt:jj]];
[usedMovie_id replaceObjectAtIndex:ii withObject:usedQuestion_id];
i++;
//NSLog(@"movie_id array %@", usedMovie_id);
}
My problem is that the array usedQuestion_id isn't different at any of the indexes in usedMovie_id, they're all the same. If usedQuestion_id has 1 and usedMovie_id is 13 in the first loop and then usedQuestion_id is 1, 3 and usedMovie_id is 10 in the second loop. The usedQuestion_id is updated to 1, 3 at the usedMovie_id at index 13 (from the first loop).
Also I need to record which question has been answered correct and incorrect so I only show the questions that haven't been answered correctly.
I don't want to have to create 26 nsmutablearrays each with their own data.
I'm thinking I may need a nsdictionary or even a database.. Also I could randomise at the beginning and loop through each question instead of randomising after each question has been answered.