Card Shuffling
Technical Information

Poker Mavens uses a cryptographically secure shuffling algorithm for dealing cards. An RC4-based stream cipher seeded with a random 256-bit key is used as the random number generator. The key is produced by hashing a seed pool with the SHA-256 hash algorithm. The seed pool is constructed by sampling low bits from the CPU's 1.193 MHz high-performance counter in between a series of thread pauses.

The deck is represented internally as an integer array from 1 to 52 with 1 to 4 representing the deuce of clubs, diamonds, hearts, and spades respectively on up to 52 representing the ace of spades. Before each hand, the array is shuffled using the highly efficient Fisher-Yates shuffling algorithm described in Donald Knuth's "The Art of Computer Programming" series of books. In Delphi, it looks like this:

for i := 52 downto 2 do
begin
  k := PRNG_Value(i) + 1;
  j := Cards[k];
  Cards[k] := Cards[i];
  Cards[i] := j;
end;

The PRNG_Value(i) function returns a random number from 0 to i - 1 from the secure random number generator described above.

Help Index | Home Page