필터 지우기
필터 지우기

How to generate a random number?

조회 수: 1 (최근 30일)
Enfa White
Enfa White 2012년 9월 25일
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
Matt Fig
Matt Fig 2012년 9월 25일
편집: Matt Fig 2012년 9월 25일
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 2012년 9월 25일
what do you mean by 0.1 interval?

댓글을 달려면 로그인하십시오.

채택된 답변

Andrei Bobrov
Andrei Bobrov 2012년 9월 25일
round(10^6*rand)*10^-5

추가 답변 (1개)

Daniel Shub
Daniel Shub 2012년 9월 25일
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.

카테고리

Help CenterFile Exchange에서 Random Number Generation에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by