How can I generate integer random variables by using exponentially distributed with a mean of 20 seconds?

2 Ansichten (letzte 30 Tage)
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)

Akzeptierte Antwort

Jeff Miller
Jeff Miller am 19 Apr. 2020
If you just want integers, then use the geometric distribution instead of the exponential:
r2 = geornd(1/mu2,sz1,sz2);
  3 Kommentare
Jeff Miller
Jeff Miller am 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).

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by