tags:

views:

15

answers:

2

i am trying to get a random number of items from an an array of dictionaries that contains 2 items. one item is at index 1 and the other is at index 0. i want to randomly alternate between the two or have the able to be viewed in a random order each item. (i know i have just 2 items ill increase the amount) this is the code im trying to get to randomize with the index 0 and index 1 files.

   - (UIImage *)imageAtIndex:(NSInteger)index
{
   NSDictionary *dict = [data_ objectAtIndex:0];
   UIImage *image = [dict objectForKey:@"fullsize"];
   return image;
}
A: 

NSUinteger index = arc4random() %([data_ count] +1);

GameBit
+1  A: 

some question for random function according to it, you can do

int index = arc4random() % 2;

edit
here is a category on NSMuteableArray to shuffle its objetcs

vikingosegundo