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
638 B

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