Chances

public struct Chances
extension Chances: Equatable
extension Chances: Hashable
extension Chances: Describable

A struct that represents the chances of different Rolls happening.

Since

0.16.0

Author

Samasaur
  • Creates a new Chances object with no data.

    Declaration

    Swift

    public init()
  • Creates a new Chances object with the given chances.

    Declaration

    Swift

    public init(chances: [Roll : Chance])

    Parameters

    chances

    The rolls and the chances of them occurring.

  • Creates a new Chances object with the given chances.

    Declaration

    Swift

    public init(chances: (Roll, Chance)...)

    Parameters

    chances

    The rolls and the chances of them occurring.

  • Creates a new Chances object with the given chances.

    Declaration

    Swift

    public init(chances: [(Roll, Chance)])

    Parameters

    chances

    The rolls and the chances of them occurring.

  • The rolls and the chances of them occurring.

    This is the property one should use in order to iterate through the possibilities, like so:

    let chances: Chances = getChancesFromSomewhereElse()
    let arr = chances.chances.sorted(by: { first, second in
        first.key < second.key
    })
    for (roll, chance) in arr {
        print("The chance of rolling a \(roll) is \(chance.n) out of \(chance.d)")
    }
    

    Since

    0.21.0

    Declaration

    Swift

    public private(set) var chances: [Roll : Chance] { get }
  • The chance of the given roll occurring.

    This subscript can be used to get or set the chance.

    Declaration

    Swift

    public subscript(of roll: Roll) -> Chance { get set }

    Parameters

    roll

    The roll to query/set the chance of occurring.

  • A normalized version of this Chances instance. The sum of the Chances will be 1

    Since

    0.17.0

    Declaration

    Swift

    public var normalized: Chances { get }
  • Declaration

    Swift

    public static func == (lhs: Chances, rhs: Chances) -> Bool
  • Declaration

    Swift

    public func hash(into hasher: inout Hasher)
  • Declaration

    Swift

    public var description: String { get }
  • Declaration

    Swift

    public var debugDescription: String { get }