int y = (random());
float x = (y % 100) / 1000.0;
NSLog(@"random() is %d", y);
NSLog(@"modulo is %2.3f", x);
Use this, to create a number between -1.000 to +1.000;
int y = (random() % 2000) - 1000;
float x = y / 1000.0;
NSLog(@"random() is %d", y);
NSLog(@"modulo is %2.3f", x);
Apparently, this is not truly random, because the number series is always identical. Good enough for many things.
int y = (random() % 2000) - 1000;
float x = y / 1000.0;
NSLog(@"random() is %d", y);
NSLog(@"modulo is %2.3f", x);
Apparently, this is not truly random, because the number series is always identical. Good enough for many things.
Other functions to look at are arc4random() or
srand(time(NULL)); which requires seeding.