This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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
Author

random number generation

deepak borole
Greenhorn

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
Greenhorn

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
Wanderer
Sheriff

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: http://aspose.com/file-tools
 
subject: random number generation