I need to implement random sampling from a number of common probability distributions (normal, binomial, gamma, ...) in my java program. I found Random.nextGaussian() and was just wondering if there's any other built in support for distributions other than normal? Or are my only options third party library or DIY?
Best How To :
You’d be looking at java.lang.math, and from the docs:
The class Math contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.
So in short no. For distributions other than Gaussian you’re going to have to look elsewhere.
In terms of third party libraries, Apache Commons (AbstractRealDistribution) is probably your best bet. But I’ve also had success with Colt.
As for DIY, a simple google search should do it, e.g. Gamma, Binomial