Reputation:
How to generate random unique pairs from array of users?
For example, we have 10 users and we must generate something like this:
etc.
Also, what should I do, if there's odd number of players?
Upvotes: 0
Views: 154
Reputation: 52357
How to generate random (unique) pairs between users (for game)
[1,2,3,4,5,6].shuffle.each_slice(2).to_a
#=> [[5, 4], [1, 3], [6, 2]]
Reference:
Also, what I should to do, if I have odd number of players?
Set even number of players to play and do nothing with the reminding one until new player shows up? :)
Upvotes: 5