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:
- calculate $p$ as the probability of a car entering the road in the next time slot(i.e. $t=1$)
- 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()?