开发者

'RandStream' is not defined in MATLAB 7.6.0.324?

I am trying to use RandStream in MATLAB 7.6.0.324 as below:

randst = RandStream('mrg32k3a', 'Seed', 0);

Apparently, RandStream is not defined on MATLAB 7.6.0.324 and I can not find a documentation about it.

How can I set random seed in this version of Matlab then for开发者_StackOverflow中文版 rand and randperm.


Most likely, you got code from someone who uses a newer version of MATLAB. The RandStream function was introduced in later versions of MATLAB (I don't remember which) and as you found out, does not exist in v7.6.0.324. In older versions, you simply set the seed inside rand like so:

rand('seed',0);
x=rand(1,5)

x =

0.2190    0.0470    0.6789    0.6793    0.9347
 

randperm on the other hand, calls rand inside it. So setting the seed for rand before calling randperm will give you the same output each time.

rand('seed',0);
y=randperm(5)

y =

     2     1     3     4     5

NOTE:

This syntax is not currently recommended (and support may be discontinued in future releases). From the documentation:

These rand and randn syntaxes are no longer recommended for the following reasons:

  • The terms 'seed' and 'state' are misleading names for the generators.
  • All of the former generators except 'twister' are flawed.
  • They unnecessarily use different generators for rand and randn.


you're obviously using an old version where the function hasn't been defined yet

try qrandstream

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜