Pseudo random number generator s> 64-bit seed for dragging a deck of 52 cards

When writing the card shuffling algorithm, I realized that there are 52! ~ = 2 ^ 225 possible shuffles that may occur. Given this, it seems to me that any PRNG-based shuffling algorithm with a standard 32-bit or 64-bit seed will be able to create a subset of all possible shuffles. Since my platform has only 32-bit seed PRNG (only POSIX srandom () / random () functions), I was wondering if there is a way to use it creatively to create a shuffling algorithm that can produce any result. If not, does anyone know of a PRNG algorithm that can use a seed, which is a composition of several 32-bit integers that I could implement myself?

+4
source share
2 answers

If you want to solve your problem with a random number generator, you just need to find a way to divide the parameter space of all possible shuffling cards into groups.

For example, if you had a random seed that could only be 1 to 4, but a parameter space that had 12 possible permutations, you would decide to use two random samples:

(seed1) determines which group of parameters you were in (1-4.5-8 or 9-12)
(seed2) determines which element is your final result

(The parameter set does not have to be an even multiple of the seed size for this to work.)

I used this method for very complex problems of complexity in physical modeling of a solid body. This is a rigorous mathematical solution, but it may not be the most elegant software solution. Good luck to you.

+1
source

Interest Ask. If on Linux / dev / urandom or even / dev / random might be appropriate. These devices rely on an โ€œentropy poolโ€ fed by the time of asynchronous hardware events.

However, also explore the mrand48 () family of functions provided in cstdlib or stdlib.h, whether it is on Linux or not. This gives you 48 bits, which is closer to what you want.

Good luck.

+1
source

Source: https://habr.com/ru/post/1403347/


All Articles