I want it keeps generating different random number. How to use While statement?
int randomnumber = (arc4random() % 188)+1;
if ([myArray containsObject:[NSNumber numberWithInt:randomnumber]])
{
NSLog(@"Yes, they are the same");
randomnumber = (arc4random() % 188)+1;
}
else
{
NSLog(@"No, they are not the same");
}
[myArray addObject:[NSNumber numberWithInt:randomnumber]];
Maybe something like this. It loops until it finds a number that’s not in the array.
If you need lots of random numbers, you can put the whole thing into another loop that runs for as many rounds as you need distinct numbers.