Safe Haskell | None |
---|

Representation of probabilities and random computations.

- type Rnd a = State StdGen a
- randomR :: Random a => (a, a) -> Rnd a
- random :: Random a => Rnd a
- oneOf :: [a] -> Rnd a
- frequency :: Show a => Frequency a -> Rnd a
- type Chance = Rational
- chance :: Chance -> Rnd Bool
- castDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Int
- chanceDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Bool
- castDiceXY :: AbsDepth -> AbsDepth -> DiceXY -> Rnd (Int, Int)

# The `Rng`

monad

type Rnd a = State StdGen aSource

The monad of computations with random generator state. The lazy state monad is OK here: the state is small and regularly forced.

# Random operations

randomR :: Random a => (a, a) -> Rnd aSource

Get a random object within a range with a uniform distribution.

frequency :: Show a => Frequency a -> Rnd aSource

Gen an element according to a frequency distribution.

# Fractional chance

# Casting dice scaled with level

castDice :: AbsDepth -> AbsDepth -> Dice -> Rnd IntSource

Cast dice scaled with current level depth. Note that at the first level, the scaled dice are always ignored.