[Haskell-cafe] working with Random.randoms

Henning Thielemann lemming at henning-thielemann.de
Sat Jun 14 09:23:28 EDT 2008


On Fri, 13 Jun 2008, Stephen Howard wrote:

> Hi List,
>
> I am a newcomer doing my obligatory struggling with Haskell's type system, 
> and I've got a nut I've not been able to crack.  Given:
>
> import Random
>
> random_test :: Int -> String
> random_test n = do
>   g <- getStdGen
>   take n (randoms g)::String
>
> I'm expecting that I ought to be able to pass this action an integer and get 
> back a random string that long (given, not all characters may be printable).

If you only need an arbitrary sequence and it is ok for you to get always 
the same one, you can construct a random generator using mkStdGen.


More information about the Haskell-Cafe mailing list