-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrandom_seed.hs
26 lines (23 loc) · 1.02 KB
/
random_seed.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import System.Random
import Control.Monad (replicateM)
import Data.Time.Clock.POSIX (getPOSIXTime)
-- genRandomNumbers x: generate a list of x random numbers
genRandomNumbers :: (Random a, Integral a) => Int -> Int -> [a]
genRandomNumbers n seed = take n $ (randoms myGenerator) where
myGenerator = mkStdGen seed
genRandomNumbersBetween :: Int -> Int -> (Int, Int) -> [Int]
genRandomNumbersBetween n seed (a, b) = take n $ (randomRs (a, b) myGenerator) where
myGenerator = mkStdGen seed
main :: IO ()
main = do
seed <- (round . (* 1000)) <$> getPOSIXTime
-- -- Generate 10 random numbers with a millisecond timestamp
-- -- as the seed and display them to the console.
-- putStrLn "Print 10 random numbers"
-- let numbers = genRandomNumbers 10 seed :: [Int]
-- putStrLn (show numbers)
-- seed <- (round .(* 1000)) <$> getPOSIXTime
-- putStrLn "Print 10 random numbers between 1 and 10"
let numbers = take 1 (genRandomNumbersBetween 10 seed (1, 10) :: [Int])
putStrLn (show seed)
return ()