Info

This question is closed. Reopen it to edit or answer.

unrepeated integers from randi function

1 view (last 30 days)
Bruno
Bruno on 9 May 2011
Closed: MATLAB Answer Bot on 20 Aug 2021
for the randi function for example
randi([2,6],1,4)
this basically creates 4 random integers from 2 to 6
eg. 2, 5,4,2
how can i do the same but generating unrepeated integers?
in the example the integer 2 is repeated twice and i dont want that for a randi function of a large range

Answers (1)

Walter Roberson
Walter Roberson on 9 May 2011
S = 2:6;
U = randperm(length(S));
S(U(1:4))

Tags

Community Treasure Hunt

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

Start Hunting!