Reputation:
I'm coding an online poker game. The shuffling part is using Fisher Yates algorithm. But I have no idea which random number generator to generate good unpredictable random numbers for the shuffling algorithm to use. 52 cards have 52! ~= 8.065e67 possible sequences.
Upvotes: 1
Views: 1795
Reputation: 1
8e+67
is a lot big number, but it is not very high in data size. It is only 226 bit in data length. 28 bytes.
You may consider using a CSPRNG, a cryptographically strong pseudorandom generator, i.e. an RNG which generates enough strong randomness to be usable for cryptography.
Sometimes also the CPU has a true random number source, it is fast. Here I describe the CSPRNG.
On Linux, you can simply read out the random bytes from the /dev/urandom
character device file.
Upvotes: 2
Reputation: 13181
As you point out, you should use one with far more than 52! possible internal states, which means 226 bits of state. There are many PRNGs that exceed this, having 1024 or more bits of state. You also want something fast, so you can simulate millions of hands. The most popular algorithm that meets these criteria is Mersenne Twister. I personally also like variants of Marsaglia's XORshift.
I generally only use hardware true RNGs (that most PCs have nowadays) for cryptography and for seeding these PRNGs, but I am told that some of the better ones are fast enough to produce values even for simulations. You'd have to look that up for your hardware.
Upvotes: 1