comnum.Rng#

class comnum.Rng(seed)#

A seeded random generator (xoshiro256** seeded through SplitMix64).

The same generator as the Rust crate: a seed gives the same draws in Rust and in Python. Every function of comnum that draws takes one as its rng argument and advances it.

Parameters:

seed (int) – the seed (any 64-bit unsigned integer).

Examples

>>> import comnum
>>> rng = comnum.Rng(1)
>>> rng.uniform(3).shape
(3,)
>>> comnum.Rng(7).next_u64() == comnum.Rng(7).next_u64()
True
static stream(seed, name, condition, trial)#

The generator of trial trial of condition condition of experiment name derived from a base seed (the streams of the Monte Carlo runner).

Parameters:
  • seed (int) – base seed.

  • name (str) – experiment name (hashed with FNV-1a).

  • condition (int) – condition index.

  • trial (int) – trial index.

Returns:

an independent generator.

Return type:

Rng

Examples

>>> import comnum
>>> a = comnum.Rng.stream(1, "exp", 0, 3).uniform(2)
>>> bool((a == comnum.Rng.stream(1, "exp", 0, 3).uniform(2)).all())
True
complex_noise(n, noise_var=1.0)#

Circular complex Gaussian draws of variance noise_var (E|w|² = noise_var).

Parameters:
  • n (int) – number of draws.

  • noise_var (float) – the variance E|w|².

Returns:

n values (complex128).

Return type:

numpy.ndarray

Raises:

ValueError – for a negative count.

gaussian(n)#

Standard normal draws.

Parameters:

n (int) – number of draws.

Returns:

n values (float64).

Return type:

numpy.ndarray

Raises:

ValueError – for a negative count.

integers(high, n)#

Uniform integers in [0, high).

Parameters:
  • high (int) – the exclusive upper bound (positive).

  • n (int) – number of draws.

Returns:

n values (int64).

Return type:

numpy.ndarray

Raises:

ValueError – for an invalid parameter (the message names it).

next_u64()#

The next raw 64-bit draw.

Returns:

an unsigned 64-bit integer.

Return type:

int

uniform(n)#

Uniform draws in [0, 1).

Parameters:

n (int) – number of draws.

Returns:

n values (float64).

Return type:

numpy.ndarray

Raises:

ValueError – for a negative count.