主题:求助关于由rand()产生随机数的问题
wgm529
[专家分:0] 发布于 2008-03-24 09:39:00
matlab中rand这个函数能产生[0,1]之间的随机数,但matlab的这个随机性我似乎理解错了。我打开matlab,输入rand(1,100),产生一个结果;然后我把matlab整个关掉,再重新打开它,再次输入rand(1,100),两次输出的结果居然一样,实验了n次都一样。但是如果不关闭软件直接输入两次rand(1,100),则出来不同的结果。rand这个函数能产生[0,1]之间的随机数好像是有一定的顺序,我要得到与顺序无关的任意的(0,1)之间的随机数怎么办呢?急用,希望能得到帮助。
回复列表 (共6个回复)
沙发
blivfate [专家分:720] 发布于 2008-03-24 22:54:00
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.
板凳
blivfate [专家分:720] 发布于 2008-03-24 22:55:00
已经在Matlab重新启动的话,会再次被重置,就是回到初始状态
3 楼
chinasoul [专家分:140] 发布于 2008-03-25 15:27:00
没有遇到过这种情况,每次都不一样
4 楼
sjohn [专家分:5600] 发布于 2008-03-27 16:00:00
自己问matlab不就完了
help rand
据说目前最好的是日本人的算法,matlab给出的参考文献是 http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
5 楼
sjohn [专家分:5600] 发布于 2008-03-27 16:13:00
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 楼
sjohn [专家分:5600] 发布于 2008-03-27 16:16:00
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为什么会不在此列?
我来回复