View Full Version : Generate random number between -150 and 150
Jeremy1026
Aug 12, 2008, 06:32 PM
I am trying to generate a random number between -150 and 150, currently I know how to generate a random number that is either between 1 and 150 or -150 and 0. But I am having problems doing both.
xmove = [[NSNumber numberWithInt:1 + arc4random() % 151] integerValue];
calculus
Aug 12, 2008, 06:35 PM
I don't know anything about programming, but could you generate a random number between 0 and 300 and then subtract 150?
Encryptic
Aug 12, 2008, 06:58 PM
He posted this on another board, and I responded there as well.
But here's a code snippet of how to do it:
NSNumber *numResult = [NSNumber numberWithInt: (arc4random() % 300) - 150];
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.