Can the random function accommodate the randi function?
显示 更早的评论
I am using
randi([0,1],[N,1]);
to randomly generate 0s and 1s. If I am not mistaken, the
random
function is replacing the older, distribution specific, functions such as the
normrnd
function. I welcome this consolidation of random number generators under the
random
function. My question is whether I can use the
random
function in some way to replace the
randi
function that I state at the top of this message.
采纳的回答
更多回答(1 个)
random('unid',2,[1,10])-1
nnz(ans)
which -all random
which -all rand
which -all randi
The deal is that random is only available if one has the Statistics TB; and the "Alternative Functionality" section of the doc states that "random is a generic function that accepts either a distribution by its name name or a probability distribution object pd. It is faster to use a distribution-specific function, ...". So, while it is possible to use the one generic name, unless you're writing code that dynamically changes a distribution family, it would seem better to forego its use for the specific distribution desired.
类别
在 帮助中心 和 File Exchange 中查找有关 Signal Generation, Analysis, and Preprocessing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


