回 帖 发 新 帖 刷新版面

主题:求助关于由rand()产生随机数的问题

matlab中rand这个函数能产生[0,1]之间的随机数,但matlab的这个随机性我似乎理解错了。我打开matlab,输入rand(1,100),产生一个结果;然后我把matlab整个关掉,再重新打开它,再次输入rand(1,100),两次输出的结果居然一样,实验了n次都一样。但是如果不关闭软件直接输入两次rand(1,100),则出来不同的结果。rand这个函数能产生[0,1]之间的随机数好像是有一定的顺序,我要得到与顺序无关的任意的(0,1)之间的随机数怎么办呢?急用,希望能得到帮助。

回复列表 (共6个回复)

沙发

The sequence of numbers produced by RAND is determined by the internal
    state of the generator.  Setting the generator to the same fixed state
    allows computations to be repeated.  Setting the generator to different
    states leads to unique computations, however, it does not improve any
    statistical properties.  Since MATLAB resets the state at start-up, RAND
    will generate the same sequence of numbers in each session unless the
    state is changed.

板凳

已经在Matlab重新启动的话,会再次被重置,就是回到初始状态

3 楼

没有遇到过这种情况,每次都不一样

4 楼

自己问matlab不就完了

help rand

据说目前最好的是日本人的算法,matlab给出的参考文献是 http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html

5 楼

Matlab之父Cleve Mole的书Numerical Computing with MATLAB (2004)的第9章一开始就说了  

Here is an interesting number
    0.95012928514718
This is the first number produced by the Matlab random number generator with its default settings. Start up a fresh Matlab, set format long, type rand, and it's the number you get.

If all Matlab users, all around the world, all on different computers, keep getting this same number,a is it really "random"? No, it isn't.

所以不知道3楼的Matlab为什么会不在此列?

6 楼

Matlab之父Cleve Mole的书Numerical Computing with MATLAB (2004)的第9章一开始就说了  

Here is an interesting number
    0.95012928514718
This is the first number produced by the Matlab random number generator with its default settings. Start up a fresh Matlab, set format long, type rand, and it's the number you get.

If all Matlab users, all around the world, all on different computers, keep getting this same number,a is it really "random"? No, it isn't.

所以不知道3楼的Matlab为什么会不在此列?

我来回复

您尚未登录,请登录后再回复。点此登录或注册