It's not a secret anymore!
The moose likes Java in General and the fly likes random number generation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "random number generation" Watch "random number generation" New topic

random number generation

deepak borole

Joined: Nov 13, 2005
Posts: 25
how to generate random numbers without repetition of numbers from a range in java

Winners Dont Do Different Things, They Do Things Differently !!!
vibhu garg

Joined: Dec 28, 2005
Posts: 4
I don't think you can stop the JVM from randomly generating the next value different from the previous ones........because JVM doesn't store which values it has already generated in a range.......

Though you can control it, & put the random values in a Set..this way you can ensure that values are not duplicated........
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
You could create a List of all the numbers in the range, then call Collections.shuffle() on it. Now you have a list of numbers in random order with no repetitions.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: random number generation
It's not a secret anymore!