module Control.Wire.Prefab.Noise
(
noise,
noiseR,
wackelkontakt,
noiseM,
noiseRM,
wackelkontaktM
)
where
import Control.Monad
import Control.Wire.Classes
import Control.Wire.Prefab.Accum
import Control.Wire.Types
import Control.Wire.Wire
import Data.Monoid
import System.Random
noise ::
(Random b, RandomGen g)
=> g
-> Wire e m a b
noise = unfold (\g' _ -> random g')
noiseM ::
(MonadRandom m, Random b)
=> Wire e m a b
noiseM =
mkFixM $ \_ _ -> liftM (Right $!) getRandom
noiseRM ::
(MonadRandom m, Random b)
=> Wire e m (b, b) b
noiseRM = mkFixM $ \_ -> liftM (Right $!) . getRandomR
noiseR ::
(Random b, RandomGen g)
=> g
-> Wire e m (b, b) b
noiseR = unfold (\g' r -> randomR r g')
wackelkontakt ::
(Monoid e, RandomGen g)
=> Double
-> g
-> Event e m a
wackelkontakt p g' =
mkPure $ \_ x ->
let (e, g) = random g' in
(if (e < p) then Right x else Left mempty, wackelkontakt p g)
wackelkontaktM ::
(MonadRandom m, Monoid e)
=> Double
-> Event e m a
wackelkontaktM p =
mkFixM $ \_ x -> do
e <- getRandom
return (if (e < p) then Right x else Left mempty)