bilby.core.utils.random

Submodule for random number generation.

This module provides a wrapper around numpy’s random number generator to ensure that the same random number generator is used throughout bilby. It also provides a function to set the random seed and generate random seeds.

The intended usage is to import the submodule and the use the rng attribute to generate random numbers. For example:

>>> from bilby.core.utils import random
# Seed the random number generator
>>> random.seed(1234)
# Generate a random number between 0 and 1
>>> x = random.rng.random()

The rng attribute is a numpy.random.Generator object, for more details see the numpy documentation: https://numpy.org/doc/stable/reference/random/generator.html

Warning

Do not import rng directly from bilby.core.utils.random since it will not be seeded correctly.

Functions

generate_seeds(nseeds)

Generate a list of random seeds.

seed(seed)

Seed the random number generator.

Classes

Generator()

Class to hold the random number generator.