views:

3540

answers:

5

From what I understand, the standard generator is for the Normal Distribution. I have to generate random numbers according to the Normal, Uniform and Poisson Distributions, but I can't seem to find a class for the last 2.

I have to generate them in the range of 0 - 999999.

+4  A: 

Check out Jakarta Commons Math and its JavaDoc. This library has (among other things) implementations of:

If the 3rd option isn't what your looking for, it still may be part of Commons Math.

Eddie
+2  A: 

Actually, the standard generator is for the uniform distribution. The basic random number generator in any language/library will always (in all cases I know of) use the uniform distribution because that's what comes out of all the popular pseudorandom number generator algorithms - basically, uniform random numbers are the easiest.

I see Eddie already pointed you to a link for other distributions so I'll skip writing the rest of this...

David Zaslavsky
Actually, it looks like that link also points out the "nextGaussian" method to create normal variates too.
gnovice
A: 
Tom
I fixed the formatting of the numbered list to what I believe you intended. If this is not what you intended, then of course feel free to roll back the change.
Eddie
+3  A: 
Simon Nickerson
Is there a way to specify the min and max value they use? Doesn't seem like it, from what I saw.
That's because Poisson and Normal distributions don't have a maximum or minimum (well, Poisson has a fixed minimum of 0).
Simon Nickerson
A: 

The standard Java RNG (java.util.Random), and its subclasses such as java.security.SecureRandom, already generate uniformly distributed values.

They also have a method, nextGaussian, that returns normally-distributed values. By default, the distribution has mean of zero and standard deviation of 1 but this is trivially tweaked. Just multiply by the required s.d. and add the required mean. So, for example, if you wanted normally-distributed values with a mean of 6 and standard deviation of 2.5, you'd do this:

double value = rng.nextGaussian() * 2.5 + 6;

The Poisson distribution is not explicitly supported, but you can fake it by doing the same as Tom's Python code.

Alternatively, you may be interested in my Uncommons Maths library, which provides utility classes for Normal, Poisson and other distributions.

Dan Dyer