How to generate random numbers 0 and 1
55 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
shruthi m
il 30 Gen 2015
Commentato: Kamal yahya
il 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 Commenti
Risposta accettata
Image Analyst
il 30 Gen 2015
Modificato: Image Analyst
il 30 Gen 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.
Più risposte (2)
Vedere anche
Categorie
Scopri di più su Random Number Generation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!