0

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;
}
Alex Stelea
  • 1,219
  • 2
  • 18
  • 29

2 Answers2

1

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

Community
  • 1
  • 1
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
0
NSUinteger index = arc4random() %([data_ count] +1);
Zoe
  • 27,060
  • 21
  • 118
  • 148
RolandasR
  • 3,030
  • 2
  • 25
  • 26