Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Write your own code to generate random variates from the following distributions:
- a. Exponential distribution (mean inter-arrival time of 0.25)
- b. Bernoulli distribution ( p = 0.25)
- c. Binomial distribution (n = 20, p = 0.5)
- d. Poisson distribution (arrival rate = 4.0)
- Draw histograms for sequences of N random numbers for 1000, 10000 and 100000.
- Poisson distribution
- Here's how Wikipedia says Knuth says to do it:
- init:
- Let L ← e^(−λ), k ← 0 and p ← 1.
- do:
- k ← k + 1.
- Generate uniform random number u in [0,1] and let p ← p × u.
- while p > L.
- return k − 1.
- In Java, that would be:
- public static int getPoisson(double lambda) {
- double L = Math.exp(-lambda);
- double p = 1.0;
- int k = 0;
- do {
- k++;
- p *= Math.random();
- } while (p > L);
- return k - 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement