objective c - Random number from a range without a certain number in the middle of the range -
i'm generating number 0 11 randomly this:
int n = arc4random() % 12;
but, i'd not 5 or 6 output. how can that?
if have such constraint, make explicit in code:
int n; { n = arc4random() % 12; } while (n == 5 || n == 6); //retry if encountered 1 of unallowable values
Comments
Post a Comment