Tyche PRNG¶
-
class randomgen.tyche.Tyche(seed=
None
, idx=None
, original=True
)¶ Container for the Tychee pseudo-random number generator.
- Parameters:¶
- seed=
None
¶ Entropy initializing the pseudo-random number generator. Can be an integer in [0, 2**64), array of integers in [0, 2**64), a SeedSequence instance or
None
(the default). If seed isNone
, then data is read from/dev/urandom
(or the Windows analog) if available.- idx=
None
¶ The index to use when seeding from a SeedSequence. If None, the default, the index is selected at random.
- original=
True
¶ If True, use the original Tyche implementation. If False, use the OpenRand implementation. Default is True.
- seed=
- lock¶
Lock instance that is shared so that the same bit git generator can be used in multiple Generators without corrupting the state. Code that generates values from a bit generator should hold the bit generator’s lock.
- Type:¶
- seed_seq¶
The SeedSequence instance used to initialize the generator if mode is “sequence” or is seed is a SeedSequence.
- Type:¶
{None, SeedSequence}
Notes
Tyche
[1] is a pseudo-random number generator based on the Tyche PRNG. It is a 32-bit PRNG that uses a set 4 32-bit unsigned integers as state, and operates using only addition, subtraction, rotation and xor.State and Seeding
The
EFIIX64
state vector consists of 4 32-bit unsigned integers. Theseed
value is translated into a 64-bit unsigned integer. Ifidx
is not None, it is translated into a 32-bit unsigned integer.Compatibility Guarantee
Tyche
makes a guarantee that a fixed seed will always produce the same random integer stream.Examples
>>> from numpy.random import Generator >>> from randomgen import Tyche >>> rg = Generator(Tyche(1234)) >>> rg.standard_normal() 0.123 # random
Parallel Features
Tyche
can be used in parallel when combined with aSeedSequence
usingspawn
.>>> from randomgen import SeedSequence >>> entropy = 8509285875904376097169743623867 >>> ss = SeedSequence(entropy) >>> bit_gens = [Tyche(child) for child in ss.spawn(1024)]
Alternatively, the same
seed
value can be used with differentidx
values.>>> from randomgen import SeedSequence >>> bit_gens = [Tyche(SeedSequence(entropy), idx=i) for i in range(1024)]
References
Seeding and State¶
|
Seed the generator |
Get or set the PRNG state |
Extending¶
CFFI interface |
|
ctypes interface |
Testing¶
|
Return randoms as generated by the underlying BitGenerator |