module FRP.NetWire.Random
(
noise,
noise1,
noiseGen,
noiseR,
wackelkontakt,
pureNoise,
pureNoiseR
)
where
import qualified System.Random as R
import Control.Monad
import Control.Monad.IO.Class
import FRP.NetWire.Wire
import System.Random.Mersenne
noise :: MonadIO m => Wire m a Double
noise = noiseGen
noise1 :: MonadIO m => Wire m a Double
noise1 =
mkGen $ \(wsRndGen -> mt) _ -> do
x <- liftM (pred . (2*)) . liftIO $ random mt
x `seq` return (Right x, noise1)
noiseGen :: (MonadIO m, MTRandom b) => Wire m a b
noiseGen =
mkGen $ \(wsRndGen -> mt) _ -> do
x <- liftIO (random mt)
x `seq` return (Right x, noiseGen)
noiseR :: (MonadIO m, Real a, Integral b) => Wire m a b
noiseR =
mkGen $ \(wsRndGen -> mt) n -> do
x' <- liftIO (random mt)
let x = floor ((x' :: Double) * realToFrac n)
return (Right x, noiseR)
pureNoise :: (Monad m, R.RandomGen g, R.Random b) => g -> Wire m a b
pureNoise g' =
mkGen $ \_ _ ->
let (x, g) = R.random g'
in x `seq` return (Right x, pureNoise g)
pureNoiseR :: (Monad m, R.RandomGen g, R.Random b) => g -> Wire m (b, b) b
pureNoiseR g' =
mkGen $ \_ range ->
let (x, g) = R.randomR range g'
in return (Right x, pureNoise g)
wackelkontakt :: MonadIO m => Wire m a Bool
wackelkontakt = noiseGen