Problem 641. Make a random, non-repeating vector.
Solution Stats
Problem Comments
Solution Comments
-
1 Comment
nice!
-
2 Comments
good problem
good problem
-
1 Comment
randperm(n);
-
1 Comment
thanks for the clue at description
-
1 Comment
vec = randperm(n);
-
1 Comment
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 Solvers6461
Suggested Problems
-
Maximum running product for a string of numbers
1713 Solvers
-
Given an unsigned integer x, find the largest y by rearranging the bits in x
1342 Solvers
-
We love vectorized solutions. Problem 1 : remove the row average.
751 Solvers
-
Find the next Fibonacci number
399 Solvers
-
calculate the length of matrix
842 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!