Filter löschen
Filter löschen

How to generate a random number?

1 Ansicht (letzte 30 Tage)
Enfa White
Enfa White am 25 Sep. 2012
How to generate a random number in 5 decimal points in the range between 0 and 10 with 0.1 intervals? Sample random numbers are like 5.4321, 3.5678, 7.7891 etc.
  2 Kommentare
Matt Fig
Matt Fig am 25 Sep. 2012
Bearbeitet: Matt Fig am 25 Sep. 2012
How are those example numbers on .1 intervals? On a .1 interval I am thinking you want numbers like:
.6, 2.4, 9.1, 5.3
Your two criteria seem to conflict with each other.
Azzi Abdelmalek
Azzi Abdelmalek am 25 Sep. 2012
what do you mean by 0.1 interval?

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andrei Bobrov
Andrei Bobrov am 25 Sep. 2012
round(10^6*rand)*10^-5

Weitere Antworten (1)

Daniel Shub
Daniel Shub am 25 Sep. 2012
You cannot do what you want. Your example random number of 5.4321 cannot be represented exactly as a float.
sprintf('%20.18f\n', 5.4321)
You would be better off generating random integers between 0 and 10^5. I also have no idea what an interval of 0.1 means nor have you said what distribution you want.

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by