You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
652 B

module LCG where
import Data.Bits(shiftR,(.&.))
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))