Search code examples
algorithmrandomshufflepoker

What RNG(random number generator) algorithm suits for poker cards shuffle?


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.


Solution

  • 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.