gpurng
R2026bControl random number generation on the GPU
Syntax
Description
gpurng("default") initializes the GPU random number generator
using the default algorithm and seed. The default algorithm is the Threefry 4x64
generator with seed 0. If the GPU is part of a cluster, each GPU
in a cluster working on the same job has an independent random number stream. The
random numbers produced are the same as if you had restarted MATLAB®.
The gpurng function controls the global GPU stream, which
determines how the rand, randi, randn, and randperm functions produce a
sequence of random numbers on the GPU. To create one or more independent streams
separate from the global GPU stream, see parallel.gpu.RandStream.
gpurng( specifies the seed for the GPU random
number generator using the current generator algorithm.seed)
Specify
seedas a nonnegative integer, such asgpurng(1), to initialize the GPU random number generator with that seed.Specify
seedas"shuffle"to initialize the generator seed based on the current time so thatrand,randi,randn, andrandpermproduce different sequences of numbers after each time you callgpurng.
gpurng( specifies the algorithm
for the GPU random number generator to use with a seed of generator)0. This
syntax is equivalent to gpurng(0,generator). (since R2023b)
gpurng( restores the random number generator based
on the settings contained in a structure s)s with fields
Type, Seed, and State.
The structure s must be a structure that is returned by a
previous call to s = gpurng or s = gpurng(__).
returns the current settings
of the random number generator as a structure s = gpurngs with fields
Type, Seed, and
State.
returns the current
settings of the random number generator in a structure s = gpurng(___)s before
changing the settings using the specified arguments.
Note
The default algorithm and seed for the random number generator in the MATLAB
Settings Window window affect random numbers generated on
the CPU only and do not affect calls to gpurng("default").
