Safe Haskell | None |
---|---|
Language | Haskell2010 |
Representation of probabilities and random computations.
Synopsis
- type Rnd a = State SMGen a
- randomR :: Integral a => (a, a) -> Rnd a
- randomR0 :: Integral a => a -> Rnd a
- nextRandom :: forall a. Integral a => a -> SMGen -> (a, SMGen)
- randomWord32 :: Rnd Word32
- oneOf :: [a] -> Rnd a
- shuffle :: Eq a => [a] -> Rnd [a]
- shuffleExcept :: Vector Word16 -> Int -> [Word16] -> Rnd [Word16]
- frequency :: Show a => Frequency a -> Rnd a
- type Chance = Rational
- chance :: Chance -> Rnd Bool
- castDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Int
- oddsDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Bool
- castDiceXY :: AbsDepth -> AbsDepth -> DiceXY -> Rnd (Int, Int)
- foldrM :: Foldable t => (a -> b -> Rnd b) -> b -> t a -> Rnd b
- foldlM' :: Foldable t => (b -> a -> Rnd b) -> b -> t a -> Rnd b
- rollFreq :: Show a => Frequency a -> SMGen -> (a, SMGen)
The Rng
monad
Random operations
randomR :: Integral a => (a, a) -> Rnd a Source #
Get a random object within a (inclusive) range with a uniform distribution.
nextRandom :: forall a. Integral a => a -> SMGen -> (a, SMGen) Source #
Generate a random integral value in [0, x]
range, where x
is within
Int32
.
The limitation to Int32
values is needed to keep it working on signed
types. In package random
, a much more complex scheme is used
to keep it working for arbitrary fixed number of bits.
shuffle :: Eq a => [a] -> Rnd [a] Source #
Generates a random permutation. Naive, but good enough for small inputs.
shuffleExcept :: Vector Word16 -> Int -> [Word16] -> Rnd [Word16] Source #
Generates a random permutation, except for the existing mapping.
frequency :: Show a => Frequency a -> Rnd a Source #
Gen an element according to a frequency distribution.
Fractional chance
Casting dice scaled with level
castDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Int Source #
Cast dice scaled with current level depth.
oddsDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Bool Source #
Cast dice scaled with current level depth and return True
if the results is greater than 50.
castDiceXY :: AbsDepth -> AbsDepth -> DiceXY -> Rnd (Int, Int) Source #
Cast dice, scaled with current level depth, for coordinates.