Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

midntdj

macrumors newbie
Original poster
Sep 23, 2009
9
0
I have a routine to randomly pick an item from a NSArray using

random() % 9

where 9 is the number of items in the NSArray. The problem I'm seeing is that every time I start my application, I'm getting the exact same random numbers being generated. This only happens when I exit the application and than restart it. I was expecting to see a different pattern each time I start the app. Is there a way to randomize the random function?

Code:
NSString strTemp = [[ NSArray arrayWithObjects: @"a.png", @"b.png", @"c.png", 
                           @"d.png",  @"e.png", @"f.png", @"h.png",@"i.png",
                           @"j.png",nil] objectAtIndex: (random() % 9)];


-- Thanks
 
Using srandom did the trick.

Thanks for posting the other related link.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.