haskell-numerics / random-fu

A suite of Haskell libraries for representing, manipulating, and sampling random variables
42 stars 21 forks source link

How do I use Data.Random.Source.IO to generate random numbers in Windows AND Unix? #9

Open mcandre opened 12 years ago

mcandre commented 12 years ago

I want my code to be platform-agnostic, but I can't find example code using Data.Random.Source.IO anywhere in the documentation.

mokus0 commented 12 years ago

Data.Random.Source.IO declares a "MonadRandom" instance for IO, which means that random variables can be sampled using the "sample" function.

For example:

sample (uniform 0 10) :: IO Int

Should "just work". If you need to reference it as a concrete "source", you can use the special value StdRandom, as in:

sampleFrom StdRandom (uniform 0 10) :: IO Int

StdRandom is a pseudo-source that refers to the default source of randomness for the monad in which it is used.

Sorry to take so long to reply. I've been mostly offline for a few months.