LambdaHack-0.10.2.0: A game engine library for tactical squad ASCII roguelike dungeon crawlers
Safe HaskellNone
LanguageHaskell2010

Game.LambdaHack.Core.Random

Description

Representation of probabilities and random computations.

Synopsis

The Rng monad

type Rnd a = State SMGen a Source #

The monad of computations with random generator state.

Random operations

randomR :: Integral a => (a, a) -> Rnd a Source #

Get a random object within a (inclusive) range with a uniform distribution.

randomR0 :: Integral a => a -> Rnd a Source #

Generate random Integral in [0, x] range.

nextRandom :: forall a. Integral a => a -> SMGen -> (a, SMGen) Source #

Generate a random integral value in [0, x] range, where x is within Int32.

The limitation to Int32 values is needed to keep it working on signed types. In package random, a much more complex scheme is used to keep it working for arbitrary fixed number of bits.

randomWord32 :: Rnd Word32 Source #

Get a random Word32 using full range.

oneOf :: [a] -> Rnd a Source #

Get any element of a list with equal probability.

shuffle :: Eq a => [a] -> Rnd [a] Source #

Generates a random permutation. Naive, but good enough for small inputs.

shuffleExcept :: Vector Word16 -> Int -> [Word16] -> Rnd [Word16] Source #

Generates a random permutation, except for the existing mapping.

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.

oddsDice :: 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 -> SMGen -> (a, SMGen) Source #

Randomly choose an item according to the distribution.