Not getting random node positions each time I run a simulation. PLEASE HELP!!

78 views
Skip to first unread message

Spandan Chowdhury

unread,
Nov 24, 2017, 12:44:47 AM11/24/17
to ns-3-users
Hi All,

I am trying to run a simulation for routing with AODV in MANETs.
I am using the code given below to allocate positions randomly to the nodes:

MobilityHelper mobiles;
 
ObjectFactory pos;
  pos
.SetTypeId("ns3::RandomRectanglePositionAllocator");
  pos
.Set ("X", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=500.0]"));
  pos
.Set ("Y", StringValue ("ns3::UniformRandomVariable[Min=0.0|Max=500.0]"));
 
Ptr<PositionAllocator> posAlloc = pos.Create()->GetObject<PositionAllocator>();
  mobiles
.SetMobilityModel("ns3::RandomWaypointMobilityModel",
                           
"Speed", StringValue ("ns3::UniformRandomVariable[Min=0|Max=60]"),
                           
"Pause", StringValue ("ns3::ConstantRandomVariable[Constant=0.0]"),
                           
"PositionAllocator", PointerValue(posAlloc));
  mobiles
.SetPositionAllocator (posAlloc);
  mobiles
.Install(node);

However, every time I run the simulation, after I open the animation file with NetAnim, I see that the nodes are at the same starting position every time. Why is this happening?
More importantly, can anyone tell me what I am doing wrong, or how can I get actually randomly positioned nodes every time I run the simulation?
And by running the simulation I mean executing this:
$ ./waf --run scratch/<filename>

I thought there is something wring with my code, and I tried running the manet-routing-compare.cc too, but it is also giving the same result- nodes in the same position everytime.

I am sure I am probably doing some silly mistake here. Kindly help me out.

Thanks

Steffen Lindner

unread,
Nov 24, 2017, 3:05:35 AM11/24/17
to ns-3-users
You have to set a different seed for the random geneator. Otherwise you will get the same random numbers (based in the same seed)

Spandan Chowdhury

unread,
Nov 24, 2017, 6:22:42 PM11/24/17
to ns-3-users
If it is not too much of a trouble, can you please post a sample code showing an example of it?

Tommaso Pecorella

unread,
Nov 25, 2017, 8:21:35 AM11/25/17
to ns-3-users
examples//tcp/tcp-variants-comparison.cc

T.
Reply all
Reply to author
Forward
0 new messages