Internet of Things with Moodle
Its a Test post showcasing Internet of Things with MOODLE
T S Pradeep Kumar
T S Pradeep Kumar
Listing 1 – Random Number Generation Sample
#create the random number generation using RNG
set rand1 [new RNG]
set rand2 [new RNG]
set rand3 [new RNG]
#$repli is the value set already and it can be either 1
or <1 or >1
for {set i 1} {$i < $repli} {incr i} {
$rand1 nextsubstream;
$rand2 nextsubstream;
$rand3 nextsubstream;
}
Here are the distributions
Pareto Distribution
set r1 [new RandomVariable/Pareto]
$r1 userng $rand1
$r1 set avg_ 10.0
$r1 set shape_ 1.2
Constant – Specifies the constant number
set r2 [new RandomVariable/Constant]
$r2 userng $rand2
$r2 set val_ 5.0
Uniform distribution – Specifies the min and
max number
set r3 [new RandomVariable/Uniform]
$r3 userng $rand3
$r3 set min_ 0.0
$r3 set max_ 10.0
Exponential distribution. Specified the
average value:
set r4 [new RandomVariable/Exponential]
$r4 userng $rand1
$r4 set avg_ 5
Hyperexponential distribution
set r5 [new RandomVariable/HyperExponential]
$r5 userng $rand2
$r5 set avg_ 1.0
$r5 set cov_ 4.0

Listing 2 – Random number generation – Case 1
#filename : randtest1.tcl
#
# Usage: ns randtest.tcl [replication number]
#
if {$argc > 1} {
puts
"Usage: ns randtest1.tcl \[replication number\]"
exit
}
set run 1
if {$argc == 1} {
set run [lindex
$argv 0]
}
if {$run < 1} {
set run 1
}
# seed the default RNG
global defaultRNG
$defaultRNG seed 9999
# create the RNGs and set them to the correct substream
set arrivaldist [new RNG]
set size [new RNG]
for {set j 1} {$j < $run} {incr j} {
$arrivaldist nextsubstream
$size
nextsubstream
}
# arrival_ is a exponential random variable describing
the time between
# consecutive packet arrivals
set arrival_ [new RandomVariable/Exponential]
$arrival_ set avg_ 5
$arrival_ userng $arrivaldist
# size_ is a uniform random variable describing packet
sizes
set size_ [new RandomVariable/Uniform]
$size_ set min_ 100
$size_ set max_ 5000
$size_ userng $size
# print the first 5 arrival times and sizes
for {set j 0} {$j < 5} {incr j} {
puts [format
"%8.3f %4d" [$arrival_
value] \
[expr round([$size_ value])]]
}

Here is the sample output for above
file
Prompt]
~/nsallinone2.35/ns2.35/tcl/ex $ ns randtest1.tcl 0
6.358 4783
5.828 1732
1.469 2188
0.732 3076
4.002 626
Prompt]~/nsallinone2.35/ns2.35/tcl/ex
$ ns randtest1.tcl 1
6.358 4783
5.828 1732
1.469 2188
0.732 3076
4.002 626
Prompt]~/nsallinone2.35/ns2.35/tcl/ex
$ ns randtest1.tcl 2
2.091 153
12.085 4732
3.588 2329
1.201 230
5.161 2980
Prompt]~/nsallinone2.35/ns2.35/tcl/ex
$ ns randtest1.tcl 3
2.515 1119
3.154 3118
9.673 1201
13.346 2515
7.052 2115
Prompt]~/nsallinone2.35/ns2.35/tcl/ex
$ ns randtest1.tcl 100
8.940 2149
0.888 4870
0.998 4860
1.801 1205
18.224 2534
Prompt]~/nsallinone2.35/ns2.35/tcl/ex
$ ns randtest1.tcl 0.5
6.358 4783
5.828 1732
1.469 2188
0.732 3076
4.002 626
