[Haskell-cafe] more improvable randomness
lemming at henning-thielemann.de
Thu Oct 15 17:16:03 EDT 2009
On Thu, 8 Oct 2009, Michael Mossey wrote:
> I wrote some code to model the keystroke-to-keystroke delay in a person
> typing, with pseudorandomness. There are two kinds of delays.. one is a
> very small delay as the person reaches for a new key (call this 'reach'
> delays), the other is a larger delay that represents a pause to think or
> to take a break (call this 'break' delays).
Has this to do with your PortMidi problems?
> breakSeries :: Int -> Int -> StdGen -> [Float]
> breakSeries lowerB upperB gen =
> let (n,gen1) = randomR (lowerB,upperB) gen
> (gen2,gen3) = split gen1
> delay = generate 1 gen2 breakM
> in replicate n 0 ++ [delay] ++ breakSeries lowerB upperB gen3
> breakM :: Gen Float
> breakM = frequency [ (10, choose( 1::Float , 2))
> , (10, choose( 4::Float , 6)) ]
> test = (print . take 100 . breakSeries 2 4 ) =<< newStdGen
Gen is from QuickCheck package, isn't it? That can't be mixed with Random
from 'random' package. You could wrap 'randomR' in a State monad
('transformers' package), write your own 'frequency' function for that,
and run that with the seed from 'newStdGen'.
More information about the Haskell-Cafe