Hi All
I came across a protocol implementation by a researcher. He needs to call a function every second that gets values from uniform distribution in range (0, maxval.size() ) , the value of
maxval, which is a vector, also changes every second and it maximum value is 14. Therefore in every call to function per second the author declares random variable every time like
void getSLotNumber()
{
UniformVariable x(0, maxval.size() );
val=x.GetInteger();
}
1. Is it correct to declare random variable again and again?
I have used other technique knowing that maxval.size() is maximum 14, by declaring Ptr<UniformRandomVariable> x initially as class object and then based on the size of current maxval i scale down the retrieved values in desired range (0, currentsize of vector). I did following:
// declared variable in class
Ptr<UniformRandomVariable> x;
// in constructor initialized variable and assigned range
x = CreateObject<UniformRandomVariable> ();
double min = 0.0;
double max = 14.0;
x->SetAttribute ("Min", DoubleValue (min));
x->SetAttribute ("Max", DoubleValue (max));
// and called function every second this way
void getSLotNumber()
{
y=x->GetInteger);
val=scaleWRT( maxval.size(),y ) // if current vector size is 5 then scales y value in
// range (0,5) instead of (0,14) using scaleWRT() function created
}
This way i dont need to redeclare random variable again and again due dynamic size of vairable (vector size)
But the pattern of random variable i got after scaling is quite different from what i get when i used already implemented logic with uniform variable declared every time. Any comments please.
I have also found in ns3 that below two segments of code produce quite differnt patterns
for(int a=0; a<20; a++){
UniformVariable x(0, 14 );
val=x.GetInteger();
}
//vs
UniformVariable x(0, 14 );
for(int a=0; a<20; a++){
val=x.GetInteger(); }
Any Comments on this. For my network simulation both of these produced quite different results. Can any one tell whats the correct way to deal with random numbers?
Thanks