Skip to content

Commit

Permalink
feat(runtime): Add more functions to RandomInterval
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-daniel-gustafsson committed Dec 16, 2021
1 parent 97a424f commit cd98cae
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/runtime-prototype/src/StuntDouble/Random.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ module StuntDouble.Random
, makeSeedIO
, interval
, exponential
, add
, detRandomInterval
, isLessThan
)
where

import Data.Fixed (mod')
import System.Random

------------------------------------------------------------------------
Expand All @@ -27,6 +31,15 @@ makeSeedIO = fmap makeSeed randomIO
newtype RandomInterval = RandomInterval Double
deriving Show

detRandomInterval :: Double -> RandomInterval
detRandomInterval d = RandomInterval $ mod' d 1

add :: RandomInterval -> RandomInterval -> RandomInterval
add (RandomInterval d) (RandomInterval d') = detRandomInterval $ d + d'

isLessThan :: RandomInterval -> Double -> Bool
isLessThan (RandomInterval d) d' = d < d'

interval :: Seed -> (RandomInterval, Seed)
interval seed =
let
Expand Down

0 comments on commit cd98cae

Please sign in to comment.