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

5 visualizaciones (últimos 30 días)
P Rakesh Kumar Dora
P Rakesh Kumar Dora el 1 de Abr. de 2021
Comentada: P Rakesh Kumar Dora el 1 de Abr. de 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]?

Respuestas (1)

Walter Roberson
Walter Roberson el 1 de Abr. de 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 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 1 de Abr. de 2021
Thanks sir +1
P Rakesh Kumar Dora
P Rakesh Kumar Dora el 1 de Abr. de 2021
Thanks for the reference

Iniciar sesión para comentar.

Categorías

Más información sobre Random Number Generation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by