Write a program that produces ten random permutations of the numbers 1 to 10. To generate a

Question:

Write a program that produces ten random permutations of the numbers 1 to 10. To generate a random permutation, you need to fill an array with the numbers 1 to 10 so that no two entries of the array have the same contents. You could do it by brute force, by generating random values until you have a value that is not yet in the array. But that is inefficient. Instead, follow this algorithm. Make a second array and fill it with the numbers 1 to 10. Repeat 10 times Pick a random position in the second array. Remove the element at the position from the second array. Append the removed element to the permutation array.

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: