[Haskell-cafe] How can i set the seed random number generator ?
Scott Turner
1haskell at pkturner.org
Tue Dec 22 07:16:16 EST 2009
On Monday 21 December 2009 20:37:30 zaxis wrote:
> In erlang, first i use the following function to set the seed:
> new_seed() ->
> {_,_,X} = erlang:now(),
> {H,M,S} = time(),
> H1 = H * X rem 32767,
> M1 = M * X rem 32767,
> S1 = S * X rem 32767,
> put(random_seed, {H1,M1,S1}).
>
> then use random:uniform/1 to get the random number.
>
> In haskell, i just use the following function to get the random number. It
> seems i donot need to set the seed of random number generator manually?
>
> rollDice :: Int -> IO Int
> rollDice n = randomRIO(1,n)
That's correct. randomRIO uses the global random number generator which is
automatically initialized with a different seed each time your program starts
up.
More information about the Haskell-Cafe
mailing list