generate 0 and 1

21 次查看(过去 30 天)
Dawon Yoo
Dawon Yoo 2020-3-28
how do I generate a binary sequence with certain probabilities?
for instance, I want 0 to have 0.6 and 1 to have 0.4 probability
It would be very helpful if you give me the whole code to this

采纳的回答

John D'Errico
John D'Errico 2020-3-28
rand() < 0.6
If you want a random binary sequence of length n, then this is sufficient:
rand(1,n) < 0.6

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Random Number Generation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by