MATLAB: Simple bernoulli sampler function

binorndMATLABStatistics and Machine Learning Toolbox

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?

Best Answer

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