module Data.Stochastic.Internal (
boxMuller
, closedRnd
, openRnd
, closedOpenRnd
, openClosedRnd
) where
import System.Random
boxMuller :: (Floating a) => a -> a -> a
boxMuller u1 u2 = cos (2 * pi * u2) * (sqrt $ (2) * (log u1))
closedRnd :: (RandomGen g) => g -> (Double, g)
closedRnd gen = randomR (0, 1.0) gen
openRnd :: (RandomGen g) => g -> (Double, g)
openRnd gen = let (a, g) = closedRnd gen
in if a == 0 || a == 1
then openRnd g
else (a, g)
closedOpenRnd :: (RandomGen g) => g -> (Double, g)
closedOpenRnd gen = let (a, g) = closedRnd gen
in if a == 1
then closedOpenRnd g
else (a, g)
openClosedRnd :: (RandomGen g) => g -> (Double, g)
openClosedRnd gen = let (a, g) = closedRnd gen
in if a == 0
then openClosedRnd g
else (a, g)