Effacer les filtres
Effacer les filtres

I need to generate a number randomly which is either -1 or 1

9 vues (au cours des 30 derniers jours)
MK96
MK96 le 22 Oct 2016
Commenté : MK96 le 22 Oct 2016
Trying to generate either -1 or 1 randomly.
I have looked at;
R = unifrnd(-1,1)
however this generates a random number in the interval (-1,1) whereas I am trying to generate a random number which is either -1 or 1

Réponse acceptée

Image Analyst
Image Analyst le 22 Oct 2016
Try this:
r = 2 * randi(2) - 3

Plus de réponses (0)

Catégories

En savoir plus sur Random Number 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!

Translated by