Danger

randomgen has been substantially merged into NumPy as of 1.17. Evolution of randomgen details how randomgen has changed since it was incorporated into NumPy.

RandomGen¶

This package contains additional bit generators for NumPy’s Generator and an ExtendedGenerator exposing methods not in Generator.

Introduction¶

randomgen supplies many bit generators that can be used with numpy.random.Generator. It also supports additional variants of the bit generators included in NumPy.

from numpy.random import Generator
from randomgen import AESCounter
rg = Generator(AESCounter())
rg.random()

Seed information is directly passed to the bit generator.

rg = Generator(AESCounter(12345, mode="sequence"))
rg.random()

History¶

randomgen began as a project to modernize NumPy’s RandomState. It has succeed at this goal. Some of the components on randomgen were deemed too exotic to include with NumPy and so have been retained in randomgen. Most of these are bit generators or extended features of bit generators included with NumPy. In addition randomgen.generator.ExtendedGenerator exposes some methods that are not included in Generator.

What’s New or Different¶

See What’s New or Different for a complete list of improvements and differences.

Parallel Generation¶

The included generators can be used in parallel, distributed applications in one of five ways:

Supported Generators¶

The main innovation is the inclusion of a number of alternative pseudo-random number generators, ‘in addition’ to the standard PRNG in NumPy. The included PRNGs are:

• MT19937 - The standard NumPy generator. Produces identical results to NumPy using the same seed/state. Adds a jump function that advances the generator as-if 2**128 draws have been made (jumped()). See NumPy’s documentation.

• DSFMT and SFMT - SSE2 enabled versions of the MT19937 generator. Theoretically the same, but with a different state and so it is not possible to produce a sequence identical to MT19937. DSFMT supports jump and so can be used in parallel applications. See the dSFMT authors’ page.

• Xorshiro256** and Xorshiro512** - The most recently introduced XOR, shift, and rotate generator. Supports jump and so can be used in parallel applications. See the documentation for jumped() for details. More information about these PRNGs is available at the xorshift, xoroshiro and xoshiro authors’ page.

• PCG64 - Fast generator that support many parallel streams and can be advanced by an arbitrary amount. See the documentation for advance(). PCG-64 has a period of $$2^{128}$$. See the PCG author’s page for more details about this class of PRNG. LCG128Mix extends the basic PCG-64 generator to allow user-defined multipliers and output functions.

• ThreeFry and Philox - counter-based generators capable of being advanced an arbitrary number of steps or generating independent streams. See the Random123 page for more details about this class of PRNG.

• Other cryptographic-based generators: AESCounter, SPECK128, ChaCha, and HC128.

• XoroShiro128+/++ - Improved version of XorShift128+ with better performance and statistical quality. Like the XorShift generators, it can be jumped to produce multiple streams in parallel applications. See jumped() for details. More information about this PRNG is available at the xorshift, xoroshiro and xoshiro authors’ page.

• XorShift1024*φ - Fast generator based on the XSadd generator. Supports jump and so can be used in parallel applications. See the documentation for jumped() for details. More information about these PRNGs is available at the xorshift, xoroshiro and xoshiro authors’ page.