The way randperm
used to work was with sort
and rand
. We can do it the same way, but with multiple columns to get a population:
>> N = 8; % length of random string
>> P = 10; % population
>> [~,AA]=sort(rand(N,P))
AA =
5 6 7 6 1 4 7 8 3 2
8 7 6 5 4 2 4 3 2 3
6 3 1 8 8 5 8 1 5 8
3 4 8 1 7 6 2 7 4 7
4 2 5 4 6 1 1 4 1 4
2 5 2 3 3 8 3 6 6 6
1 1 3 2 2 3 6 5 8 1
7 8 4 7 5 7 5 2 7 5