Create a number between specific values
조회 수: 1 (최근 30일)
이전 댓글 표시
I want to create a random or not value between specific values:
I have three double a,b,c a>b>c
and i want d number to be (a+c)/2<d<a
댓글 수: 0
채택된 답변
Jan
2018년 3월 9일
편집: Jan
2018년 3월 9일
A random value between the two limits:
lim1 = (a + c) / 2;
lim2 = a;
d = lim1 + rand * (lim2 - lim1)
댓글 수: 3
Walter Roberson
2018년 3월 9일
Yes. rand() can never be exactly 0 or exactly 1, so d can never be exactly lim1 or exactly lim2.
추가 답변 (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!