MATLAB Answers

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

10 views (last 30 days)
Vikas Rahar
Vikas Rahar on 26 Nov 2019
Commented: Star Strider on 26 Nov 2019
Does anybody know how to generate a series of 100 non-repeating random floating numbers between 1 and 10?


Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 26 Nov 2019
One option:
v = rand(1, 100)*9+1;
[L, H] = bounds(v) % Check
producing (in this run):
L =
H =


Show 3 older comments
Star Strider
Star Strider on 26 Nov 2019
With a pseudo-random random number generator, I’m certain that’s possible. With a vector of only 100 numbers, several trials (in a loop) have always found equality between the element numbers of the vector and its unique elements, although with enough trials, there are bound to occasionally be repeats. Noting that is a probability of , so it is not likely to be a significant issue with a vector of 100 elements.
Walter Roberson
Walter Roberson on 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 on 26 Nov 2019
I’d not thought to test this with the ‘Birthday Party’ problem.

Sign in to comment.

More Answers (1)

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


Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by