random_seed

To achieve a reproducible result, the pcvl.random_seed() function can be used before a given computation. This function ensures that any random numbers used in algorithms will be the same from run to run.

Example:

>>> from perceval import random_seed
>>> import random
>>>
>>> random_seed(2)  # Set the seed to 2
>>> print(random.random())
0.9478274870593494
>>> print(random.random())
0.9560342718892494
>>> random_seed(2)  # Reset the seed to 2
>>> print(random.random())
0.9478274870593494
>>> print(random.random())
0.9560342718892494

The random real numbers drawn are in the same order when the seed is fixed to the same value.

perceval.utils._random.random_seed(seed=None)

Initialize the seed used for random number generation (RNG)

Impacts the RNG in:

  • Python core random package

  • numpy

  • exqalibur

Note

With a fixed seed, exqalibur RNG is deterministic even inside multithreaded algorithms

Parameters:

seed (Optional[int]) – The seed value. If None, use a time-based seed