How to understand/use exponentially distributed random numbers

206 Views Asked by At

I want to emulate a road traffic situation, which should obey the "poisson distribution", and the probability of vehicles entering the road in the "next" time slot being exponentially distributed. My method is to use the following formula:

$$ P(X \le t) = 1 - e^{-\lambda t} $$

The program logic is:

  1. calculate $p$ as the probability of a car entering the road in the next time slot(i.e. $t=1$)
  2. generate a random number $R$ between $[0, 1)$,if $R \le p$, add a car to the road, otherwise, skip until next iteration.

I wonder if this approach is correct or not?

=== EDIT ===

The following part of my question is answered by Kurt G, but he didn't answer whether my simulation procedure is correct or not.


Also, There is a function in golang (which I use):

// ExpFloat64 returns an exponentially distributed float64 in the range
// (0, +math.MaxFloat64] with an exponential distribution whose rate parameter
// (lambda) is 1 and whose mean is 1/lambda (1) from the default Source.
// To produce a distribution with a different rate parameter,
// callers can adjust the output using:
//
//  sample = ExpFloat64() / desiredRateParameter
//
func ExpFloat64() float64 { return globalRand.ExpFloat64() }

My quesion is, can I use ExpFloat64() to implement my simulation, and how do I understand the value generated by ExpFloat64()?

1

There are 1 best solutions below

2
On

To simulate an exponentially distributed RV $R$ you can do it in two ways:

  1. Call that ExpFloat64() function (its description sounds OK).

OR ( that's an XOR ! )

  1. Simulate a uniform random variable $U\in[0,1]$ and plug it into the inverse of the exponential CDF:

$$ R=-\log (1-U)/\lambda $$ This works because any RV that is plugged into its own CDF will create a uniform RV.

You can try both approaches and compare.