All random number generator in MATLAB is pseudo random generator, so it starts from a number and do certain operations to get another number. If you start from the same place, e.g., s, you will always get same series of random numbers. In fact MATLAB currently has three random number generators. If you use 'seed', you are using one of them, if you are using 'state', you are using another one of them. The best one so far is 'twister', but it may not be in randn yet.
【在 m******t 的大作中提到】 : randn('state', s) - reset the state to s : 这个到底是什么意思啊? : 是说如果你连续run s次,出来的random number 都是一样的马?
【在 h***n 的大作中提到】 : All random number generator in MATLAB is pseudo random generator, so it : starts from a number and do certain operations to get another number. If : you start from the same place, e.g., s, you will always get same series of : random numbers. : In fact MATLAB currently has three random number generators. : If you use 'seed', you are using one of them, if you are using 'state', you : are using another one of them. The best one so far is 'twister', but it may : not be in randn yet.
c*g
5 楼
s0 = rand('state') %returns the current state of the random number generator, x = rand(10,1); % generate random number s1 = rand('state') % returns the current state of the random number generator disp([s0,s1]) % you will see s0 and s1 are different,that means the state changes each time you ran the random number generatror s0 =rand('state'); x1 = rand; x2 = rand; rand('state',s0); x3 = rand; x1,x2,x3, $ you will see that x1 = x3, x1~=x2
【在 r*****f 的大作中提到】 : 没明白, 我直接用randn产生一个1000*1的向量,但是不加任何 state, seed : 每次出来的也不一样啊.并不是从同样的数字开始的 : : you : may
r*f
6 楼
now that state change each time I ran the random generator, why should I specificly use 'seed' or 'state' to manually change it?
generator,
【在 c****g 的大作中提到】 : s0 = rand('state') %returns the current state of the random number generator, : x = rand(10,1); % generate random number : s1 = rand('state') % returns the current state of the random number : generator : disp([s0,s1]) % you will see s0 and s1 are different,that means the state : changes each time you ran the random number generatror : s0 =rand('state'); : x1 = rand; : x2 = rand; : rand('state',s0);
s*h
7 楼
try: close MATLAB open MATLAB input randn and record the number. then close MATLAB and open MATLAB input randn and see what happens.
h*n
8 楼
Because sometimes you may want to reproduce the behavior.
【在 r*****f 的大作中提到】 : now that state change each time I ran the random generator, why should I : specificly use 'seed' or 'state' to manually change it? : : generator,
【在 c****g 的大作中提到】 : s0 = rand('state') %returns the current state of the random number generator, : x = rand(10,1); % generate random number : s1 = rand('state') % returns the current state of the random number : generator : disp([s0,s1]) % you will see s0 and s1 are different,that means the state : changes each time you ran the random number generatror : s0 =rand('state'); : x1 = rand; : x2 = rand; : rand('state',s0);