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

1 Expert Approved Answer
Step: 1 Unlock

Here is an example of how you could write a program to produce ten random permutations of the num... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Java Concepts Late Objects Questions!