haigowtham haigowtham - 4 months ago 41x
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 ??

- (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;