Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.apache.commons.math3.random.RandomDataGenerator
- sealed abstract class Distribution(params: List[String]) {
- def get: Either[Int, Double]
- }
- object Distribution {
- protected val rnd: RandomDataGenerator = new RandomDataGenerator()
- }
- case class Binomial(params: List[String]) extends Distribution(params)
- {
- require( params.size == 2, "Wrong number of arguments! Binomial distribution expects (int trials, double p). Found "+params.size+" arguments." )
- val trials: Int = params(0).toInt
- val p: Double = params(1).toDouble
- def get: Int = Distribution.rnd.nextBinomial(trials, p)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement