加入收藏 | 设为首页 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > 原创教程 > NS2网络模拟与仿真

NS2中随机数应用举例

时间:2011-07-29 17:32:42  来源:  作者:

当随机数种子seed为0时,每次得到的随机变量值为任意的,是不重复的,当随机数种子seed为某个非零值时,虽然当seed不同时(如1,2),得到的变量值不同,但每次运行ns RV.tcl时当

set count 3

for {set i 0} {$i < 3} {incr i} {
        puts "===== i = $i"

        set MyRng1 [new RNG]                                          #定义随机数发生器(并指定seed),后面要通过随机数发送器产生随机变量
        $MyRng1 seed $i

        set MyRng2 [new RNG]                                          #定义随机数发生器(并指定seed),后面要通过随机数发送器产生随机变量
        $MyRng2 seed $i

        set r1 [new RandomVariable/Pareto]                 #使用随机数发送器$MyRng1产生随机变量r1
        $r1 use-rng $MyRng1
        $r1 set avg_ 10.0
        $r1 set shape_ 1.2
        puts stdout "Testing Pareto Distribution,avg = [$r1 set avg_]  shape=[$r1 set shape_]"
        $r1 test $count                                                      #产生3个随机数(因为$count=3)

        set r2 [new RandomVariable/Pareto]
        $r2 use-rng $MyRng2
        $r2 set avg_ 10.0
        $r2 set shape_ 1.2
        puts stdout "Testing Pareto Distribution,avg = [$r2 set avg_]  shape=[$r2 set shape_]"
        $r2 test $count
}

输出结果:

[root@localhost 7]# ns rv.tcl
===== i = 0                                                               当i=0(即seed为0)时
Testing Pareto Distribution,avg = 10  shape=1.2
3.883571e+00                                                                                             
1.688700e+00
2.291968e+00
Testing Pareto Distribution,avg = 10  shape=1.2
5.517943e+00
5.370109e+00
1.851364e+00
===== i = 1
Testing Pareto Distribution,avg = 10  shape=1.2
1.296383e+03
2.718717e+00
5.774172e+01
Testing Pareto Distribution,avg = 10  shape=1.2
1.296383e+03
2.718717e+00
5.774172e+01
===== i = 2
Testing Pareto Distribution,avg = 10  shape=1.2
7.323108e+02
1.034996e+01
3.241146e+01
Testing Pareto Distribution,avg = 10  shape=1.2
7.323108e+02
1.034996e+01
3.241146e+01

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
在CentOS下搭建Android 开发环境
在CentOS下搭建Androi
轻松搭建属于自己的Ubuntu发行版
轻松搭建属于自己的Ub
利用SUSE Studio 打造自己的个性化Linux发行版
利用SUSE Studio 打造
那些采用PHP技术的IT大企业
那些采用PHP技术的IT大
相关文章
栏目更新
栏目热门