Best way to do that is just generate a random number then access the array item at that particular index.
#include <stdlib.h>
int numberOfItemsInArray = [arrayWithQuestions count]; //find out how many questions you have
int randomNumber = arc4random() % numberOfItemsInArray; //generate a number less that or equal to the number of questions
[arrayWithQuestion objectAtIndex:randomNumber]; //do with this what you will, this will return a random array item
Best way to do that is just generate a random number then access the array item at that particular index.
#include <stdlib.h>
int numberOfItemsInArray = [arrayWithQuestions count]; //find out how many questions you have
int randomNumber = arc4random() % numberOfItemsInArray; //generate a number less that or equal to the number of questions
[arrayWithQuestion objectAtIndex:randomNumber]; //do with this what you will, this will return a random array item
Replies
#include <stdlib.h> int numberOfItemsInArray = [arrayWithQuestions count]; //find out how many questions you have int randomNumber = arc4random() % numberOfItemsInArray; //generate a number less that or equal to the number of questions [arrayWithQuestion objectAtIndex:randomNumber]; //do with this what you will, this will return a random array item
Note: This code is untested.
<strong><a href="http://itunes.apple.com/au/app/jubilee-weather-gerringong/id558227705?mt=8">Our Only App - Jubilee Weather</a>
randomPhrases is my NSMutableArray. The method shuffles the array and shows the array in the console once it is shuffled.
<strong><a href="http://itunes.apple.com/au/app/jubilee-weather-gerringong/id558227705?mt=8">Our Only App - Jubilee Weather</a>