@hackage random-source0.3.0.13
Generic basis for random number generators
Categories
License
LicenseRef-PublicDomain
Maintainer
James Cook <mokus@deepbondi.net>
Links
Versions
Deprecated
Dependencies (11)
- base >=4 && <4.16
- mtl >=1 && <2
- primitive
- random >=1.2.0 && <1.3
- template-haskell
- flexible-defaults >=0.0.0.2 Show all…
Dependents (25)
@hackage/fei-datasets, @hackage/polysemy-RandomFu, @hackage/Dust-tools, @hackage/fei-examples, @hackage/bayes-stack, @hackage/lambdabot-misc-plugins, Show all…
Package Flags
base4
(on by default)
base-4 and above do not include syb
mtl2
(on by default)
mtl-2 has State, etc., as "type" rather than "newtype"
This is now deprecated and it is better to use the random package as the source of randomness.
Here's what you might have written before:
import qualified Data.Random as Random
import qualified Data.Random.Distribution.Bernoulli as Bernoulli
main :: IO ()
main = do
x <- Random.sample $ Bernoulli.Bernoulli (0.5 :: Double) :: IO Double
print x
And here's what you should write now (but there are many other options):
import qualified System.Random.Stateful as Random.Stateful
import qualified Data.Random as Random
import qualified Data.Random.Distribution.Bernoulli as Bernoulli
import qualified Control.Monad.Reader as Reader
main :: IO ()
main = do
stdgen <- Random.Stateful.newIOGenM =<< Random.Stateful.newStdGen
x <- Reader.runReaderT (Random.sample $ Bernoulli.Bernoulli (0.5 :: Double)) stdgen
:: IO Double
print x