cupy.random.RandomState

class cupy.random.RandomState(seed=None, method=100)[source]

Portable container of a pseudo-random number generator.

An instance of this class holds the state of a random number generator. The state is available only on the device which has been current at the initialization of the instance.

Functions of cupy.random use global instances of this class. Different instances are used for different devices. The global state for the current device can be obtained by the cupy.random.get_random_state() function.

Parameters:
  • seed (None or int) – Seed of the random number generator. See the seed() method for detail.
  • method (int) –

    Method of the random number generator. Following values are available:

    cupy.cuda.curand.CURAND_RNG_PSEUDO_DEFAULT
    cupy.cuda.curand.CURAND_RNG_XORWOW
    cupy.cuda.curand.CURAND_RNG_MRG32K3A
    cupy.cuda.curand.CURAND_RNG_MTGP32
    cupy.cuda.curand.CURAND_RNG_MT19937
    cupy.cuda.curand.CURAND_RNG_PHILOX4_32_10
    

Methods

choice(a, size=None, replace=True, p=None)[source]

Returns an array of random values from a given 1-D array.

See also

cupy.random.choice() for full document, numpy.random.choice()

gumbel(loc=0.0, scale=1.0, size=None, dtype=<class 'float'>)[source]

Returns an array of samples drawn from a Gumbel distribution.

See also

cupy.random.gumbel() for full documentation, numpy.random.RandomState.gumbel()

interval(mx, size)[source]

Generate multiple integers independently sampled uniformly from [0, mx].

Parameters:
  • mx (int) – Upper bound of the interval
  • size (None or int or tuple) – Shape of the array or the scalar returned.
Returns:

If None, an cupy.ndarray with shape () is returned. If int, 1-D array of length size is returned. If tuple, multi-dimensional array with shape size is returned. Currently, only 32 bit integers can be sampled. If 0 \(\leq\) mx \(\leq\) 0x7fffffff, a numpy.int32 array is returned. If 0x80000000 \(\leq\) mx \(\leq\) 0xffffffff, a numpy.uint32 array is returned.

Return type:

int or cupy.ndarray

lognormal(mean=0.0, sigma=1.0, size=None, dtype=<class 'float'>)[source]

Returns an array of samples drawn from a log normal distribution.

normal(loc=0.0, scale=1.0, size=None, dtype=<class 'float'>)[source]

Returns an array of normally distributed samples.

See also

cupy.random.normal() for full documentation, numpy.random.RandomState.normal()

permutation(num)[source]

Returns a permuted range.

rand(*size, **kwarg)[source]

Returns uniform random values over the interval [0, 1).

See also

cupy.random.rand() for full documentation, numpy.random.RandomState.rand()

randint(low, high=None, size=None, dtype='l')[source]

Returns a scalar or an array of integer values over [low, high).

randn(*size, **kwarg)[source]

Returns an array of standard normal random values.

See also

cupy.random.randn() for full documentation, numpy.random.RandomState.randn()

random_sample(size=None, dtype=<class 'float'>)[source]

Returns an array of random values over the interval [0, 1).

seed(seed=None)[source]

Resets the state of the random number generator with a seed.

See also

cupy.random.seed() for full documentation, numpy.random.RandomState.seed()

shuffle(a)[source]

Returns a shuffled array.

See also

cupy.random.shuffle() for full document, numpy.random.shuffle()

standard_normal(size=None, dtype=<class 'float'>)[source]

Returns samples drawn from the standard normal distribution.

tomaxint(size=None)[source]

Draws integers between 0 and max integer inclusive.

Parameters:size (int or tuple of ints) – Output shape.
Returns:Drawn samples.
Return type:cupy.ndarray
uniform(low=0.0, high=1.0, size=None, dtype=<class 'float'>)[source]

Returns an array of uniformly-distributed samples over an interval.