I just started to study Haskellwith a pleasant reading, "Find out that you are Haskell for the great good!" and there’s an example in the book that makes no sense to me. It says that the following code will output the same random string twice:
main = do
gen <- getStdGen
putStrLn $ take 20 (randomRs ('a','z') gen)
gen2 <- getStdGen
putStrLn $ take 20 (randomRs ('a','z') gen2)
On the other hand, if the same program is called twice, it will undoubtedly give different results. Moreover, this does not seem consistent if I compare it with the code below, which gives different values s1and s2:
main = do
s1 <- getLine
s2 <- getLine
putStrLn s1
putStrLn s2
I am wondering how these two examples differ.
source
share