필터 지우기
필터 지우기

How I generate a random number between 300 and 450?

조회 수: 1 (최근 30일)
zeezo
zeezo 2017년 10월 19일
댓글: Star Strider 2017년 11월 12일
Hi
I would like to generate a number between 300 and 450.
I also would like which is the possible ways to generate numbers on Matlab? Is there a Poisson generator for random numbers?
And what does the initial seed mean?
Thank you for your help.
  댓글 수: 1
Jan
Jan 2017년 10월 19일
Do you mean integer or floating point numbers?

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

채택된 답변

Bora Eryilmaz
Bora Eryilmaz 2017년 11월 12일
You can create a "truncated" Poisson distribution that is based on the regular Poisson distribution, but with its range truncated to a given interval and its probability density function (PDF) adjusted so that the distribution remains a proper one (i.e., its integral over the truncation range equals 1).
For example, to generate numbers in the range [300, 450] from a truncated Poisson distribution, you could use
% Regular Poisson distribution
lambda = (300+450)/2; % To put the mean in the middle of the range
d = makedist('poisson', 'lambda', lambda)
% Truncated Poisson distribution
td = d.truncate(300, 450)
td.random(10,1) % Generate 10 random numbers in the range [300 450]
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 11월 12일
Object methods can (usually) be coded as either
MethodName(Object, parameter, parameter2, ...)
or as
Object.MethodName(parameter, parameter2, ...)
Star Strider
Star Strider 2017년 11월 12일
Thanks, Bora and Walter.
I had no idea it was possible to truncate a distribution and still have it maintain the properties of a distribution.
I also thought I knew my way around the documentation and the essentials of the Toolboxes!

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

추가 답변 (2개)

KL
KL 2017년 10월 19일
편집: KL 2017년 10월 19일
randi([300 450])
  댓글 수: 5
Jan
Jan 2017년 10월 19일
@Guillaume: I appreciate the "your favorite search engine". You take care for not advertising a commercial service, which we do not pay by money, but by our personal data. Thanks!
@zeezo: All details are explained exhaustively in the documentation. To use Matlab reliably, you have to read there at first.
zeezo
zeezo 2017년 10월 19일
@jan I did read the documentation before I post my question, but because I do not understand the details I asked here. If you see that my question is easy, that because I am a beginner on Matlab. :(
Thank you very much

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


Guillaume
Guillaume 2017년 10월 19일
편집: Guillaume 2017년 10월 19일
I would like to generate a number between 300 and 450
I tried to use poissrnd but I couldn't generate a number between the two values.
A poisson distribution is defined over the range [0, Inf] and has only one parameter lambda (mean and variance). You cannot have a set of numbers that follow a poisson distribution and at the same time is restricted to a smaller range than [0 Inf].
You could generate random numbers that follow a poisson distribution with mean (300+450)/2, but you are guaranteed that with enough samples some of these will be out of the interval. Otherwise it is not a poisson distribution anymore.
  댓글 수: 1
Image Analyst
Image Analyst 2017년 10월 19일
Exactly correct. But if you, say, generated a million Poisson numbers between 0 and (say) 5000, and then threw them all away except those that landed between 300 and 450, it's not really Poisson anymore, is it? Indeed, it might even look rather uniform.

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

Community Treasure Hunt

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

Start Hunting!

Translated by