simple bernoulli sampler function

2 views (last 30 days)
Michal on 14 Oct 2020
Commented: Michal on 15 Oct 2020
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);
If not, what is the correct equivalent?

Accepted Answer

Ameer Hamza
Ameer Hamza on 14 Oct 2020
Yes, this code is correct for the case n=1.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!