Rotate-Multiply (Romu) Generators¶
Mark A. Overton’s quad and trio rotate-multiply-based generators
A seed to initialize the BitGenerator. If None, then fresh, unpredictable entropy will be pulled from the OS. If an
array_like[ints]is passed, then it will be passed to SeedSequence to derive the initial BitGenerator state. One may also pass in a SeedSequence instance.
The variant to use. The Quad variant is somewhat slower but has a larger state.
Romuis a rotate-multiply based generator either either a 256-bit state (default, “quad”) or a 192-bit state (“trio”) (, ).
Romuhas a large capacity and has a tiny chance of overlap, especially when using the default “quad” variant. It is extremely fast.
Romuprovides a capsule containing function pointers that produce doubles, and unsigned 32 and 64- bit integers. These are not directly consumable in Python and must be consumed by a
Generatoror similar object that supports low-level access.
State and Seeding
Romustate vector consists of 3 (“trio”) or 4 unsigned 64-bit values. The input seed is processed by SeedSequence to generate all values, then the
Romualgorithm is iterated a small number of times to mix.
Romumakes a guarantee that a fixed seed will always produce the same random integer stream.
Romusupports parallel application using distinct seed values.
>>> from randomgen import SeedSequence, Romu >>> NUM_STREAMS = 8192 >>> seed_seq = SeedSequence(489048146361948) >>> bit_gens = [Romu(child) for child in seed_seq.spawn(NUM_STREAMS)] >>> [bg.random_raw() for bg in bit_gens[:3]] [9130649916277841551, 2156737186088199787, 12803009197309261862]
Seeding and State¶
Seed the generator
Get or set the PRNG state
Return randoms as generated by the underlying BitGenerator