Random Number Generation — Dask documentation (original) (raw)

Random Number Generation

Dask’s random number routines produce pseudo random numbers using combinations of a BitGenerator to create sequences and a Generator to use those sequences to sample from different statistical distributions.

Since Dask version 2023.2.1, the Generator can be initialized with a number of different BitGenerator classes. It exposes many different probability distributions. The legacy RandomState random number routines are still available, but are considered frozen and will not be getting any updates.

Differences with NumPy

Dask follows the NumPy interface for random number generation with some differences:

Notes

Quick Start

Call default_rng to get a new instance of a Generator, then call its methods to obtain samples from different distributions. By default, Generator uses bits provided by PCG64 which has better statistical properties than the legacy MT19937 used in RandomState.

Do this (new version)

import dask.array as da rng = da.random.default_rng() vals = rng.standard_normal(10) more_vals = rng.standard_normal(10)

instead of this (legacy version)

import dask.array as da vals = da.random.standard_normal(10) more_vals = da.random.standard_normal(10)

For further info, please see NumPy docs