Hello ! I'm not sure, but I think you mean a sequence of numbers in an arbitrary order (a so called permutation). A possibility to do so is to create an int-array with the numbers in the correct order. Something like
After that you could create a loop (e.g. 2*n iterations) and in each iteration you take to random numbers beetween 0 and n-1 and swap the two corresponding elements in the numbers-array. Use the Random-class in java.util for getting the random-numbers (method nextInt()). I hope that helped and I understood your problem ... Greetings from Hamburg, Stefan
Author of German LDAP-Book
Committer at Apache Directory Project
If you want a series of random numbers that will not contain identicals try (1) creating a int array to hold your random numbers (2) As many times as you need numbers: (a) generate random numbers in the desired range (b) test each number against all already stored in the array - this would likely be a method like "isANewOne" that returns a boolean. If isANewOne returns true you add the new random to the array and count that as one more successful find, otherwise you generate & test a new random. (3)Once your number of successful finds equals the number of unique randoms needed, you're done. (4)Remember to testy that the request is possible - for example, there's only 40 unique randoms between 1 and 40.