I use this code in Objective-C to generate a random height between 100 and 1000.
My problem is, that new height is often near to the previous one and that is not so nice.
So how to make it so, that there is always some space (50px, for example) between previous and next height?
_randomHeight = arc4random() % (1000-100+1);
You just have to keep generating values until a value meets your requirement:
CGFloat height;
do {
height = arc4random() % (1000-100+1);
} while (fabs(_randomHeight - height) < 50.0f);
_randomHeight = height;