pypdevsbbl.extra.rngstreams package

Subpackage for RNGs.

This file contains:

By default, the MRG32k3a-based RngStreams are used for generating random numbers in the building blocks, but this can be changed to Python’s builtin random module, or the numpy.random module, as is required by the user. Call setGeneratorType() to do so.

Warning

In order to use RngStreams, please make sure you have the required library installed. This consists of the compiled C code for RngStreams and should be located in the src/dependencies/RngStreams/c folder.

Whenever this library cannot be found, a warning will be printed and the builtin random module will be used instead.

class pypdevsbbl.extra.rngstreams.Generators[source]

Bases: enum.Enum

Enum helper class to determine the RNG to use.

RANDOM = 0

Use Python’s builtin RNG. (i.e. the random module)

NUMPY = 1

Use Numpy’s RNG.

RNGSTREAMS = 2

Use Pierre L’Ecuyers’ and Richard Simard’s RngStreams.

pypdevsbbl.extra.rngstreams.GENERATE_WITH = <Generators.RANDOM: 0>

Identifies the stream to use.

Set this value to the desired RNG stream, before the model is constructed. Must be a value from the Generators enum.

pypdevsbbl.extra.rngstreams.setGeneratorType(gen_type)[source]

Sets the GENERATE_WITH variable.

Call this function to validly set the generator type.

Note

May be changed during construction of RNG-dependent building blocks. This allows the combination of multiple generator types.

class pypdevsbbl.extra.rngstreams.RngStream_InfoState[source]

Bases: _ctypes.Structure

Anti

Structure/Union member

Bg

Structure/Union member

Cg

Structure/Union member

Ig

Structure/Union member

IncPrec

Structure/Union member

name

Structure/Union member

pypdevsbbl.extra.rngstreams.setSeed(gen, seed)[source]

Sets a new seed for the RngStreams generator object.

RngStream requires a seed that is of size 6. This function makes it easier in a sense that when it does not find enough values for its seed, it will automatically fill the seed until it is large enough.

Parameters:
  • gen (object) – The generator object (RngStreams).
  • seed – Either a numeric, or an iterable. The new seed to use.
Returns:

-1 on faillure, 0 on success.

Raises:

ValueError – When an invalid seed was given.

pypdevsbbl.extra.rngstreams.createStream(name, seed=None)[source]

Creates a custom RNG stream, w.r.t. the requested generator.

Parameters:
  • name (str) – The unique name in case of an RngStreams generator.
  • seed – Either a numeric, or an iterable. The seed to use. When None, no seed will be set. Defaults to None.
pypdevsbbl.extra.rngstreams.U01(gen)[source]

Return a uniformly distributed random variable within (0, 1).

This function works no matter the selected generator.

Parameters:gen (object) – The generator to use.
Returns:A numpy.float64 in the range (0, 1).