How to generate random numbers 0 and 1
195 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
shruthi m
le 30 Jan 2015
Commenté : Kamal yahya
le 27 Fév 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 commentaires
Réponse acceptée
Image Analyst
le 30 Jan 2015
Modifié(e) : Image Analyst
le 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.
Plus de réponses (2)
Voir également
Catégories
En savoir plus sur Waveform 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!