vector-random-0.2: Generate vectors filled with high quality pseudorandom numbers






Fill a vector with randoms.

randoms :: (PureMTRandom a, Vector v a) => PureMT -> Int -> v aSource

Return a random vector of length n, filled with random elements of type a generated by the mersenne-twister.

E.g. to compute the sum of 100 million random Double values in a vector:

 import qualified Data.VectorUnboxed as U
 import System.Random.Mersenne.Pure64
 import qualified Data.Vector.Random.Mersenne as G
 main = do
     g <- newPureMT
     let a = G.random g 10000000 :: U.Vector Double
     print (U.sum a)

The generator will fuse under stream fusion, so e.g. sum . random g will allocate no intermediate array.

Class of MT random types

class PureMTRandom a whereSource

Class of types that we have efficient generators for.


random :: PureMT -> (a, PureMT)Source

Given a pure mersenne twister state, yield a new random value, and the next state.