How to duplicate rand('twister', 0) in current Matlab?
이전 댓글 표시
Hi everyone,
I am trying to change my old code to use the new RNG in current Matlab (R2011a).
In my old code, I usually have something like this,
>> rand('twister', 1);
>> x = rand(1, 1e5);
So I have tried the following experiment to verify that RNG will give me the same random numbers,
>> rng(1, 'twister'); x1 = rand(1,100);
>> rand('twister', 1); x2 = rand(1,100);
>> max(abs(x1 - x2))
ans =
0
So this works for seed = 1. However when I try setting seed to 0, then they do not match,
>> rng(0, 'twister'); x1 = rand(1,100);
>> rand('twister', 0); x2 = rand(1,100);
>> max(abs(x1 - x2))
ans =
0.817037959716122
A while back (probably year ago), I have posted some comment about random stream (back then, this is a new feature) and seed of 0 have come up in the discussion. But I cannot find the discussion any more.
So my question: how can I use RNG to duplicate the effect of rand('twister', 0)?
Also besides 0, is there any other seed having this problem?
Thanks Kevin
채택된 답변
추가 답변 (2개)
Sean de Wolski
2012년 2월 6일
0 is the same as the MT default in the original paper, 5489.
rng(0,'twister'); x1 = rand(1,100);
rand('twister', 5489); x2 = rand(1,100);
isequal(x1,x2)
Kevin
2012년 2월 6일
댓글 수: 2
Peter Perkins
2012년 2월 7일
Yes, although
* The seed need not be an unsigned 32 bit integer type, it can be any numeric type. It just has to be an integer _value_. So type "1", not "uint32(1)".
* 5489 is perfectly acceptable as itself. 0 is just a shorthand.
Kevin
2012년 2월 7일
카테고리
도움말 센터 및 File Exchange에서 Entering Commands에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!