npy_random_seed

odl.util.utility.npy_random_seed(seed)[source]

Context manager to temporarily set the NumPy random generator seed.

Parameters:
seedint or None

Seed value for the random number generator. None is interpreted as keeping the current seed.

Examples

Use this to make drawing pseudo-random numbers repeatable:

>>> with npy_random_seed(42):
...     rand_int = np.random.randint(10)
>>> with npy_random_seed(42):
...     same_rand_int = np.random.randint(10)
>>> rand_int == same_rand_int
True