LambdaHack-0.2.6.5: A roguelike game engine in early and active development

Game.LambdaHack.Random

Description

Representation of probabilities and random computations.

Synopsis

# The `Rng` monad

type Rnd a = State StdGen aSource

The monad of computations with random generator state.

# Random operations

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

Get a random object within a range 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.

Roll a single die.

# Rolling dice

data RollDice Source

Dice: 1d7, 3d3, 1d0, etc. `RollDice a b` represents `a` rolls of `b`-sided die.

Constructors

 RollDice Word8 Word8

Instances

 Eq RollDice Ord RollDice Read RollDice Show RollDice

Roll dice and sum the results.

Maximal value of dice.

Minimal value of dice.

Mean value of dice.

# Rolling 2D coordinates

data RollDiceXY Source

Dice for rolling a pair of integer parameters pertaining to, respectively, the X and Y cartesian 2D coordinates.

Constructors

 RollDiceXY (RollDice, RollDice)

Instances

 Show RollDiceXY

Roll the two sets of dice.

# Rolling dependent on depth

type RollDeep = (RollDice, RollDice)Source

Dice for parameters scaled with current level depth. To the result of rolling the first set of dice we add the second, scaled in proportion to current depth divided by maximal dungeon depth.

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

Roll dice scaled with current level depth and return `True` if the results if greater than 50.

Generate a `RollDeep` that always gives a constant integer.

Maximal value of scaled dice.

# Fractional chance

type Chance = RationalSource

Fractional chance.

Give `True`, with probability determined by the fraction.