How to generate random number in [0, 1] range

6 visualizzazioni (ultimi 30 giorni)
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]?

Risposte (1)

Walter Roberson
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.

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!

Translated by