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

7 Ansichten (letzte 30 Tage)
P Rakesh Kumar Dora
P Rakesh Kumar Dora am 1 Apr. 2021
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]?

Antworten (1)

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

Kategorien

Mehr zu Random Number Generation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by