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.

  1. uniformDoublePositive01M :: StatefulGen g m => g -> m Double

    random 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.

  2. uniformEnumM :: (Enum a, Bounded a, StatefulGen g m) => g -> m a

    random 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
    

  3. uniformEnumRM :: (Enum a, StatefulGen g m) => (a, a) -> g -> m a

    random 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)
    

  4. uniformFloat01M :: StatefulGen g m => g -> m Float

    random 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.

  5. uniformFloatPositive01M :: StatefulGen g m => g -> m Float

    random 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.

  6. 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]
    

  7. uniformM :: (Uniform a, StatefulGen g m) => g -> m a

    random 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]
    

  8. uniformRM :: (UniformRange a, StatefulGen g m) => (a, a) -> g -> m a

    random 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>
    The following law should hold to make the function always defined:
    uniformRM (a, b) = uniformRM (b, a)
    

  9. uniformShortByteString :: StatefulGen g m => Int -> g -> m ShortByteString

    random System.Random.Stateful

    uniformShortByteString n g generates a ShortByteString of length n filled with pseudo-random bytes.

  10. uniformViaFiniteM :: (StatefulGen g m, Generic a, GFinite (Rep a)) => g -> m a

    random 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]
    

Page 412 of many | Previous | Next