Random distribution with specific total amount

18 ビュー (過去 30 日間)
htet wai
htet wai 2018 年 5 月 14 日
コメント済み: Walter Roberson 2018 年 5 月 14 日
How can I generate the 10 random number with total summation value of 1. The random number should be anything between 0 and 1. Thanks.

採用された回答

Walter Roberson
Walter Roberson 2018 年 5 月 14 日
Look in the File Exchange for Roger's randfixedsum()
  2 件のコメント
htet wai
htet wai 2018 年 5 月 14 日
Thank you for your answer. I tried that function and that generate random number to too many decimal point. I would like to generate random number with only 2 decimal point such 0.28, 0.36 and so on. Thanks again for your support.
Walter Roberson
Walter Roberson 2018 年 5 月 14 日
The only 2 digit decimal numbers that are exactly representable in binary floating point are 0.25, 0.50, and 0.75 . The smallest of these is 0.25, and if you add 10 of those then you would get 2.5, which would exceed your required total of 1.0 . Your task is not possible.
The closest that IEEE 754 double representation gets to 0.28 is 0.2800000000000000266453525910037569701671600341796875
1/100 is not exactly representable in finite binary, exactly the same way that 1/7 is not exactly representable in finite decimal.
You will not be able to do what you want.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by