Recreate a random number series when not using Random.seed!(my_seed)

Is there a way to get back a random number series when Random.seed!(my_seed) was not used to create the series.

One thought I had was to randomly generate my_seed and then use that to gen the series in the Random.seed! command. This is kind of a self defeating argument.

Maybe there is some elegant function for this?

Are you asking how to compute the seed from the random sequence?

Your method will be hard. RNGs are designed to generate uncorrelated sequences, so you will have to try all possible integers (or exploit some advanced tricks used by the cryptographers I guess…)

There are cryptographic RNGs where it wouldn’t work, but don’t rely on this NOT being possible with Julia’s default RNG. The seed is UInt64 (max, though can also take a Vector of) so should only take a few hours to do. See below in my later post, if 4 are used as I think it is, then forget it.

help?> Random.seed!(10)   # works but not for seed! so it seems not exported (from Random), but shouldn't it be, also for helping with help search?

Could look into the default seeding procedure as well, perhaps it’s from a clock, and you can restrict to a particular range based on when the original sequence was made?

Yes. Given that I used a random number series without seeding first, then what is the my_seed variable that would have created that series if I had used Random.seed!(my_seed) first?

Be aware this will also depend on the version of Julia as the default random number generator has changed through time.

Also, the rng state consists of 4 UInt64, while a seed is only one.
Most states will not have any seeds that map to them.

Thanks to all. I solved this by first creating my_seed with rand(1:10000) and then using that in Random.seed!(my_seed). I created a file which initially holds my_seed. This can then be used to recreate the sequence for debugging purposes in case my program bombs due to a logic bug. My program creates thousands of different sequence for simulation purposes.

I see, you want to be able to recreate each simulation, so you first create a set of seeds, one for each simulation?

There are two ways to go about this. The first is to not worry about potential correlations and just use the seeds in order, for ease of use… Seed the nth simulation with the number n.

The other is to try to spread the seeds out in a way that avoids correlations between simulations in which case I’d recommend reading 64 bit ints from /dev/urandom on Linux, or some similar process on Windows, and storing those… I don’t think random(1:10000) is a good choice.

As of Julia 1.7 MersenneTwister is no longer the default RNG, and the seed is 4 UInt64, and if I’ve reading correctly, i.e. all set, then you will never recover the seed.

For the older (used in Julia 1.6 and before):

Create a MersenneTwister RNG object. Different RNG objects can have
their own seeds, which may be useful for generating different streams
of random numbers.

The seed may be a non-negative integer or a vector of
UInt32 integers. If no seed is provided, a randomly generated one
is created (using entropy from the system).

It looks like this can be done portably by using rand(RandomDevice(),10000)

Do note that for Xoshiro (and TaskLocalRGN, the default RNG), it should be fine to use sequential seeds, and they go through SHA2_256, and the result of that cryptographic hash is used as the state.