How to create a random float in Objective-C?
Here is a function
- (float)randomFloatBetween:(float)smallNumber and:(float)bigNumber { float diff = bigNumber - smallNumber; return (((float) (arc4random() % ((unsigned)RAND_MAX + 1)) / RAND_MAX) * diff) + smallNumber;}
Try this:
(float)rand() / RAND_MAX
Or to get one between 0 and 5:
float randomNum = ((float)rand() / RAND_MAX) * 5;
Several ways to do the same thing.
- use arc4random() or seed your random values
try
float pscale = ((float)randn) / 100.0f;