Random sampling (cupy.random
)#
Differences between cupy.random
and numpy.random
:
Most functions under
cupy.random
support thedtype
option, which do not exist in the corresponding NumPy APIs. This option enables generation of float32 values directly without any space overhead.cupy.random.default_rng()
uses XORWOW bit generator by default.Random states cannot be serialized. See the description below for details.
CuPy does not guarantee that the same number generator is used across major versions. This means that numbers generated by
cupy.random
by new major version may not be the same as the previous one, even if the same seed and distribution are used.
New Random Generator API#
Random Generator#
|
Construct a new Generator with the default BitGenerator (XORWOW). |
|
Container for the BitGenerators. |
Bit Generators#
|
Generic BitGenerator. |
CuPy provides the following bit generator implementations:
|
BitGenerator that uses cuRAND XORWOW device generator. |
|
BitGenerator that uses cuRAND MRG32k3a device generator. |
|
BitGenerator that uses cuRAND Philox4x3210 device generator. |
Legacy Random Generation#
|
Portable container of a pseudo-random number generator. |
Functions in cupy.random
#
|
Beta distribution. |
|
Binomial distribution. |
|
Returns random bytes. |
|
Chi-square distribution. |
|
Returns an array of random values from a given 1-D array. |
|
Dirichlet distribution. |
|
Exponential distribution. |
|
F distribution. |
|
Gamma distribution. |
|
Geometric distribution. |
|
Returns an array of samples drawn from a Gumbel distribution. |
|
hypergeometric distribution. |
|
Laplace distribution. |
|
Logistic distribution. |
|
Returns an array of samples drawn from a log normal distribution. |
|
Log series distribution. |
|
Returns an array from multinomial distribution. |
|
Multivariate normal distribution. |
|
Negative binomial distribution. |
|
Noncentral chisquare distribution. |
|
Noncentral F distribution. |
|
Returns an array of normally distributed samples. |
|
Pareto II or Lomax distribution. |
|
Returns a permuted range or a permutation of an array. |
|
Poisson distribution. |
|
Power distribution. |
|
Returns an array of uniform random values over the interval |
|
Returns a scalar or an array of integer values over |
|
Returns an array of standard normal random values. |
|
Returns an array of random values over the interval |
|
Return a scalar or an array of integer values over |
|
Returns an array of random values over the interval |
|
Returns an array of random values over the interval |
|
Rayleigh distribution. |
|
Returns an array of random values over the interval |
|
Resets the state of the random number generator with a seed. |
|
Shuffles an array. |
|
Standard cauchy distribution. |
|
Standard exponential distribution. |
|
Standard gamma distribution. |
|
Returns an array of samples drawn from the standard normal distribution. |
|
Standard Student's t distribution. |
|
Triangular distribution. |
|
Returns an array of uniformly-distributed samples over an interval. |
|
von Mises distribution. |
|
Wald distribution. |
|
weibull distribution. |
|
Zipf distribution. |
CuPy does not provide cupy.random.get_state
nor cupy.random.set_state
at this time.
Use the following CuPy-specific APIs instead.
Note that these functions use cupy.random.RandomState
instance to represent the internal state, which cannot be serialized.
Gets the state of the random number generator for the current device. |
|
|
Sets the state of the random number generator for the current device. |