module Data.Tempo.Random (countToRand, countToRands) where
import Data.Bits
xorwise :: Int -> Int
xorwise x =
let a = xor (shiftL x 13) x
b = xor (shiftR a 17) a
in xor (shiftL b 5) b
countToIntSeed :: RealFrac a => a -> Int
countToIntSeed = xorwise . truncate . (* 536870912) . snd . (properFraction :: (RealFrac a => a -> (Int,a))) . (/ 300)
intSeedToRand :: Fractional a => Int -> a
intSeedToRand = (/ 536870912) . realToFrac . (`mod` 536870912)
countToRand :: (RealFrac a, Fractional b) => a -> b
countToRand = intSeedToRand . countToIntSeed
countToRands :: (RealFrac a, Fractional b) => a -> Int -> [b]
countToRands t n = countToRands' (countToIntSeed t) n
countToRands' :: Fractional a => Int -> Int -> [a]
countToRands' seed n
| n <= 0 = []
| otherwise = (intSeedToRand seed) : (countToRands' (xorwise seed) (n-1))