您的位置:首页 > 编程语言 > MATLAB

Matlab中rand('state',s)和rand('state',0)

2014-04-17 14:29 302 查看

RAND('state',0) resets the generator to its initial state.

RAND('state',J), for integer J, resets the generator to its J-th state.

RAND('state',J) and RAND('state',S) cause the MATLAB 5 generator to be used.

help 里面解释

rand('state',s)Resets the state to s.

rand('state',0)Resets the generator to its initial state.

rand('state',j)For integer j, resets the generator to its j-th state.

用法:

(一)rand('state',s)表示随机产生数的状态state,一般情况下不用指定状态。但是有的书籍作者为了让读者能够看到和他书本的同样结果,采用了设置state,rand('state',0)。作用在于如果指定状态,产生随机结果就相同了。

 

(二)因为每次rand产生的随机数都不一样,在产生之后,为了得到与前面某个状态相同的结果,用这个函数来产生该相同的随机数

如:>> a=rand(3,1)

a =

    0.4565

    0.0185

    0.8214

>> a=rand(3,1)

a =

    0.4447

    0.6154

    0.7919

>> a=rand(3,1)

a =

    0.9218

    0.7382

    0.1763



>> rand('state',0)

>> a=rand(3,1)

a =

    0.9501

    0.2311

    0.6068

>> rand('state',0)

>> a=rand(3,1)

a =

    0.9501

    0.2311

    0.6068

>> rand('state',0)

>> a=rand(3,1)

a =

    0.9501

    0.2311

    0.6068
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  matlab