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 a Source

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 a Source

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

random :: Random a => Rnd a Source

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

oneOf :: [a] -> Rnd a Source

Get any element of a list with equal probability.

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

Gen an element according to a frequency distribution.

Fractional chance

type Chance = Rational Source

Fractional chance.

chance :: Chance -> Rnd Bool Source

Give True, with probability determined by the fraction.

Casting dice scaled with level

castDice :: AbsDepth -> AbsDepth -> Dice -> Rnd Int Source

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

chanceDice :: 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.