I am generating a random number between 0 and topOfRange. I can exclude firstNumberToExclude with this code:
NSInteger aRandom;
while ((aRandom = arc4random()%topOfRange) == firstNumberToExclude);
how about if I had two numbers to exclude: firstNumberToExclude and secondNumberToExclude? This was my plan but doesnt seem to be proper:
NSInteger aRandom = arc4random()%topOfRange;
while (aRandom == firstNumberToExclude || aRandom == secondNumberToExclude)
{
aRandom = arc4random()%topOfRange;
}
I think your code would be cleaner, and easier to maintain, if you refactored this into a utility method:
Then you can call it like: