Safe Haskell | None |
---|
Representation of probabilities and random computations.
- type Rnd a = State StdGen a
- randomR :: Random a => (a, a) -> Rnd a
- random :: Random a => Rnd a
- oneOf :: [a] -> Rnd a
- frequency :: Show a => Frequency a -> Rnd a
- roll :: Int -> Rnd Int
- data RollDice = RollDice Word8 Word8
- rollDice :: RollDice -> Rnd Int
- maxDice :: RollDice -> Int
- minDice :: RollDice -> Int
- meanDice :: RollDice -> Rational
- data RollDiceXY = RollDiceXY (RollDice, RollDice)
- rollDiceXY :: RollDiceXY -> Rnd (Int, Int)
- type RollDeep = (RollDice, RollDice)
- rollDeep :: Int -> Int -> RollDeep -> Rnd Int
- chanceDeep :: Int -> Int -> RollDeep -> Rnd Bool
- intToDeep :: Int -> RollDeep
- maxDeep :: RollDeep -> Int
- type Chance = Rational
- chance :: Chance -> Rnd Bool
- rndToIO :: Rnd a -> IO a
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.
frequency :: Show a => Frequency a -> Rnd aSource
Gen an element according to a frequency distribution.
Rolling dice
Dice: 1d7, 3d3, 1d0, etc.
RollDice a b
represents a
rolls of b
-sided die.
Rolling 2D coordinates
data RollDiceXY Source
Dice for rolling a pair of integer parameters pertaining to, respectively, the X and Y cartesian 2D coordinates.
rollDiceXY :: RollDiceXY -> Rnd (Int, Int)Source
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.
rollDeep :: Int -> Int -> RollDeep -> Rnd IntSource
Roll dice scaled with current level depth. Note that at the first level, the scaled dice are always ignored.
chanceDeep :: Int -> Int -> RollDeep -> Rnd BoolSource
Roll dice scaled with current level depth and return True
if the results if greater than 50.