NYCPHP Meetup

NYPHP.org

[nycphp-talk] Question about random selection

Rolan Yang rolan at omnistep.com
Mon Dec 10 03:43:16 EST 2007


Anthony Papillion wrote:
> Hello Everyone,
>
>
> I have a 'secret santa' type application that I designed for a Yahoo 
> Group my wife owns.  The way it works is that people go to the site, 
> enter their email address and are randomly matched with some other 
> person. The two filtering criteria for the match are 1) the persons 
> match can't be taken )as indicated in an 'isTaken' field) and 2) the 
> persons match can't be themselves.
>
> The systems works very well unless there are an odd number of people 
> on the list. Then, one person is left out. We've just run into this 
> problem a few minutes ago. There are 7 people on the list and everyone 
> is owned by someone else except one person.
>
> Any idea how I can make this workable on an odd numbered list?
> Your help is really appreciated.
>

Do they have to be matched as pairs? If so, then it's simply not 
possible. If they only need to be matched to another person, then pick 
any pair off the list (Santa A & B) and the left out Santa (C) and match 
A->B, B->C, C->A

~Rolan



More information about the talk mailing list