random no.
2 ビュー (過去 30 日間)
古いコメントを表示
hi, can i get random no. in specific range ?
between 19 , -19
thanks
回答 (4 件)
Image Analyst
2012 年 3 月 18 日
You didn't read the help on rand(), did you? If you had, you would have seen the answer to your question as the very first example:
Example 1
Generate values from the uniform distribution on the interval [a, b]:
r = a + (b-a).*rand(100,1);
Needless to say, a=-19 and b = 19 in your case, and 100 is the number of random numbers to be generated, or:
r = -19 + 38 .* rand(100, 1);
1 件のコメント
Jan
2012 年 3 月 18 日
While the solution in easy, not to say trivial, the suggestion to read the documentation is an will be valuable. +1
the cyclist
2012 年 3 月 18 日
Depending on whether you want to draw from a discrete or a continuous distribution, you will likely want to use either the randi() or unifrnd() function.
0 件のコメント
Sahyadri Vibhu
2012 年 3 月 20 日
As Sean Lawson said in the above comment, using -19+38*rand will generate a random real number in the range (-19 19)
to generate random integers use
randi ([lower_limit upper_limit],a,b,c...)
which generates an axbxcx..... random integer array in the range (lower_limit upper_limit)
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!