Hi,
I have two objects that get their Y axis randomised by arc4random_uniform. I want to be able to set a minimum gap of atleast 60px between the two objects where ever they randomise. I could randomise one object and then add 60px to the other objects but I wanted the gap between them to be completely random but no less than 60px.
Below is my code that generates the two objects, but I am in need of a way to set a minimum gap of 60px between them
-(void)GenerateLines {
CGRect BlackTop = Black.superview.bounds;
CGRect BlackBottom = BlackOne.superview.bounds;
CGFloat topMargin = 80;
CGFloat bottomMargin = 140;
CGFloat RandomX, RandomY;
RandomX = arc4random_uniform(500) + topMargin;
CGFloat BlackYMax = BlackTop.size.height-topMargin-bottomMargin-
Black.bounds.size.height/2;
RandomY = arc4random_uniform(BlackYMax) + topMargin;
Black.center = CGPointMake(300, RandomY);
CGFloat TopMargin = 140;
CGFloat BottomMargin = 80;
RandomX = arc4random_uniform(500) + TopMargin;
CGFloat BlackOneYMax = BlackBottom.size.height-TopMargin-BottomMargin-
BlackOne.bounds.size.height/2;
RandomY = arc4random_uniform(BlackOneYMax) + TopMargin;
BlackOne.center = CGPointMake(300, RandomY);
}
Thanks in advance,
Josh