0

I have a game that produces 1 of 6 random images when btnStart is pressed. I am using int randomImages followed by a switch statement with cases 0 - 5. However, case 1 is the only image that shows up every time. Case 0 and cases 2-5 do not show up. No matter what order I set the images, it is only case 1 that is shown.
Are there any alternatives to switch cases when using a random image generator?

int randomImages = rand() % 6;
switch (randomImages) {
picciano
  • 22,341
  • 9
  • 69
  • 82

1 Answers1

0

You need to seed the rand() function or you'll get the same result every time. Try using int randomImages = arc4random_uniform(6); instead.

Also see: Generating random numbers in Objective-C

Community
  • 1
  • 1
Ryan Epp
  • 931
  • 1
  • 10
  • 21