module Stochastic.Poisson(mkPoisson, Poisson) where import Stochastic.Distribution import Stochastic.Exponential import Helpers data Poisson = Poisson Exponential mkPoisson :: Exponential -> Poisson mkPoisson base = Poisson base toDbl :: Int -> Double toDbl = fromInteger . toInteger instance DiscreteDistribution Poisson where randIntIn (a, b) (Poisson g0) = mapTuple (\x -> min (x+a-1) b) (Poisson) (f 0 0 g0) where f x s g1 | s > 1 = (x-1, g1) | otherwise = f (x+1) (s+y) g2 where (y, g2) = (randDouble g1)