필터 지우기
필터 지우기

Generating one random number from a given range of numbers.

조회 수: 5 (최근 30일)
Rich Cavanaugh
Rich Cavanaugh 2018년 4월 5일
댓글: Rich Cavanaugh 2018년 4월 5일
This may be a poor question but I can't seem to find a usable answer. I need to generate one random number from a range 2/3 X to X
So if I were to set X to 30 I would want one random value from 20 to 30 likewise if I set X to 300 I would want a value from 200 to 300...
Does anyone have any suggestions for how to go about this? Thanks in advance.

답변 (2개)

Fangjun Jiang
Fangjun Jiang 2018년 4월 5일
R = randi([IMIN,IMAX],...) returns an array containing integer values drawn from the discrete uniform distribution on IMIN:IMAX

Bosong Lin
Bosong Lin 2018년 4월 5일
Hi Rich,
If I understood your question, I would do it this way: 1/3*X*rand()+2/3*X; rand() returns a single uniformly distributed random number in the interval (0,1).
Bosong
  댓글 수: 1
Rich Cavanaugh
Rich Cavanaugh 2018년 4월 5일
I feel like this is close, but I need an integer return. I am using this piece of the program to randomly select an index in the last third of a matrix so i can change it's value.

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by