simple bernoulli sampler function

I am trying to find replacement of binornd function by standard MATLAB code. Is the following command
r = binornd(1,p,sz)
exactly equivalent to the:
function r = randb(p,sz)
% simple bernoulli sampler
r = double(rand(sz) < p);
end
If not, what is the correct equivalent?

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日

0 投票

Yes, this code is correct for the case n=1.

1 件のコメント

Michal
Michal 2020 年 10 月 15 日
Well OK ... thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeDescriptive Statistics and Visualization についてさらに検索

タグ

質問済み:

2020 年 10 月 14 日

コメント済み:

2020 年 10 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by