RNG
控制随机数生成器
Syntax
描述
rng(
指定MATLAB的种子®随机数生成器。例如,seed
)rng(1)
使用一种种子初始化Mersenne Twister Generator1
。
TheRNG
function controls the全球流, which determines how therand
,randi
,randn
, 和randperm
functions produce a sequence of random numbers. To create one or more independent streams separate from the global stream, seeRandStream
和RandStream.create
。
s =RNG
返回结构中的当前随机数生成器设置s
。
例子
Input Arguments
提示
When you perform parallel processing, do not use
RNG(“洗牌”)
to set the random number stream on different workers to ensure independent streams since it seeds the random number generator based on the current time. This is especially true when the command is sent to multiple workers simultaneously, such as inside aparfor
job. For independent streams on the workers, use the default behavior or consider using a unique substream on each worker usingRandStream
。When you perform parallel processing, the default random number generators on the MATLAB client and MATLAB workers are different. If you need to generate the same random stream of numbers on the client and workers, you can use
RNG
with the same generator type and seed (or consider usingRandStream
具有相同的发电机类型,种子和正常转化算法)。有关更多信息,请参阅Control Random Number Streams on Workers(Parallel Computing Toolbox)。To use
RNG
instead of therand
或者randn
functions with the'种子'
,'状态'
, or'twister'
inputs, see替换Rand和Randn的灰心语法。