フィルターのクリア

random vector (1,10)

3 ビュー (過去 30 日間)
Ariela Glikman
Ariela Glikman 2018 年 12 月 9 日
コメント済み: Walter Roberson 2018 年 12 月 10 日
hi,
im tring to make a vector size (1,10) who has random integers between 1 to a,
( but only round numbers )
v= a-1 .* round(rand (1,10) +1;
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 9 日
ceil(something * rand(size stuff)) + somevalue

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

回答 (2 件)

Stephen23
Stephen23 2018 年 12 月 9 日
編集済み: Stephen23 2018 年 12 月 9 日
ceil(a*rand(1,10))
Often beginners think of using round for something like this, but the usual algorithm they use has nasty end-effects, where the first and last values have half the probability of any other number.
ceil avoids this.
  1 件のコメント
Walter Roberson
Walter Roberson 2018 年 12 月 10 日
What Stephen mentions is important for fair weighting. It is common to use round() in such cases, even amonst people who have programmed for decades but do not have particular background in probability necessary to be know to always be really thorough about cross-checking that the code really does match the probability distribution required.
See for example https://www.mathworks.com/matlabcentral/answers/246999-probability-1-2-with-matlab-random-number-generators in which I explore how difficult it is to really get 50% probability in MATLAB.

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


Steven Lord
Steven Lord 2018 年 12 月 9 日
Use the randi function.

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by