FUNCTION REFERENCE

rng

Seed or query the session's random number generator.

Seed or query the session's random number generator.

Syntax

rng(seed)

Syntax

rng(seed, generator)

Syntax

rng(generator)

Syntax

rng('default')

Syntax

rng('shuffle')

Syntax

s = rng

Syntax

s = rng(...)

Syntax

rng(s)

Controls the shared rand, randn, randi and randperm stream. Supported generators are 'twister' (default, MT19937), 'philox' (Philox4x32-10) and 'combRecursive' (MRG32k3a, also accepted as 'mrg32k3a'). Seed must be an integer from 0 to 2^32-1, inclusive. 'mt19937ar' is accepted as an alias for 'twister'. 'default' selects 'twister' with seed 0; 'shuffle' derives a seed from the current time. s = rng returns a struct with Type, Seed and State (625x1 uint32 for 'twister'); s = rng(...) returns the previous settings; rng(s) restores the saved state.

Example

s=rng; a=rand(1,2); rng(s); b=rand(1,2); isequal(a,b)   % 1

Differences from MATLAB: 'simdTwister', 'v4', 'v5uniform' and 'v5normal' are not supported. No claim that doubles match MATLAB bit-for-bit for 'philox', 'combRecursive', or randn.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.