Control.Monad.Gen.Trans
- Package
- purescript-generate-values
- Repository
- jordanmartinez/purescript-generate-values
This module defines the random generator monad using a linear congruential generator, as well as helper funtions for constructing random generators.
Depending on your underlying monad, stack-safety can be an issue.
All functions (e.g. vectorOf) that do not end with ' are stack-safe,
but sometimes this safety is guaranteed via MonadRec.
If your underlying monad (e.g. Aff) is already stack-safe, you can omit
this extra constraint and use the variant that ends with '
(e.g. vectorOf').
#GenT Source
#perturbGenT Source
perturbGenT :: forall m a. Monad m => Number -> GenT m a -> GenT m aPerturb a random generator by modifying the current seed
#resizeGenT Source
resizeGenT :: forall m a. Monad m => Int -> GenT m a -> GenT m aModify a random generator by setting a new size parameter.
#perturbGen Source
perturbGen :: forall m a. Monad m => Number -> Gen a -> Gen aPerturb a random generator by modifying the current seed
#repeatable Source
repeatable :: forall m a b. Monad m => (a -> Gen b) -> GenT m (a -> b)Create a random generator for a function type.
Note that the a -> Gen b cannot run effects.
#oneOf Source
oneOf :: forall m a. Monad m => NonEmptyArray (GenT m a) -> GenT m aCreate a random generator which selects and executes a random generator from a non-empty array of random generators with uniform probability.
#arrayOf1 Source
arrayOf1 :: forall m a. MonadRec m => GenT m a -> GenT m (NonEmptyArray a)Create a random generator which generates a non-empty array of random values.
Stack-safety is guaranteed via the MonadRec constraint
#arrayOf1' Source
arrayOf1' :: forall m a. Monad m => GenT m a -> GenT m (NonEmptyArray a)Create a random generator which generates a non-empty array of random values. This is only stack-safe if the underlying monad is stack-safe.
#enum Source
enum :: forall m a. Monad m => BoundedEnum a => GenT m aCreate a random generator for a finite enumeration.
toEnum i must be well-behaved:
It must return a value wrapped in Just for all Ints between
fromEnum bottom and fromEnum top.
#elements Source
elements :: forall m a. Monad m => NonEmptyArray a -> GenT m aCreate a random generator which selects a value from a non-empty array with uniform probability.
#randomSample1 Source
randomSample1 :: forall m a. MonadEffect m => GenT m a -> m aGenerate a single value using a randomly generated seed.
#randomSampleN Source
randomSampleN :: forall m a. MonadRec m => MonadEffect m => Int -> GenT m a -> m (Array a)Sample a random generator, using a randomly generated seed
Stack-safety is guaranteed via the MonadRec constraint
#randomSampleN' Source
randomSampleN' :: forall m a. MonadEffect m => Int -> GenT m a -> m (Array a)Sample a random generator, using a randomly generated seed This is only stack-safe if the underlying monad is stack-safe.
- Modules
- Control.
Monad. Gen. Trans