This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach 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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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
 
Don't get me started about those stupid light bulbs.
 
subject: random number generation
 
Similar Threads
Generating Random Number
Random Numbers ??
random number generation
generation of random numbers without using Random
Random number