generate random numbers in range from (0.8 to 4)
조회 수: 398 (최근 30일)
이전 댓글 표시
Hi How to generate 20 random numbers in range from (0.8 to 4) Thanks
댓글 수: 1
채택된 답변
Azzi Abdelmalek
2013년 3월 11일
편집: Azzi Abdelmalek
2013년 3월 11일
xmin=0.8
xmax=4
n=20
x=xmin+rand(1,n)*(xmax-xmin)
댓글 수: 3
Steven Lord
2021년 1월 19일
xmin=0.8;
xmax=4;
n = 1e6; % Generating a few more numbers than the original n=20;
x=xmin+rand(1,n)*(xmax-xmin);
histogram(x, 0.8:0.1:4.1)
Looks reasonably uniform to me.
Image Analyst
2021년 1월 20일
If you want it EXACTLY perfectly uniform (which is doubtful), then you should use linspace() instead of rand().
추가 답변 (3개)
Image Analyst
2013년 3월 11일
Did you look in the help? You will see the first example does what you want:
Example 1
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
댓글 수: 1
Ka Mirul
2017년 10월 17일
Hallo, I have seen a tutorial about "Generating Random Number in Specific Range" at https://www.youtube.com/watch?v=MyH3-ONYL_k and it works. Hope it will help you.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!