Reputation: 13688
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?
Upvotes: 2
Views: 1859
Reputation: 10444
For your use: Probably.
From the gaming industry perspective: No.
The Nevada Gaming Commission oversees the odds and randomness of approved games here. For such a purpose, it is in the interest of the house to eliminate the possibility of RE the randomizer so the real gaming software uses expiring "true random" seeds which must be obtained by certified methods (usually using some naturally chaotic input). Banks will often employ similar tools.
For further reading, see LavaRand
Upvotes: 0
Reputation: 838376
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.
Upvotes: 5