Hoogle Search
Within LTS Haskell 24.38 (ghc-9.10.3)
Note that Stackage only displays results for the latest LTS and Nightly snapshot. Learn more.
uniformDoublePositive01M :: StatefulGen g m => g -> m Doublerandom System.Random.Stateful Generates uniformly distributed Double in the range <math>. Number is generated as <math>. Constant is 1/2 of smallest nonzero value which could be generated by uniformDouble01M.
uniformEnumM :: (Enum a, Bounded a, StatefulGen g m) => g -> m arandom System.Random.Stateful Generates uniformly distributed Enum. One can use it to define a Uniform instance:
data Colors = Red | Green | Blue deriving (Enum, Bounded) instance Uniform Colors where uniformM = uniformEnumM
uniformEnumRM :: (Enum a, StatefulGen g m) => (a, a) -> g -> m arandom System.Random.Stateful Generates uniformly distributed Enum in the given range. One can use it to define a UniformRange instance:
data Colors = Red | Green | Blue deriving (Enum) instance UniformRange Colors where uniformRM = uniformEnumRM inInRange (lo, hi) x = isInRange (fromEnum lo, fromEnum hi) (fromEnum x)
uniformFloat01M :: StatefulGen g m => g -> m Floatrandom System.Random.Stateful Generates uniformly distributed Float in the range <math>. Numbers are generated by generating uniform Word32 and dividing it by <math>. It's used to implement UniformRange instance for Float.
uniformFloatPositive01M :: StatefulGen g m => g -> m Floatrandom System.Random.Stateful Generates uniformly distributed Float in the range <math>. Number is generated as <math>. Constant is 1/2 of smallest nonzero value which could be generated by uniformFloat01M.
uniformListM :: (StatefulGen g m, Uniform a) => Int -> g -> m [a]random System.Random.Stateful Generates a list of pseudo-random values.
Examples
>>> import System.Random.Stateful >>> let pureGen = mkStdGen 137 >>> g <- newIOGenM pureGen >>> uniformListM 10 g :: IO [Bool] [True,True,True,True,False,True,True,False,False,False]
uniformM :: (Uniform a, StatefulGen g m) => g -> m arandom System.Random.Stateful Generates a value uniformly distributed over all possible values of that type. There is a default implementation via Generic:
>>> :set -XDeriveGeneric -XDeriveAnyClass >>> import GHC.Generics (Generic) >>> import System.Random.Stateful >>> data MyBool = MyTrue | MyFalse deriving (Show, Generic, Finite, Uniform) >>> data Action = Code MyBool | Eat (Maybe Bool) | Sleep deriving (Show, Generic, Finite, Uniform) >>> gen <- newIOGenM (mkStdGen 42) >>> uniformListM 10 gen :: IO [Action] [Code MyTrue,Code MyTrue,Eat Nothing,Code MyFalse,Eat (Just False),Eat (Just True),Eat Nothing,Eat (Just False),Sleep,Code MyFalse]
uniformRM :: (UniformRange a, StatefulGen g m) => (a, a) -> g -> m arandom System.Random.Stateful Generates a value uniformly distributed over the provided range, which is interpreted as inclusive in the lower and upper bound.
- uniformRM (1 :: Int, 4 :: Int) generates values uniformly from the set <math>
- uniformRM (1 :: Float, 4 :: Float) generates values uniformly from the set <math>
uniformRM (a, b) = uniformRM (b, a)
uniformShortByteString :: StatefulGen g m => Int -> g -> m ShortByteStringrandom System.Random.Stateful uniformShortByteString n g generates a ShortByteString of length n filled with pseudo-random bytes.
uniformViaFiniteM :: (StatefulGen g m, Generic a, GFinite (Rep a)) => g -> m arandom System.Random.Stateful A definition of Uniform for Finite types. If your data has several fields of sub-Word cardinality, this instance may be more efficient than one, derived via Generic and GUniform.
>>> :set -XDeriveGeneric -XDeriveAnyClass >>> import GHC.Generics (Generic) >>> import System.Random.Stateful >>> data Triple = Triple Word8 Word8 Word8 deriving (Show, Generic, Finite) >>> instance Uniform Triple where uniformM = uniformViaFiniteM >>> gen <- newIOGenM (mkStdGen 42) >>> uniformListM 5 gen :: IO [Triple] [Triple 60 226 48,Triple 234 194 151,Triple 112 96 95,Triple 51 251 15,Triple 6 0 208]