WeightedRandom.Dice.Types (weighted_random v1.0.0-rc.1)

Copy Markdown View Source

Summary

Types

The map to later be turned into a Dice struct

Widely used notation for describing dice. Within the context of WeightedRandom, there are two formats: string, and tuple.

Types

dice_sides()

@type dice_sides() :: pos_integer()

dice_spec()

@type dice_spec() :: %{
  :dice => [WeightedRandom.Die.t()],
  optional(:modifier) => integer()
}

The map to later be turned into a Dice struct

die_spec()

@type die_spec() :: %{
  optional(:sides) => integer(),
  optional(:weights) => [WeightedRandom.Utils.Types.weight_spec()]
}

modifier()

@type modifier() :: integer()

num_dice()

@type num_dice() :: pos_integer()

standard_dice_notation()

@type standard_dice_notation() :: String.t()

Widely used notation for describing dice. Within the context of WeightedRandom, there are two formats: string, and tuple.

String: "#{num_dice}d#{dice_sides}+#{modifier}"

Tuple: {num_dice, dice_sides, modifier}

In either case, num_dice and modifier are both optional

String Examples

  • "d8" => A single die with 8 sides.
  • "4d6" => 4 dice with 6 sides each.
  • "2d10+1" => 2 dice, each with 10 sides, always adding +1 to the total

Tuple Examples

  • {8} => A single die with 8 sides.
  • {4, 6} => 4 dice with 6 sides each.
  • {2, 10, 1} => 2 dice, each with 10 sides, always adding +1 to the total