How do I create a random integer number binomial distributed between two values?

Hi All, as from subject I would like to know how to generate a random integer number binomial distributed between two values. Is there any built-in function ? Thanks

 採用された回答

the cyclist
the cyclist 2018 年 3 月 21 日

0 投票

If you have the Statistics and Machine Learning Toolbox, you can use binornd. (You might need to add or multiply the result, depending exactly which integers you want.)
If you do not have this toolbox, there are other tricks you can do using core MATLAB.

4 件のコメント

amatlabr
amatlabr 2018 年 3 月 21 日
編集済み: amatlabr 2018 年 3 月 21 日
Yes, I just saw that function and it needs two parameters (the number of trials, N, and probability of success for each trial, P). If I correctly understand this “binornd(n,p) function” will give a random number by ranging of 0 to n?
Another question : Let's say I both have the parameters, but I would like to get a random integer number between [start,end] according a binomial distribution. Then,Do I need to do :[end-start]*binornd(N,p)+ start ?
No.
start + binornd(end-start,p)
and presumably
N = end - start
so you can make that substitution if you want, to get
start + binornd(N,p)
(Note that you will not be able to use end as a variable name, because it is a MATLAB keyword.)
amatlabr
amatlabr 2018 年 3 月 21 日
So if my range is between 0 and 1000 --> binornd(1000,p) Otherwise if my range is between 10 and 1000 --> 10+binornd(9990,p)
the cyclist
the cyclist 2018 年 3 月 21 日
Yes

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeRandom Number Generation についてさらに検索

質問済み:

2018 年 3 月 21 日

コメント済み:

2018 年 3 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by