How to generate random numbers 0 and 1
53 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
shruthi m
am 30 Jan. 2015
Kommentiert: Kamal yahya
am 27 Feb. 2020
I need to generate random numbers 0 and 1,if i use randi(1) it will be in fraction. exactly i need to generate 0 and 1 randomly???pls help
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 30 Jan. 2015
Bearbeitet: Image Analyst
am 30 Jan. 2015
Try
n = 10; % However many numbers you want.
randomNumbers = randi([0, 1], [1, n])
This will give a double. If you want integers, then cast to int32.
randomNumbers = int32(randi([0, 1], [1, n]));
or use logical() if you want booleans.
Weitere Antworten (2)
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!