View Source WeightedRandom.Dice (weighted_random v0.4.1)
Summary
Functions
Adds weight to ALL dice in the Dice struct.
Take a list of Dice structs, and combine them without rerolling
Directly create a Dice struct.
Takes a Dice struct and rerolls it.
Convenience sigil for creating dice
Functions
Adds weight to ALL dice in the Dice struct.
Examples
iex> :rand.seed(:exsss, {205, 301, 402})
iex> d = ~d{10, 20}
iex> Enum.map(d.dice, &(&1.result))
[17, 10, 1, 16, 17, 15, 11, 16, 12, 3]
iex> d.total
118
iex> d = Dice.add_weight(d, [%{target: 2, weight: 25}])
iex> d = Dice.roll(d)
iex> Enum.map(d.dice, &(&1.result))
[2, 2, 2, 2, 3, 2, 2, 2, 18, 6]
iex> d.total
41
Take a list of Dice structs, and combine them without rerolling
Directly create a Dice struct.
Takes a Dice struct and rerolls it.
Examples
iex> :rand.seed(:exsss, {200, 301, 402})
iex> dice = ~d{2, 12}
iex> dice.total
8
iex> Dice.roll(dice).total
16
Convenience sigil for creating dice
Examples
iex> :rand.seed(:exsss, {100, 101, 102})
iex> d = ~d{4, 6, 1} # Equal to 4d6+1 in standard dice notation
iex> [die1 | _] = d.dice
iex> die1
%WeightedRandom.Die{sides: 6, weights: [], result: 2}
iex> d.subtotal
10
iex> d.total
11