I'm having trouble figuring out what to do and how to do.. could someone explain to me what I need to do in order to work?
THIS IS WHAT I NEED TO DO:
Professor Snoop wants a program that will randomly generate 10 unique random numbers. Your job is to write a program that produces random permutations of the numbers 1 to 10. “Permutation” is a mathematical name for an arrangement. For example, there are six permutations of the numbers 1,2,3: 123, 132, 231, 213, 312, and 321.
To generate a random permutation, you need to fill an ArrayList 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 calling Random.nextInt ( ) until it produces a value that is not yet in the array. Instead, you should implement a smart method.
Make a second ArrayList and fill it with the numbers 1 to 10.
Then pick one of those at random, remove it, and append it to the permutation ArrayList. Repeat ten times.
Implement a class PermutationGenerator with the following method:
ArrayList nextPermutation
The output will consist of 10 lists of random permutations of the numbers 1 through 10.
Example output is shown below:
Random Permutation List Generator
List 1: 4 6 8 1 9 7 10 5 3 2
List 2: 6 8 1 7 3 4 9 10 5 2
List 3: 2 4 9 6 8 1 10 5 7 3
List 4: 8 5 4 3 2 9 6 7 1 10
List 5: 10 3 2 6 8 9 5 7 4 1
List 6: 9 10 3 2 1 5 6 8 4 7
List 7: 3 8 5 9 4 2 10 1 6 7
List 8: 3 2 4 5 7 6 9 8 10 1
List 9: 4 1 5 10 8 3 6 2 7 9
List 10: 3 5 2 4 1 7 9 6 8 10
THIS IS WHAT I HAVE SO FAR:
Expand|Select|Wrap|Line Numbers
- /**
- * Write a description of class PermutationGenerator here.
- *
- * @author (your name)
- * @version (a version number or a date)
- */
- import java.util.Random;
- import java.util.ArrayList;
- public class PermutationGenerator
- {
- public static void main(String[]args)
- {
- for(int i = 1; i <= 10; i++)
- {
- System.out.print("List " + i + ":");
- }
- class PermutationGenerator
- {
- //create an array of #s from 1-10 without 2 entries
- // having the same content.
- private ArrayList<Integer>nums = new ArrayList<Integer>();
- {
- String[] Numbers = new String[11];
- String[] randomNum = {"", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
- int i = 10;
- int n = 10;
- /*creates an array for the randomly selected numbers*/
- }
- private ArrayList<Integer>permutation = new ArrayList<Integer>();
- {
- String Numbers = randomNum.Random.nextInt();
- }
- public int PermutationGenerator();
- {
- for(int i = 0; i < 10; i++)
- {
- nums.add(i + 1);
- }
- Random generator = new Random();
- {
- for (int n = 0; n < 10; n++)
- int n = randomNum.nextInt(nums.size());
- permutation.add(nums.get(d));
- }
- }
- }
Thank You.