Can the random function accommodate the randi function?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (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.
1 Kommentar
Snoopy
am 22 Nov. 2024
Kategorien
Mehr zu Signal Generation, Analysis, and Preprocessing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


