Matlab equivalent of rand() in C++
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Rishi Balasubramanian
le 17 Avr 2021
Commenté : Rishi Balasubramanian
le 17 Avr 2021
Hello,
I am trying to adapt a C++ code to my Matlab project.
In C++ there is this line
random4 = rand() % item // Here the % is modulo in C++
So random is the range of values 'rand' modulo by variable 'item'.
How do I implement this in Matlab. Since I am looking for targeted platform and efficiency, I cannot call the Cpp file in matlab. I am looking for a matlab adaptation.
Any help or suggestions offered are much appreciated. Thank you in advance...
3 commentaires
Walter Roberson
le 17 Avr 2021
no. randi(6) would be 1 to 6, but random integer mod 6 would be 0 to 5. You can randi([0 5])
Réponse acceptée
Bruno Luong
le 17 Avr 2021
Modifié(e) : Bruno Luong
le 17 Avr 2021
random4 = randi(item)-1
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical 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!