Search code examples
algorithmrandomsrand

Is it possible to get an approximation to a seed based on a finite sequence of pseudo random numbers?


suppose I have some numbers that form a series for example: 652,328,1,254 and I want to get a seed that if I, for example, do

srand(my_seed);

I will get some kind of approximation with bounded error to my origonal sequence, when all numbers appearing in the same order.


Solution

  • Depends on the algorithm used for the pseudo-random generation. If the algorithm is a simple linear congruential generator, then getting the seed back is just a matter of solving a linear modular equation (note that the solution may be non-unique, but as such a generator is memory-less, it doesn't matter).

    If the algorithm is more complex, this may be impossible.

    Note that the algorithm used in the C standard library isn't restricted by the standard, so different platforms may have different implementations.