tags:

views:

24

answers:

1

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
thank u very much
pankaj
@pankaj No problem :) If this answers your question, you can mark it as "accepted" by clicking the tick on the left.
Cannonade