Problem 641. Make a random, non-repeating vector.
Solution Stats
Problem Comments
解决方案的评论s
-
1 Comment
Josh Klueberon 2 Nov 2021
nice!
-
2 Comments
john perkinson 4 May 2021
good problem
Isabella Stellitanoon 3 Nov 2021
good problem
-
1 Comment
TIMOTHY PIERGIOVANNIon 21 Apr 2021
randperm(n);
-
1 Comment
Muhammad Akmal Afibuddin Putraon 14 Oct 2020
thanks for the clue at description
-
1 Comment
Piero Cimuleon 20 Jun 2020
vec = randperm(n);
-
1 Comment
Timothy Chavezon 31 Aug 2019
This solution seems to run correctly in MATLAB (desktop)... can anyone tell me why it is coming back with an "Assertion Failed"?
function vec = makeRandomOrdering(n)
vec = zeros(1, numel(n));
flags = zeros(1, numel(n));
index = 1;
while (sum(flags) ~= numel(n))
pos = randi(numel(n));
if (flags(pos) ~= 1)
vec(index) = n(pos);
index = index + 1;
flags(pos) = 1;
end
end
end
Problem Recent Solvers5406
Suggested Problems
How to find the position of an element in a vector without using the find function
2563 Solvers
2571 Solvers
541 Solvers
Is this triangle right-angled?
4162 Solvers
696 Solvers
More from this Author51
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!