How to generate random number from Bernoulli distribution?

54 vues (au cours des 30 derniers jours)
PARVATHY NAIR
PARVATHY NAIR le 19 Jan 2023
just like the below command
a=randn(1,1000)
how can we generate random number from bernoulli distribution

Réponse acceptée

Bruno Luong
Bruno Luong le 19 Jan 2023
p = 0.25
p = 0.2500
X = double(rand(1,1000) < p)
X = 1×1000
0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1 0 0 0
histogram(X,'Normalization','pdf')

Plus de réponses (0)

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by