haigowtham haigowtham - 1 year ago 121
iOS Question

Objective-c generating a random point which lies in given cgrect

my requirement is generating a random point in a given area, i.e i have an Cg Rectangle of some space and i need to generate a random point in this rectangle ..

how can i proceed in this scenario ??

Answer Source
- (CGPoint)randomPointInRect:(CGRect)r
    CGPoint p = r.origin;

    p.x += arc4random_uniform((u_int32_t) CGRectGetWidth(r));
    p.y += arc4random_uniform((u_int32_t) CGRectGetHeight(r));

    return p;