lst = rng('enginelist')
rng('default')
s = rng('default')
rng('shuffle')
s = rng('shuffle')
rng(seed)
s = rng(seed)
rng(seed, generator)
s = rng(seed, generator)
rng('shuffle', generator)
s = rng('shuffle', generator)
s = rng
s = rng(generator)
rng(s)
rng(stream)
| Parameter | Description |
|---|---|
| seed | an integer value: new seed for random generator |
| generator | a string: 'twister', 'twister64', 'simdTwister', 'combRecursive', 'philox', 'threefry', 'laggedfibonacci607', 'pcg', 'xoshiro'. The keywords 'pcg64dxsm' and 'xoshiro256pp' are also accepted. |
| s | a struct or RandStream object |
| Parameter | Description |
|---|---|
| lst | a cell of strings. |
| s | a struct |
lst = rng('enginelist') returns the list of available random number generator.
rng('default') puts the settings of the random number generator to default values.
s = rng('default') puts the settings of the random number generator to default values.
rng('shuffle') puts the settings of the random number generator to default values and returns previous generator as an struct.
s = rng('shuffle') seeds the random number generator based on the current time.
rng(seed) seeds the random number generator using the nonnegative integer.
s = rng(seed) seeds the random number generator using the nonnegative integer and returns previous generator as an struct.
rng(seed, generator) seeds the random number generator using the nonnegative integer and specify also the type of generator used.
s = rng(seed, generator) seeds the random number generator using the nonnegative integer and specify also the type of generator used and returns previous generator as an struct.
rng('shuffle', generator) seeds the random number generator based on the current time and specify also the type of generator used.
s = rng('shuffle', generator) seeds the random number generator based on the current time,specify also the type of generator used and returns previous generator as an struct.
s = rng returns current generator as an struct.
rng(s) restores the settings of the random number generator using a previous struct returned bys = rng. rng(stream) restores the generator from a RandStream object.
Available generators are:
| Value | Generator Name | Generator Keyword |
|---|---|---|
| "twister" | Mersenne Twister | mt19937ar |
| "simdTwister" | SIMD-Oriented Fast Mersenne Twister | dsfmt19937 |
| "combRecursive" | Combined Multiple Recursive | mrg32k3a |
| "multFibonacci" | Multiplicative Lagged Fibonacci | mlfg6331_64 |
| "philox" | Philox 4x32 generator with 10 rounds | philox4x32_10 |
| "pcg" | 64-bit permuted congruential generator with double xor-shift multiply | pcg64dxsm |
| "xoshiro" | Xor-shift-rotate generator with 256-bit state and double addition | xoshiro256pp |
The "pcg" and "xoshiro" generators produce 64-bit outputs: each double uses 53 random bits and randn uses the inversion method (inverse normal cumulative distribution of a uniform value). Their state (s.State) is a uint64 column vector: the engine words (128-bit state and increment for "pcg", 256-bit state for "xoshiro"), the precision mode (0: full precision, 1: reduced precision set by the FullPrecision property of RandStream) and a cached 32-bit half output used by the reduced precision mode. The seed is expanded into the engine state with the SplitMix64 generator.
Default generator is "twister".
rng('default');
r = rng()
lst = rng('enginelist')
rng(42, 'xoshiro');
s = rng();
a = rand(1, 3);
rng(s);
b = rand(1, 3);
isequal(a, b)
s.Type
| Version | Description |
|---|---|
| 1.0.0 | initial version |
| 1.15.0 | New random number generator: simdTwister, combRecursive, philox |
| 2.0.0 | New random number generators: pcg (pcg64dxsm) and xoshiro (xoshiro256pp) |