Generating random integers in MATLab

7 vues (au cours des 30 derniers jours)
Ajay Kumar
Ajay Kumar le 25 Déc 2018
Commenté : madhan ravi le 25 Déc 2018
Can anyone please tell me on how to generate random inters every time my program passes through the loop.
I need 20 nodes between the coordinates of 0-100
during each iterations 20 nodes have to be created at random coordinates.

Réponse acceptée

madhan ravi
madhan ravi le 25 Déc 2018
randi([0 100],1,20)
  2 commentaires
John D'Errico
John D'Errico le 25 Déc 2018
+1, but remember that this generates integers with replacement. So if you cannot tolerate replicates, then you need to use other tools. Randperm can do it without replacement, so if you want them including 0 up to 100, do this:
randperm(101,20) - 1
madhan ravi
madhan ravi le 25 Déc 2018
Thank you @John D'Errico completely agree..

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by