gpucoder.randi
R2026bSyntax
Description
The gpucoder.randi function generates random integers from a
discrete uniform distribution. When you generate GPU code from
gpucoder.randi, the code uses the NVIDIA® cuRAND library to generate random integers on the GPU. When you call
gpucoder.randi in MATLAB®, the function generates random integers by using the randi function.
Note
Because the cuRAND library and MATLAB use different random number generators, the results of
gpucoder.randi
in MATLAB do not match the results from the generated GPU code.
returns an X = gpucoder.randi(imax,sz1,...,szN)sz1-by-...-by-szN array where each
argument in sz1,...,szN indicates 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.If
iminorimaxare outside of the minimum or maximum values of the selected type,gpucoder.randifirst generates random integers in the range[imin,imax]. The function then maps values outside of the minimum or maximum value of the output type to the nearest endpoint.
Extended Capabilities
Version History
Introduced in R2026b