for {set i 0} {$i < $num_nodes} {incr i} {
for {set j 0} {$j < 10} {incr j} {
$ns at [expr 7.2+[expr rand()*3.0]] "$n($i) send_message 10 1 {[expr round([expr rand()*100000])]:[expr round([expr rand()*$numdata1])]:1:-1:-1} $MESSAGE_PORT"
set generated1 [expr $generated1 + 1]
}
}
I am building code for request packet generation in tcl ns2. i found these line from the internet, but I cannot understand this line:
$ns at [expr 7.2+[expr rand()*3.0]] "$n($i) send_message 10 1 {[expr round([expr rand()*100000])]:[expr round([expr rand()*$numdata1])]:1:-1:-1} $MESSAGE_PORT"
please tell me what is the logic behind these above lines?
First of all, that's bad use of nested
expr. Cleaning that up:Looking at that word-by-word:
$nsat[expr {7.2+rand()*3.0}]"$n($i) send_message 10 1 {[expr {round(rand()*100000)}]:[expr {round(rand()*$numdata1)}]:1:-1:-1} $MESSAGE_PORT"$n($i)<== an associative array value at key$i[expr {round(rand()*100000)}]<== a random integer between 0 and 100,000[expr {round(rand()*$numdata1)}]<== a random integer between 0 and$numdata1After Tcl substitutes all that, we might have something like