Random number generator errors after switching modes from 'state' to 'shuffle'

19 views (last 30 days)
When I specify a seed value for the random number generator using:
randn('state', sd);
and then try to use the current time as the seed value using:
rng('shuffle');
MATLAB errors saying I need to reinitialize my random number generator: ERROR: Error using rng (line 99) The current random number generator is the legacy generator. This is because you have executed a command such as rand('state',0), which activates MATLAB's legacy random number behavior. You may not use RNG to reseed the legacy random number generator. Use rng('default') to reinitialize the random number generator to its startup configuration, or call RNG using a specific generator type, such as rng(seed,'twister').

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 7 Feb 2019
Using "rand" or "randn" with 'seed', state', or 'twister' inputs is no longer a recommended syntax. "rng" is encouraged instead. "rand" or "randn" will still run, but will use the legacy generator. Once "rand" or "randn" is used, "rng" cannot be used to reseed without reinitializing. More information on the encouraged syntax can be found in this article:

More Answers (0)

Categories

Find more on Random Number Generation in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!