Re: [Haskell-cafe] How can i set the seed random number generator ?
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. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How can i set the seed random number generator ?
On Tue, Dec 22, 2009 at 1:16 PM, Scott Turner 1hask...@pkturner.org wrote: 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. but you can always change it with setStdGen, and you can always use the non-IO part of System.Random (or even another random library altogether, particularly recommended if you need performances as System.Random is more than slow). -- Jedaï ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] How can i set the seed random number generator ?
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) Sincerely! - fac n = foldr (*) 1 [1..n] -- View this message in context: http://old.nabble.com/How-can-i-set-the-seed-random-number-generator---tp26882798p26882798.html Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe