Problem with System.Random

I installed the System.Random package with cabal (Prelude System.Random >), but when I compile a simple program like this:

threeCoins :: StdGen -> (Bool, Bool, Bool)
threeCoins gen =
let (firstCoin, newGen) = random gen
(secondCoin, newGen’) = random newGen
(thirdCoin, newGen’’) = random newGen’
in (firstCoin, secondCoin, thirdCoin)

a message tell me that StdGen it’s not a recognized type. I’m going crazy with that. Someone can explain me what’s wrong?

Hello Moreno,
you need to put

import System.Random

on top of your .hs file.


I write indeed (import System.Random) in the .hs file, but the problem persists. Is it possible that the code is obsolete, I mean StdGen is not already a type of System.Random?

StdGen definitely still exists

Could you show us a minimal example on what you’re trying, together with the imports? You can format the code by wrapping it in backticks like so:


Also if you could show us what you mean by “installed with cabal”.

1 Like