How To Generate Non Repeating floating Random Numbers from 1 to 10

2 vues (au cours des 30 derniers jours)
Vikas Rahar
Vikas Rahar le 26 Nov 2019
Commenté : Star Strider le 26 Nov 2019
Hi,
Does anybody know how to generate a series of 100 non-repeating random floating numbers between 1 and 10?
Thanks

Réponse acceptée

Star Strider
Star Strider le 26 Nov 2019
One option:
v = rand(1, 100)*9+1;
[L, H] = bounds(v) % Check
producing (in this run):
L =
1.0846
H =
9.9740
  6 commentaires
Walter Roberson
Walter Roberson le 26 Nov 2019
With 2^53 possible rand() outputs, an estimation using The Birthday Paradox logic suggests that the probability of a duplicate rises to 1/2 at about 10^8
Star Strider
Star Strider le 26 Nov 2019
Noted.
I’d not thought to test this with the ‘Birthday Party’ problem.

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 26 Nov 2019
z = cumsum(rand(100,1));
mn = min(z);
Z = 9/(max(z) - mn)*(z - mn) + 1;
out = Z(randperm(100));

Catégories

En savoir plus sur Birthdays dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by