What's the best seed for random API ?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

What's the best seed for random API ?

z_axis
picoSec :: IO Integer
picoSec = do
    t <- ctPicosec `liftM` (getClockTime >>= toCalendarTime)
    return t

rollDice ::  Int -> IO Int
rollDice n = do
    ps <- picoSec
    return $ (take 1 $ randomRs (1,n) $ mkStdGen $ fromInteger ps) !! 0

The above code uses `ctPicosec` as seed. Is it better to use the output of /dev/urandom as seed ?

Sincerely!
e^(π.i) + 1 = 0
Reply | Threaded
Open this post in threaded view
|

Re: What's the best seed for random API ?

Alex Rozenshteyn
Admittedly, I don't know much about this from the haskell end or about the particular api.

If you want statistical randomness, your seed doesn't matter; just the PRNG.  I might even have seeded with a constant or taken the seed from the user.

Seeding from urandom will make your output "more random" for some unquantifiable meaning of the phrase.

If you want cryptographic randomness, you probably shouldn't be writing your own library if you can avoid it.

On Wed, Jan 5, 2011 at 7:21 PM, z_axis <[hidden email]> wrote:

picoSec :: IO Integer
picoSec = do
   t <- ctPicosec `liftM` (getClockTime >>= toCalendarTime)
   return t

rollDice ::  Int -> IO Int
rollDice n = do
   ps <- picoSec
   return $ (take 1 $ randomRs (1,n) $ mkStdGen $ fromInteger ps) !! 0

The above code uses `ctPicosec` as seed. Is it better to use the output of
/dev/urandom as seed ?

Sincerely!

-----
e^(π.i) + 1 = 0
--
View this message in context: http://haskell.1045720.n5.nabble.com/What-s-the-best-seed-for-random-API-tp3329807p3329807.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe



--
          Alex R


_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: What's the best seed for random API ?

Robert Clausecker
In reply to this post by z_axis
It probably is, but definitly not portable. Try to find /dev/urandom
under Windows.

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe