module LCG where import Data.Bits modulus = 2^32 multiplier = 1103515245 increment = 12345 shiftval = 16 andmask = 0x7FFF lcg_pseudorandom_internal :: Integer -> [Integer] lcg_pseudorandom_internal n = pseudo_val:(lcg_pseudorandom_internal n_new) where n_new = (multiplier * n + increment) `mod` modulus pseudo_val = (shiftR n shiftval) .&. andmask --take a seed, a length of units vector and number of units and give a vector of orders lcg :: Int -> Int -> Int -> [Int] lcg seed len num = map (\x -> fromInteger (x `mod` toInteger len)) finite_vec where finite_vec = take num (lcg_pseudorandom_internal (toInteger seed))