[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [ns] Problem with the generation of random numbers




Hi Karim,

when you use only one random number generator (RNG), your problem can be
explained as follows:

The RNG generates a stream of uniformly distributed random
numbers. Everytime, the code asks for a random number (from this RNG) it
gets the next number in the sequence. It does not matter wether this
number is a uniformly or exponentially distributed random
number. Exponentially distributed random numbers are computed from
uniformly distributed random numbers :-)

So, when you have the following pieces of code

(1)
N=100;
for (i+0: i<N; i++)
  Ru[i]=Random::uniform();
Re=Random::exponential();

(2)
N=50;
for (i+0: i<N; i++)
  Ru[i]=Random::uniform();
Re=Random::exponential();

(3)
Re=Random::exponential();
N=100;
for (i+0: i<N; i++)
  Ru[i]=Random::uniform();

You will get for the variables Ru[] and Re (The numbers in the table
correspond to the position in the sequence of random numbers, and
therefore, the same position can be considered the same random number.)

             (1)      (2)               (3)
Ru[0..99]  1..100   1..50, not used   2..101
Re         101      51                1

So, when you want to change the N in your program without getting a
different value for the exponentially distributed random number, you could
use TWO different RNGs. One for all your uniform, the other for
exponential.

Hope this helps
Michael



On Thu, 24 Aug 2000, Karim El-Khazen (ERA) wrote:

> 
> Thanks for helping me.
> 
> I modified in fact expoo.cc adding some functionalities. I added a function CalcDTX(A,P). 
> 
> This is my function next_interval() after modification :
> 
> double EXPOO_Traffic::next_interval(int& size)
> {
> 	double t = interval_;
> 	if (rem_ == 0) {
> 		rem_ = int(burstlen_.value() + .5);    <-- (1)
> 		CalcDTX(A,P);            		  <-- (2)
> 		/* compute number of packets in next burst */
> 		/* make sure we got at least 1 */
> 		if (rem_ == 0)
> 			rem_ = 1;
> 		/* start of an idle period, compute idle time */
> 		t += Offtime_.value();
> 	}	
> 	rem_--;
> 	size = size_;
> 	return(t);
> }
> 
> This is CalcDTX() : 
> 
> void EXPOO_Traffic::CalcDTX(int AA[sizeAP], int PP[sizeAP])
> {
> 	double pa[5] = {0.271, 0.131, 0.000225, 0.00203, 0.00270};
> 	double pp[5] = {0.164, 0.106, 0.0881, 0.0624, 0.0563};
> 	double pia[3] = {0.426, 0.481, 0.0936};
> 	double pip[3] = {0.676, 0.323, 0.00148};
> 	double lamdaa[3] = {0.0802, 0.00976, 0.00324};
> 	double lamdap[3] = {0.121, 0.0275, 0.00126};
> 	double Qa[8], Qp[8];
> 	int Tstate;
> 	int i;
> 	double rand_val;
>         	cumsum(Qa, pa, pia);
> 	cumsum(Qp, pp, pip);
> 	
> 	for (i=0; i<sizeAP; i++)
> 	{
> 		rand_val = Random::uniform();
> 		Tstate = NumberLessThen(Qa, rand_val) + 1;
> 		if (Tstate <= 5)
> 		{
> 			AA[i] = Tstate;
> 		}
> 		else
> 		{			
>                         	rand_val = Random::uniform();
> 			AA[i] = 6 + (int)(-log(rand_val) / lamdaa[Tstate-5]);
> 		}
> 		rand_val = Random::uniform();
> 		Tstate = NumberLessThen(Qp, rand_val) + 1;
> 		if (Tstate <= 5)
> 		{
> 			PP[i] = Tstate;
> 		}
> 		else
> 		{
> 			rand_val = Random::uniform();
> 			PP[i] = 6 + (int)(-log(rand_val) / lamdap[Tstate-5]);
> 		}
> 	}
> }
> 
> It's calling other functions...
> 
> (1) must give me a exponential value
> 
> and (2) give me a 2 vectors of size AP, with random values, with some formulas.
> 
> The main problem is by changing the order of (1) and (2), 
> 
> (2) : CalcDTX(A,P);            			
> (1) : rem_ = int(burstlen_.value() + .5);    
> 
> The exponential value depend on the numbers of random values generated
> before.
> 
> Is it normal ? I was not expecting a correlation between this 2 operations.
> 
> Thanks in advance, 
> 
> Karim.
> 
> NB: The Floating Point Exception was not correlated to this probelm, I solved it.
> 
> Karim El-Khazen
> Email : [email protected] 
> Website : http://www.directmoving.com 
> �
> -----------------------------------------------------------------
> Karim C. El-Khazen� [email protected] http://www.elkhazen.com
> MS in Electrical & Computer Engineering, Georgia Tech, Atlanta, USA 
> Ericsson Radio Systems AB, S-164 80 Stockholm SWEDEN
> -----------------------------------------------------------------
> 
> 
> -----Original Message-----
> From: Haobo Yu [mailto:[email protected]]
> Sent: Thursday, August 24, 2000 4:06 AM
> To: Karim El-Khazen (ERA)
> Cc: [email protected]
> Subject: Re: [ns] Problem with the generation of random numbers
> 
> 
> It'll greatly help if you can provide some example scripts. I calculated
> 100 exponential values then 200 exponential ones, and the first 100 of the
> second run are identical to those in the first run.
> 
> On Tue, 15 Aug 2000, Karim El-Khazen (ERA) wrote:
> 
> > Hi everybody,
> >  
> > I'm having a problem with the generation of random numbers. 
> >  
> > 1 ) I'm computing N random variables with " Random::uniform() " THEN an exponential random variable using " ExponentialRandomVariable ". I get coherent results which seem correct. If I run this simulation plenty of time, I always get the same values, since I'm not changing any initial values.
> > I tried after to change the number N of random uniform variables, the exponential value changed. It shouldn't, no ?
> > These parameters are not correlated at all (except in the random generator?!).
> >  
> > 2) Then I tried to reverse the order of these generations. For N=100, it gives me a result. For N=50, I get a "Floating Point Exception (core dumped)" !!!
> >  
> > Is there anybody who can help me solve this problem ?
> >  
> > Thanks in advance, Karim.
> > 
> > 
> >  
> > Karim El-Khazen
> > Email : [email protected] 
> > Website : http://www.directmoving.com 
> > 
> > -----------------------------------------------------------------
> > Karim C. El-Khazen  [email protected] http://www.elkhazen.com 
> > MS in Electrical & Computer Engineering, Georgia Tech, Atlanta, USA
> > Ericsson Radio Systems AB, S-164 80 Stockholm SWEDEN
> > -----------------------------------------------------------------
> > 
>