samedi 21 juillet 2018

Haskell: How to seed (set the entropy used by) Data.Random?

The random-fu (Data.Random) package in Haskell offers the following example:

import Data.Random
import System.Random.MWC

logNormal :: Double -> Double -> RVar Double
logNormal mu sigmaSq = do
  x <- normal mu sigmaSq
  return (exp x)

main = do
  mwc <- create
  y <- sampleFrom mwc (logNormal 5 1)
  print y

It always generates the same result. I want to seed it from the clock. Ideally without having to get my hands dirty by actually reading the time.

(I haven't seen the word "seed" anywhere in the random-fu documentation, but I have found the phrsae "source of entropy" in a few places.)




Aucun commentaire:

Enregistrer un commentaire