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



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

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值