How can you disallow some nubers from being chosen with the arc4random function?
Current code:
int random = (arc4random() % 92);
(numbers from 0 to 92)
I want it do disallow the following numbers: 31, 70, 91, 92
Thank you (:
How can you disallow some nubers from being chosen with the arc4random function?
Current code:
int random = (arc4random() % 92);
(numbers from 0 to 92)
I want it do disallow the following numbers: 31, 70, 91, 92
Thank you (:
First, you'll need to change
% 92
to
% 93
to get numbers from 0..92
I'd do something like this
int random;
do {
random = arc4random() % 93;
}
while ( random == 31 || random == 70 || random == 91 || random == 92 );
Simple, keep asking for numbers:
get a new random number
while the new number is one of the disallowed ones:
get a new random number
return the random number
Pseudo code, but you should get the idea.
If you are going to disallow numbers 91 and 92, why bother including them in your mod?
Expanding on the previous answer:
int random;
do {
random = arc4random() % 91;
}
while ( random == 31 || random == 70 );