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

조회 수: 1 (최근 30일)
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)

채택된 답변

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by