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
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.
Step by Step Solution
3.46 Rating (162 Votes )
There are 3 Steps involved in it
Here is an example of how you could write a program to produce ten random permutations of the num... View full answer
Get step-by-step solutions from verified subject matter experts
