LambdaHack- A game engine library for roguelike dungeon crawlers

Safe HaskellNone




Representation of probabilities and random computations.


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.

random :: Random a => Rnd aSource

Get a random object of a given type with a uniform distribution.

oneOf :: [a] -> Rnd aSource

Get any element of a list with equal probability.

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

Gen an element according to a frequency distribution.

Fractional chance

type Chance = RationalSource

Fractional chance.

chance :: Chance -> Rnd BoolSource

Give True, with probability determined by the fraction.

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.

chanceDice :: AbsDepth -> AbsDepth -> Dice -> Rnd BoolSource

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.