Sampling from a distribution

I guess I overlook something, but when migrating from Apache common math3, there was a method “sample()” defined on statistical distributions that allowed to draw a random sample based on the used distribution and defined parameters for that distribution.

I cannot figure out how to do this with Hipparchus, since the sample function isn’t there anymore. Any hints or tips?


Hi there,

I’m not familiar with that part of the library but I see that there is a bunch of generator classes in the package called random within hipparchus-core. Maybe it has the distribution that you need?


Thanks, indeed the random generator classes have methods that provide this functionality. For future reference:

val rg: RandomGenerator = JDKRandomGenerator()
val gen = GaussianRandomGenerator(rg)

For my use-case it would be nicer if this would be the instance of a class and could be past as a parameter (rather than a hard-coded method on a generator). But can work around this.

It was removed very early in Hipparchus, in May 2016. See commit f962712.
I don’t remember the rationale behind this decision.

I’m no english native speaker, but should the names of the methods:

  • org.hipparchus.random.RandomDataGenerator#nextDeviate(IntegerDistribution)
  • org.hipparchus.random.RandomDataGenerator#nextDeviates(IntegerDistribution)
  • org.hipparchus.random.RandomDataGenerator#nextDeviate(RealDistribution)
  • org.hipparchus.random.RandomDataGenerator#nextDeviates(RealDistribution)

better be renamed to nextVariate, nextVariates?

Not native speaker either, so I will just wait until someone more fluent than me in both math/english decides!
As next version will be a major one (3.0), we can can change these names if required.