All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.twitter.scalding.mathematics.Poisson.scala Maven / Gradle / Ivy

There is a newer version: 0.16.1-RC3
Show newest version
package com.twitter.scalding.mathematics

import scala.util.Random

/**
 * Generating Poisson-distributed random variables
 * according to Donald Knuth's algorithm as shown on Wikipedia's
 * Poisson Distribution page
 */

class Poisson(fraction: Double, seed: Int) {

  val L = math.exp(-fraction)
  val randomGenerator = new Random(seed)

  def nextInt = {
    var k = 0
    var p = 1.0
    do {
      k = k + 1
      p = p * randomGenerator.nextDouble
    } while (p > L)
    k - 1
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy