LambdaHack-0.7.0.0: A game engine library for roguelike dungeon crawlers

Safe HaskellNone
LanguageHaskell2010

Game.LambdaHack.Common.Random

Contents

Description

Representation of probabilities and random computations.

Synopsis

The Rng monad

type Rnd a = State StdGen a Source #

The monad of computations with random generator state.

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.

Specialized monadic folds

foldrM :: Foldable t => (a -> b -> Rnd b) -> b -> t a -> Rnd b Source #

foldlM' :: Foldable t => (b -> a -> Rnd b) -> b -> t a -> Rnd b Source #

Internal operations

rollFreq :: Show a => Frequency a -> StdGen -> (a, StdGen) Source #

Randomly choose an item according to the distribution.