gpucoder.rand
R2026bSyntax
Description
The gpucoder.rand function generates random numbers from a
uniform distribution. When you generate GPU code from gpucoder.rand, the
code uses the NVIDIA® cuRAND library to generate random numbers on the GPU. When you call
gpucoder.rand in MATLAB®, the function generates random numbers by using the rand function.
Note
Because the cuRAND library and MATLAB use different random number generators, the results of
gpucoder.rand
in MATLAB do not match the results from the generated GPU code.
returns a random scalar
from a uniform distribution. In MATLAB, the distribution is over the open interval (0,1). In the generated GPU
code, the distribution is over the half-open interval (0,1].X = gpucoder.rand
returns an X = gpucoder.rand(sz1,...,szN)sz1-by-...-by-szN array of random
numbers, where sz1,...,szN specifies the size of each
dimension.
Examples
Input Arguments
Output Arguments
Limitations
Generating complex numbers is not supported.
For code generation, if you use the
szinput argument, the vector must have a fixed size. If you use thesz1,...,szNinput arguments, the number of arguments must be constant. You can change the values inszorsz1,...,szNat run time.
Tips
In generated GPU code, a pseudorandom number generator determines the sequence of numbers generated by
gpucoder.rand,gpucoder.randi, andgpucoder.randn. To control the sequence of random numbers, use thegpucoder.rngfunction.
Extended Capabilities
Version History
Introduced in R2026b