How to generate random number in [0, 1] range
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Walter Roberson
il 1 Apr 2021
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 Commenti
Vedere anche
Categorie
Scopri di più su Random Number Generation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!