generating random numbers from a range

3 ビュー (過去 30 日間)
Meh
Meh 2012 年 6 月 13 日
Hello, I want to generate random numbers from a range. Example I want 1000 random numbers in the range from 1000 to 3000. How can I do this in matlab, because what I could get using the rand command is only in the range [0,1]. Thanks!
Edit Nr. 1 I think the rand command gives UNIFORMLY distributed random numbers. Is there a way to generate samples from NORMALLY distributed functions ( randn command), but instead of mean and std, I want to enter initial value and ranges. I want this for a stochastic modelling (sensitivity analysis) purpose.

回答 (2 件)

Andrei Bobrov
Andrei Bobrov 2012 年 6 月 13 日
please read about function rand
out = 1000 + 2000*rand(1000,1);
OR
use function unifrnd from Statistics Toolbox
out = unifrnd(1000,3000,1000,1);
  2 件のコメント
Meh
Meh 2012 年 6 月 13 日
Thanks andrei that was the answer for my previous question. Now I want to ask one more question. I think the rand command gives UNIFORMLY distributed random numbers. Is there a way to generate samples from NORMALLY distributed functions (randn command), but instead of mean and std, I want to enter initial value and ranges. I want this for a stochastic modelling (sensitivity analysis) purpose.
Andrei Bobrov
Andrei Bobrov 2012 年 6 月 13 日
k = randn(1000,1);
km = min(k);
out = (k-km)/(max(k)-km)*2000+1000;
hist(kn,1000:100:3000)
But this is distribution - not normal distribution

サインインしてコメントする。


Walter Roberson
Walter Roberson 2012 年 6 月 13 日
Normal distribution is, by definition, infinite tail on both sides. If you want your generated values to be confined to a finite range, you do not have a normal distribution.
Perhaps you want a beta distribution.

カテゴリ

Help Center および File ExchangeRandom Number Generation についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by