Selecting random numbers iphone sdk
Posted
by harekam_taj
on Stack Overflow
See other posts from Stack Overflow
or by harekam_taj
Published on 2010-04-28T19:55:12Z
Indexed on
2010/04/28
19:57 UTC
Read the original article
Hit count: 257
iphone
|iphone-sdk
Hey,
I want to select 10 random numbers from 1 to 35.
I am trying to do the following, but I get some repeated numbers
int totalNumberCnt = 1;
while (totalNumberCnt < 11) {
int randomNumber1 = 1 + arc4random() % 35;
NSString *numberString = [NSString stringWithFormat: @"%d",randomNumber1];
NSLog(numberString);
[firstNumber addObject:numberString];
[secondNumber addObject:numberString];
totalNumberCnt++;
}
Thank you for your help.
© Stack Overflow or respective owner