How can I generate integer random variables by using exponentially distributed with a mean of 20 seconds?
2 views (last 30 days)
Show older comments
Burhan Elaldi
on 19 Apr 2020
Commented: Burhan Elaldi
on 19 Apr 2020
I used this code that you see in below but this all values, I generate, not integer:
mu2 = 20;
sz1 = 50;
sz2 = 1;
r2 = exprnd(mu2,sz1,sz2)
0 Comments
Accepted Answer
Jeff Miller
on 19 Apr 2020
If you just want integers, then use the geometric distribution instead of the exponential:
r2 = geornd(1/mu2,sz1,sz2);
3 Comments
Jeff Miller
on 19 Apr 2020
The geometric is the integer-only analog of the exponential, so it gives you exactly what you would get by truncating the exponential to an integer. Compare these two nearly identical figures:
mu2 = 20;
n=100000;
er = exprnd(mu2,n,1);
ier = floor(er);
gr = geornd(1/mu2,n,1);
edges = 0:140;
figure;
histogram(ier,edges);
figure;
histogram(gr,edges);
It really makes no sense to say that the values must be integers and must come from an exponential distribution, because the exponential distribution does not give integer values (i.e., there is zero probability that a random number from an exponential distribution is an integer).
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!