SHA-256 shuffle

Someone at StackOverflow asked if it was possible to shuffle a deck of cards based on the value of a SHA-256 hash. The question was deleted before I got a chance to answer, but it’s an interesting idea. A standard deck of playing cards has 52! (52 factorial) permutations. This doesn’t evenly divide the number of possible SHA-256 hashes (which is 2256, obvs), but since 52! is much smaller, the results are still very uniform. To be precise, some deck permutations will be about 0.00000007% more likely than others. This might be a problem for cryptographic applications, but I can’t see how it could cause any problems for card games. This code also provides a useful way of representing the ordering of a deck of cards with a single number from 0 to 52!−1 (226 bits, or 29 bytes).

You can try it out here. Check the source code if you want to see how it works.

Results will appear below

.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.