C API for random#

Access to various distributions below is available via Cython or C-wrapper libraries like CFFI. All the functions accept a bitgen_t as their first argument. To access these from Cython or C, you must link with the npyrandom static library which is part of the NumPy distribution, located in numpy/random/lib. Note that you must also link with npymath, see Linking against the core math library in an extension.

type bitgen_t#

The bitgen_t holds the current state of the BitGenerator and pointers to functions that return standard C types while advancing the state.

struct bitgen:
    void *state
    npy_uint64 (*next_uint64)(void *st) nogil
    uint32_t (*next_uint32)(void *st) nogil
    double (*next_double)(void *st) nogil
    npy_uint64 (*next_raw)(void *st) nogil

ctypedef bitgen bitgen_t

See Extending for examples of using these functions.

The functions are named with the following conventions:

  • “standard” refers to the reference values for any parameters. For instance “standard_uniform” means a uniform distribution on the interval 0.0 to 1.0

  • “fill” functions will fill the provided out with cnt values.

  • The functions without “standard” in their name require additional parameters to describe the distributions.

  • Functions with inv in their name are based on the slower inverse method instead of a ziggurat lookup algorithm, which is significantly faster. The non-ziggurat variants are used in corner cases and for legacy compatibility.

double random_standard_uniform(bitgen_t *