0

This question arises from my attempt to mix two different RNGs. I'd like to mix them choosing the best of the two according to the operations I need to carry out to achieve better performance. I'm restricted to use a Mersenne Twister (MT19937) RNG with any other RNG listed here:

  • PCG-64
  • PCG-64 DXSM
  • MT19937
  • Philox
  • SFC64

Also, a requirement of my project is that I need to have reproducible results so unpredictable entropy should be avoided to set the seeds, but I can set one of the seed with a pseudorandom number generated with one of the RNG if needed.

I read here that using two Mersenne Twister can be problematic in terms of the quality/correlation of the sequence generated. So another MT19937 seems not a good choice at least if I don't pass the state of the first MT19937 to this new other when I need to carry out some operations, but this type of procedure creates a relevant overhead. Can any of the others be initialized together with a MT19937 without incurring in these problems? Or is there any other solution? I posted a similar question on StackOverflow where it is described also the specific programming context where an answer to this question can prove useful to me. Thank you in advance!

Tortar
  • 111
  • 4
  • 4
    Define what "best" means to you. – Wolfgang Bangerth Feb 02 '23 at 22:27
  • I'm not sure what you are referring to but I'd like to have a sequence of numbers so that there is no correlation achieving the best performance in mixing two generators, where one has to be a MT19937 – Tortar Feb 02 '23 at 22:33
  • 1
    Well, the thing is that for every non-random sequence, some kind of correlation can be found if you just look hard enough. And no RNG produces random sequences, though all modern RNG sequences are very good, including for that matter MT19937. – Wolfgang Bangerth Feb 03 '23 at 03:04
  • 4
    But what I meant with "define best" is that you say "achieving the best performance in mixing two generators": How would you measure "best performance"? How will you know that one way of mixing generators is better or worse than another way of mixing generators? – Wolfgang Bangerth Feb 03 '23 at 03:05
  • In my case it's clear I think since I have a rather specific problem in mind as you can read in the linked question on stack overflow: to choose between the default random rng and the Numpy rng, I manually calculated where one is better than the other timings the different functions as you can see in the other question – Tortar Feb 04 '23 at 21:38
  • So if "better" = "faster", then why mix RNGs to begin with? You might as well go with the faster one right away! – Wolfgang Bangerth Feb 06 '23 at 19:51
  • there is no faster one for all operations, one is better in something than the other because I'm talking about random functions not just about generating single random uniform numbers, for example the random function "shuffle" is faster with the first RNG than with the other, but the second is better at generating single random number, so there is no faster in this sense – Tortar Feb 06 '23 at 20:36

1 Answers1

1

Maybe I've found a solution myself, hope that someone knowledgable can check if this is correct!

I can use a second MT19937 with the same seed where I jump ahead the state of the generator at the start of the simulation with a step size which can be impossible to arrive at with the first generator so that it is like having only one generator throughout the all simulation.

It is possible to do so as described in

  • Hiroshi Haramoto, Makoto Matsumoto, Takuji Nishimura, François Panneton, Pierre L’Ecuyer, “Efficient Jump Ahead for F2-Linear Random Number Generators”, INFORMS JOURNAL ON COMPUTING, Vol. 20, No. 3, Summer 2008, pp. 385-390.
Tortar
  • 111
  • 4