Skip to content

Instantly share code, notes, and snippets.

@nothingrealhappen
Last active February 19, 2016 02:55
Show Gist options
  • Save nothingrealhappen/2c0a9f0a5f85b4293983 to your computer and use it in GitHub Desktop.
Save nothingrealhappen/2c0a9f0a5f85b4293983 to your computer and use it in GitHub Desktop.
2016-02-18

Write a method to shuffle a deck of cards. It must be a perfect shuffle - in other words, each 52! permutations of the deck has to be equally likely. Assume that you are given a random number generator which is perfect.

@ScorpiusZ
Copy link

cards = (1..52).to_a
result = []
cards.size.times do
  result << cards.delete_at(cards.size * rand)
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment