I’ve got a poker and blackjack game that store a base card deck in a MySQL database. In order to shuffle the cards, I order the table at random using ORDER BY RAND() and insert the cards in that order into a different table. Will using RAND() result in realistic odds that would be found playing with real cards and physically shuffling, or is this function not random enough?
Share
Shuffling with real cards isn’t really all that random unless you practise it a lot. It’s easy to shuffle incorrectly so that either the top or the bottom of the pack isn’t shuffled well.
Using ORDER BY RAND() to shuffle is a reasonable approach but there are some things to be aware of:
For entertainment purposes your approach should be fine. If this is for serious money you might want to use a better shuffle algorithm such as the Fisher Yates shuffle and cryptographically secure random number generator.