avatar
matlab 里面的randn# EE - 电子工程
m*t
1
randn('state', s) - reset the state to s
这个到底是什么意思啊?
是说如果你连续run s次,出来的random number 都是一样的马?
avatar
s*h
2
我一般这样做:
rand('state', sum(100*clock));
由当前时间来确定初态。
要不然你每次打开matlab, randn输出的结果一样。
说白来了是pseudo-random.
avatar
h*n
3
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 都是一样的马?

avatar
r*f
4
没明白, 我直接用randn产生一个1000*1的向量,但是不加任何 state, seed
每次出来的也不一样啊.并不是从同样的数字开始的

you
may

【在 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.

avatar
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

avatar
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);

avatar
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.
avatar
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,

avatar
m*t
9
ok, 我理解的意思是如果你每次都从相同的state开始, 出来的结果就是一样的random
sequence, 但是randn('state', 100) 和randn('state', 1)除了是不同的state, 还有
区别马? 都是给定一个起始状态就是了吧.

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);

avatar
z*n
10
给一个seed并不能让输出变成真正的random,
seed只是改变了输出序列的开始值。

【在 s****h 的大作中提到】
: 我一般这样做:
: rand('state', sum(100*clock));
: 由当前时间来确定初态。
: 要不然你每次打开matlab, randn输出的结果一样。
: 说白来了是pseudo-random.

avatar
z*n
11
matlab的randn里面应该有随机化机制。我的经验跟你一样。

【在 r*****f 的大作中提到】
: 没明白, 我直接用randn产生一个1000*1的向量,但是不加任何 state, seed
: 每次出来的也不一样啊.并不是从同样的数字开始的
:
: you
: may

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。