Random Sampling (cupy.random)

The big difference of cupy.random from numpy.random is that cupy.random supports dtype option for most functions. This option enables us to generate float32 values directly without any space overhead.

Unlike NumPy, CuPy allows itself to replace its random number generator across its major versions. It means that numbers generated by cupy.random of a new major version may not be the same as that of its previous one even if the same seed and distribution are used.

Sample random data

cupy.random.rand Returns an array of uniform random values over the interval [0, 1).
cupy.random.randn Returns an array of standard normal random values.
cupy.random.randint Returns a scalar or an array of integer values over [low, high).
cupy.random.random_integers Return a scalar or an array of integer values over [low, high]
cupy.random.random_sample Returns an array of random values over the interval [0, 1).
cupy.random.random Returns an array of random values over the interval [0, 1).
cupy.random.ranf Returns an array of random values over the interval [0, 1).
cupy.random.sample Returns an array of random values over the interval [0, 1).
cupy.random.choice Returns an array of random values from a given 1-D array.
cupy.random.bytes Returns random bytes.

Distributions

cupy.random.beta Beta distribution.
cupy.random.binomial Binomial distribution.
cupy.random.chisquare Chi-square distribution.
cupy.random.dirichlet Dirichlet distribution.
cupy.random.exponential Exponential distribution.
cupy.random.f F distribution.
cupy.random.gamma Gamma distribution.
cupy.random.geometric Geometric distribution.
cupy.random.gumbel Returns an array of samples drawn from a Gumbel distribution.
cupy.random.laplace Laplace distribution.
cupy.random.lognormal Returns an array of samples drawn from a log normal distribution.
cupy.random.multinomial Returns an array from multinomial distribution.
cupy.random.multivariate_normal (experimental) Multivariate normal distribution.
cupy.random.normal Returns an array of normally distributed samples.
cupy.random.pareto Pareto II or Lomax distribution.
cupy.random.poisson Poisson distribution.
cupy.random.standard_cauchy Standard cauchy distribution.
cupy.random.standard_exponential Standard exponential distribution.
cupy.random.standard_gamma Standard gamma distribution.
cupy.random.standard_normal Returns an array of samples drawn from the standard normal distribution.
cupy.random.standard_t Standard Student’s t distribution.
cupy.random.uniform Returns an array of uniformly-distributed samples over an interval.
cupy.random.vonmises von Mises distribution.
cupy.random.zipf Zipf distribution.

Random generator

cupy.random.RandomState Portable container of a pseudo-random number generator.
cupy.random.seed Resets the state of the random number generator with a seed.
cupy.random.get_random_state Gets the state of the random number generator for the current device.
cupy.random.set_random_state Sets the state of the random number generator for the current device.

Note

CuPy does not provide cupy.random.get_state nor cupy.random.set_state at this time. Use cupy.random.get_random_state() and cupy.random.set_random_state() instead. Note that these functions use cupy.random.RandomState instance to represent the internal state, which cannot be serialized.

Permutations

cupy.random.shuffle Shuffles an array.
cupy.random.permutation Returns a permuted range or a permutation of an array.