2010-06-09

Haskell's random

Hi, it is NISHIO Hirokazu, Haskell newbie. Today I post a small code. It's not a bug. It's a feature of Haskell.


$ ghci
GHCi, version 6.8.3
Prelude> import Random
Prelude Random> let g = mkStdGen 1
Prelude Random> (fst (random g)) + 0
-604496784
Prelude Random> (fst (random g)) / 1
0.35925462466181596
Prelude Random> (fst (random g)) * 1
-604496784
Prelude Random> (fst (random g)) * 1.0
0.35925462466181596


Yes, it is a feature. Haskell's random changes its behavior by what type inferred. See The Haskell 98 Library Report: Random Numbers.

No comments: