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

2 ビュー (過去 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