i trying figure out how present pair of users array of users current_user
of app, , not have current_user
see same pair of users again. mathematically, understand n choose 2
, n size of user array. however, unsure how set data structure could, at random, present of combination of pairs current_user
. thanks!
i create class consisted of id's 2 users.
@interface userpair: nsobject @property (nonatomic, assign) nsinteger user1id; @property (nonatomic, assign) nsinteger user2id; @end
i create nsmutablearray of possible pairs run awesome shuffle method: (taken this answer)
- (void)shuffle { nsuinteger count = [self count]; (nsuinteger = 0; < count; ++i) { // select random element between , end of array swap with. nsinteger nelements = count - i; nsinteger n = (arc4random() % nelements) + i; [self exchangeobjectatindex:i withobjectatindex:n]; } }