randomgen.pcg64.LCG128Mix.advance_step

static LCG128Mix.advance_step(max_draws)

Step for splitting one stream into streams of up to max_draws draws

Added in version 2.5.0.

Parameters:
max_draws

The largest number of draws that any stream makes. Must be at least 1 and at most the integer part of 2**128 / phi, about 2.1 * 10**38, where phi is the golden ratio.

Returns:

step – The odd integer closest to 2**XX / phi, where XX is the smallest integer for which 2**XX / phi is larger than max_draws. The step is never smaller than max_draws.

Return type:

int

Raises:
  • ValueError – If max_draws is outside the range above.

  • TypeError – If max_draws is not an integer.

See also

advance

Advance the state as-if delta draws have occurred.

Notes

Advance stream i by i * step to split one stream into several. The step is odd, so, for the default multiplier, the states of two streams differ as if at random, apart from their lowest few bits. The step is at least max_draws, so a stream that makes at most max_draws draws does not reach the start of the next stream. The Notes of advance explain this choice of step.

The starts i * step are taken modulo the period, 2**128, so streams 0 to n - 1 are only guaranteed not to overlap when n * step <= 2**128. advance_step does not check this, since it does not know n, but it is not a practical limit: streams of 10**12 draws allow about 2.5 * 10**26 streams.

The step is computed with integer arithmetic only, so it is exact for any max_draws.

Examples

>>> from randomgen import LCG128Mix
>>> step = LCG128Mix.advance_step(10**10)
>>> hex(step)
'0x278dde6e5'
>>> streams = [LCG128Mix(1234).advance(i * step) for i in range(8)]