2
votes

Using the C++11 #include<random> or Boost C++ Boost.Random is it possible to use one seed to start the random number generator at an arbitrary sequence in that you can choose?.

In other words I want to be able to specific where in the sequence the number generator starts, while using the same seed.

For example if i'm using the mt19937 generator with a length of cycle 2^19937-1 I would like to start generating random numbers at a user specified position in the length of the cycle. Say I pick 1000, the generator will start at the 1000th position in the length of the cycle.

1
Are you saying that you want to be able to configure the RNG (e.g. by giving it a specific seed) such that it generates a specific sequence of values at first? Or do you just want it to start at a specific position in it's cycle, but you don't care what values are produced?Nate Kohl
@NateKohl right so the second is what i want, the seed could be anything lets just say we use seed X, given .seed(X) for operation A i want to start at the beginning of the cycle , and for operation B i want to start at the 100,000th position of the cycle. Both A and B used the same seed and generator.pyCthon

1 Answers

8
votes

Yes. There is a member discard(unsigned long long z) that does this for you. For example:

#include <random>
#include <cassert>

int main()
{
    std::mt19937 e1(6492);
    std::mt19937 e2(6492);
    const int N = 1000;
    for (int i = 0; i < N; ++i)
        e1();
    e2.discard(N);
    assert(e1() == e2());
}

This program should not assert.