randomgen.pcg32.PCG32.advance_step¶
- static PCG32.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**64 / phi, about1.1 * 10**19, 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 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**64, so streams0ton - 1are only guaranteed not to overlap whenn * step <= 2**64.advance_stepdoes not check this, since it does not known, and the period ofPCG32is short enough for the limit to matter. The largestnis2**64 // step:max_drawsLargest
n10**61.4 * 10**1310**91.4 * 10**1010**121.4 * 10**710**1513,254
10**1812
The step is less than
2 * max_draws, sonstreams always fit whenn * max_draws <= 2**63. When many streams or many draws per stream are needed, usePCG64, or the relatedPCG64DXSMorLCG128Mix. Their period of2**128allows about2.5 * 10**26streams of10**12draws.The step is computed with integer arithmetic only, so it is exact for any
max_draws.Examples
>>> from randomgen import PCG32 >>> step = PCG32.advance_step(10**10) >>> hex(step) '0x278dde6e5' >>> streams = [PCG32(1234).advance(i * step) for i in range(8)]