I call arc4random in a function in an iOS application to generate random values ββfrom -5 to 6.
double num;
for (int i = 0; i < 3; i++) {
num = (arc4random() % 11) - 5;
NSLog(@"%0.0f", num);
}
I get the following output from the console.
2012-05-01 20:25:41.120 Project32[8331:fb03] 0
2012-05-01 20:25:41.121 Project32[8331:fb03] 1
2012-05-01 20:25:41.122 Project32[8331:fb03] 4294967295
0 and 1 are values ββwithin the range, but wowww, where does 4294967295 come from?
Changing arc4random()to rand()fixes the problem, but of rand()course requires sowing.
source
share