How to create random/dynamic topology in NS2

Description

The dynamic topology can be created using rand function in Tool Command Language (TCL) script with fixed number of nodes. The nodes can be deployed in the area of X & Y. Each node is assigned with a random location within X & Y using rand function. In dynamic topology, the neighbors of each node vary with the location of that particular node. The code segment in sample2.tcl file demonstrates the dynamic topology in wireless network with 2 nodes that are deployed in the area of 500m & 400m.

#Filename: sample2.tcl

#*******************Random Topology Creation*******************#
#Random Location for a two nodes

for {set i 0} {$i < 2} {incr i} {

$node_($i) set X_ [expr rand()*500]
$node_($i) set Y_ [expr rand()*400]
$node_($i) set Z_ 0

}