By default, NS2 runs deterministic simulation. That is, you will get the same result for every run. The deterministic setting is usually good for debugging, where you would like to know what goes wrong at an exact point.

Random Setting

Statistical analysis involves running simulation for several times and find averages/variance for all the runs. NS2 is deterministic by default. The results from every run with default setting are the same, and the variance of the results is therefore zero. Statistical analysis require randomness so that the avarages and variances would be meaningful.

In order to introduce a randomness to NS2, you will need to insert the following line into the Tcl Simulation script prior to "$ns run":

$defaultRNG seed n

where

By default, NS2 sets n

$default seed 101

the result would be different from the result corresponding to the default setting. But all the result with n

T. Issaraiyakul and E. Hossain, "Introduction to Network Simulator

NS2", Springer 2008.

http://www.springer.com/engineering/signals/book/978-0-387-71759-3

You may also find the following website useful:

http://www.ece.ubc.ca/~teerawat/NS2.htm

## 11 comments:

This assumes that you are using the ns-2 facilities for getting the random numbers. If (for example) you are using c++ function rand(), then this won't solve it.

Yeah. This is good for NS2 only. In other languages, you may need different approaches.

Even, in NS2, this option works for Tcl only. If you would like to work on C++ part of NS2 you may need different approaches (which provide more functionality including the implementation of various random variables and/or multiple stream random number generators).

But for the beginner, putting "defaultRNG set n" would be an quick start to generate statistically independent results.

hi mr..Im fauzan,from indonesia..i want implemented Evolutionary Algorthm in NS 2.35 to optimized relay..could u teach me how to implemented in NS 2...i using OLSR..please helpme..

How much do you know about NS2? If you are new to NS2, I suggest you to read the following blog post.

http://www.ns2ultimate.com/post/434349586/for-ns2-newbies

In future correspondence, please be specific on your questions so that I can help you properly.

If you have NS2 book, you can refer to

http://www.ns2ultimate.com/post/503046431/how-to-read-my-book

for a quick startup. This is (in my opinion) the fastest way to start using NS2 properly.

Also, please read the following blog post, which is a guidance for asking right questions.

http://www.ns2ultimate.com/post/535741560/assistance-and-ethics

Hi boss!!!!!

I am running a simulation and I am having the same result all the times. I change the seed, but is always the same: the results!!!

I put this line

global defaultRNG

$defaultRNG seed 0

I put your suggestion in the NS Ultimate site..but nothing works..the same results...every simulation I do and using AODV and DSR protocols. Could you give an idea..what is this happening??

Best regards!!!

@ Ederval

What you did is to set the seed to be zero. That's mean the simulation result would be the same every time.

What you should do is to change the seed to 0, 1, 2, 3 and so on. You can do this by

1st run...

$defaultRNG seed 0

2nd run...

$defaultRNG seed 1

3rd run...

$defaultRNG seed 2

4th run...

$defaultRNG seed 3

Hi, I am working on some simulation in NS right now, trying to calculate the average throughput. No matter what seed I set ( I am passing this by command line arguments), I get the same value. Can you help me with where I might be going wrong?

You cannot passing the seed from the command line. You have to do it within the Tcl simulation script.

Hi Dr. Teerawat,

I am trying to add randomness in a wired network simulation by using $defaultRNG seed 0, $defaultRNG seed 1, and so on but every time I get the same trace file. However, when I did the same for wireless networks I got different traces for the same network topology. Kindly shed light into it.

Sir I'm trying to add mobility to UEs in an lte patched version of ns2, the usual setdest command is giving an error; do you know anything about it?

how to randomly generate malicious node in AODV (using rand() function)?

Post a Comment