i want to know how to aceess random items from array in iphone sdk? i have made an music player in which next song comes from array on button click but i want to get the songs randomly
+3
A:
You can use the rand() function:
NSInteger randomIndex = rand () % [list count];
Thing * randomThing = [list objectAtIndex:randomIndex];
Don't forget to call srand(unsigned int seed) on startup:
srand(time(0));
Cannonade
2010-08-18 06:29:59
thank u very much
pankaj
2010-08-18 09:37:53
@pankaj No problem :) If this answers your question, you can mark it as "accepted" by clicking the tick on the left.
Cannonade
2010-08-18 12:09:19