class randomgen.xoshiro512.Xoshiro512(seed=None, *, mode=None)

Container for the xoshiro512** pseudo-random number generator.

seed{None, int, array_like[uint64], SeedSequence}, optional

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 is None, then data is read from /dev/urandom (or the Windows analog) if available. If unavailable, a hash of the time and process ID is used.

mode{None, “sequence”, “legacy”}

The seeding mode to use. “legacy” uses the legacy SplitMix64-based initialization. “sequence” uses a SeedSequence to transforms the seed into an initial state. None defaults to “sequence”.


xoshiro512** is written by David Blackman and Sebastiano Vigna. It is a 64-bit PRNG that uses a carefully constructed linear transformation. This produces a fast PRNG with excellent statistical quality [1]. xoshiro512** has a period of \(2^{512} - 1\) and supports jumping the sequence in increments of \(2^{256}\), which allows multiple non-overlapping subsequences to be generated.

Xoshiro512 provides 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 Generator or similar object that supports low-level access.

See Xorshift1024 for a related PRNG with a different period (\(2^{1024} - 1\)) and jump size (\(2^{512} - 1\)).

State and Seeding

The Xoshiro512 state vector consists of a 4 element array of 64-bit unsigned integers.

Xoshiro512 is seeded using either a single 64-bit unsigned integer or a vector of 64-bit unsigned integers. In either case, the seed is used as an input for another simple random number generator, SplitMix64, and the output of this PRNG function is used as the initial state. Using a single 64-bit value for the seed can only initialize a small range of the possible initial state values.

Parallel Features

Xoshiro512 can be used in parallel applications by calling the method jump which advances the state as-if \(2^{128}\) random numbers have been generated. This allows the original sequence to be split so that distinct segments can be used in each worker process. All generators should be initialized with the same seed to ensure that the segments come from the same sequence.

>>> from numpy.random import Generator
>>> from randomgen import Xoshiro512
>>> rg = [Generator(Xoshiro512(1234)) for _ in range(10)]
# Advance each Xoshiro512 instance by i jumps
>>> for i in range(10):
...     rg[i].bit_generator.jump(i)

Compatibility Guarantee

Xoshiro512 makes a guarantee that a fixed seed will always produce the same random integer stream.



“xoroshiro+ / xorshift* / xorshift+ generators and the PRNG shootout”, https://prng.di.unimi.it/


>>> from numpy.random import Generator
>>> from randomgen import Xoshiro512
>>> rg = Generator(Xoshiro512(1234))
>>> rg.standard_normal()
0.123  # random

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.

seed_seq{None, SeedSequence}

The SeedSequence instance used to initialize the generator if mode is “sequence” or is seed is a SeedSequence. None if mode is “legacy”.

Seeding and State


Seed the generator


Get or set the PRNG state

Parallel generation


Jumps the state as-if 2**256 random numbers have been generated.


Returns a new bit generator with the state jumped



CFFI interface


ctypes interface


random_raw([size, output])

Return randoms as generated by the underlying BitGenerator