How to generate random number in [0, 1] range
6 ビュー (過去 30 日間)
古いコメントを表示
I am using rand(1) function which gives random number in between 0 and 1. But is there any function which will give random number between 0 and 1 & includes 0 and 1 as well, i.e in the interval [0,1]?
0 件のコメント
回答 (1 件)
Walter Roberson
2021 年 4 月 1 日
Not any of the Mathworks supplied ones.
Not unless philox4x32_10 or threefry4x64_20 can do it (not explicitly documented).
However, you could potentially use
randi([0 2^52]) / 2^52
which would differ from rand() in that rand() is 53 bits and this would be 52 bits.
I have not seen any information as to how randi() ensures fairness.
Note: randi([0 2^n]) is a range of ((2^n)+1) values, not a range of 2^n values.
2 件のコメント
参考
カテゴリ
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!