Advertisement
Guest User

Untitled

a guest
Jun 27th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.60 KB | None | 0 0
  1. import org.apache.commons.math3.random.RandomDataGenerator
  2.  
  3. sealed abstract class Distribution(params: List[String]) {
  4.   def get: Either[Int, Double]
  5. }
  6.  
  7. object Distribution {
  8.   protected val rnd: RandomDataGenerator = new RandomDataGenerator()
  9. }
  10.  
  11. case class Binomial(params: List[String]) extends Distribution(params)
  12. {
  13.   require( params.size == 2, "Wrong number of arguments! Binomial distribution expects (int trials, double p). Found "+params.size+" arguments." )
  14.   val trials: Int = params(0).toInt
  15.   val p: Double = params(1).toDouble
  16.  
  17.   def get: Int = Distribution.rnd.nextBinomial(trials, p)
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement