Thursday, August 29, 2002 02:52 PM
If possible, you'd be better off with next(int) than nextInt(int), as there is no filter that skews the randomness.. and by the way, filtering out duplicates also skews the randomness of your overall sample.
If that doesn't smooth out your histogram (you need a very large sample to be able to tell), try java.security.SecureRandom
which uses a stronger, but slower random number generation algorithm.
You are on the right track with seeding the generator to the time before you get in the loop, otherwise you will get the same random sequence every time you run the application.
It is not a good idea to re-seed for every iteration. Setting the seed just changes the starting point in the random (pseudo-random, actually) sequence, and you break the randomness by re-seeding every time.