Stability | experimental |
---|---|
Maintainer | Patrick Perry <patperry@stanford.edu> |
Safe Haskell | None |
Random number generators.
- newtype RNG = MkRNG (ForeignPtr ())
- data RNGType
- newRNG :: RNGType -> IO RNG
- setSeed :: RNG -> Word64 -> IO ()
- getSample :: RNG -> IO Word64
- getUniform :: RNG -> IO Double
- getUniformPos :: RNG -> IO Double
- getUniformInt :: RNG -> Int -> IO Int
- getName :: RNG -> IO String
- getMax :: RNG -> IO Word64
- getMin :: RNG -> IO Word64
- getSize :: RNG -> IO Word64
- getState :: RNG -> IO [Word8]
- setState :: RNG -> [Word8] -> IO ()
- copyRNG :: RNG -> RNG -> IO ()
- cloneRNG :: RNG -> IO RNG
- mt19937 :: RNGType
- rngType :: String -> Maybe RNGType
Data types
MkRNG (ForeignPtr ()) |
Initializing
newRNG :: RNGType -> IO RNGSource
Allocate a new random number generator of the given type and initialize it with the default seed.
Sampling
getUniform :: RNG -> IO DoubleSource
Returns a value uniform on [0,1)
getUniformPos :: RNG -> IO DoubleSource
Returns a value uniform on (0,1)
getUniformInt :: RNG -> Int -> IO IntSource
Returns an integer uniform on [0,n-1]. n
must be greater than 0
.
Auxiliary functions
setState :: RNG -> [Word8] -> IO ()Source
Set the generator state. The input array should have size equal
to getSize
of the generator; otherwise, strange things will happen.
Copying state
copyRNG :: RNG -> RNG -> IO ()Source
copyRNG dst src
copies the state from one generator to another. The
two generators must have the same type.
cloneRNG :: RNG -> IO RNGSource
Allocate a new random number generator that is an exact copy of another generator