The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

importjava.util.Random;//imports the Random java classpublicclass PermutationGenerator
{/*This method iterates the nextPermutation() method 10 times
*to produce 10 differernt arrays of size 10 with integers
*1 to 10 inclusive*/publicvoid PGenerator(){
PermutationGenerator a =new PermutationGenerator();for(int i=0;i<10;i++) a.nextPermutation();//This loop repeats the nextPermutation method 10 times to produce 10 different arrays}/*This method returns an array of 10 integers from
*1 to 10 inclusive in a random order by creating a
*new array from permutations of a base array*/publicint[] nextPermutation(){Random rand =newRandom();//Creates the random generatorint baseSize =0;//Initializes the base counter as 0int[] base =newint[10];//Initializes the base arrayfor(int i =0; i<10; i++){//This loop fills up the base array with integers 1 to 10 inclusive
base[i]= i +1;
baseSize++;//Increases the counter for base sizeSystem.out.println(base);}int[] mutation =newint[10];//Initializes the mutation arrayfor(int i =0; i<10; i++){int a = rand.nextInt(baseSize);//Picks a random index between 0 and the length of the base array
mutation[i]= base[a];//Sets the ith index of the result mutation array to the value at a in the basefor(int j = a; j<baseSize -1; j++){
base[j]= base[j +1];//This loop deletes the value at index a in the base array to prevent it from being chosen againSystem.out.println(base);}
baseSize--;//Decreases the length of the base array}return mutation;}publicstaticvoid main(String[] args){}}publicstaticvoid main(String[] args){}

Re: Help generating random permutations from array list

There is no output for this code

Add some println statements that print out messages as the code is executed and shows the execution flow and the values of variables as they are changed and used.
Put the println statements in all the methods so you know what is being executed.

Re: Help generating random permutations from array list

What methods did you see were being executed? What was printed out?
Did the method that was executed call any other methods?
Where those other methods executed?
You'll know when a method is executed when the println statement prints out a message.