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, about2.1 * 10**38, where phi is the golden ratio.
- Returns:¶
step – The odd integer closest to
2**XX / phi, whereXXis the smallest integer for which2**XX / phiis larger thanmax_draws. The step is never smaller thanmax_draws.- Return type:¶
- Raises:¶
ValueError – If
max_drawsis outside the range above.TypeError – If
max_drawsis not an integer.
See also
advanceAdvance the state as-if delta draws have occurred.
Notes
Advance stream
ibyi * stepto split one stream into several. The step is odd, so, for the defaultmultiplier, the states of two streams differ as if at random, apart from their lowest few bits. The step is at leastmax_draws, so a stream that makes at mostmax_drawsdraws does not reach the start of the next stream. The Notes ofadvanceexplain this choice of step.The starts
i * stepare taken modulo the period,2**128, so streams0ton - 1are only guaranteed not to overlap whenn * step <= 2**128.advance_stepdoes not check this, since it does not known, but it is not a practical limit: streams of10**12draws allow about2.5 * 10**26streams.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)]