WeightedDie
public struct WeightedDie
extension WeightedDie: Rollable
extension WeightedDie: Equatable
extension WeightedDie: Hashable
extension WeightedDie: Describable
A representation of a weighted die; i.e. a die whose sides do not necessarily have the same chance of being rolled.
The chances of specific rolls are passed using a Chances object. It is recommended to create the object separately, because it is easier to manipulate the Chances that way.
Since
0.16.0-
Creates a new
WeightedDiewith the given rolls and chances of them occurring.Throws
Error.emptyDictionaryParameters
cThe rolls and the chances of them occurring.
-
The number of possible
Rolls.Declaration
Swift
public var sides: Int { get } -
Creates a new
WeightedDiethat is a copy of the givenWeightedDie.Declaration
Swift
@available(*, deprecated, message: "CustomDie is now a struct; copying is not necessary") public init(copyOf other: WeightedDie)Parameters
otherThe other
WeightedDieto copy. -
The probabilities of all possible rolls.
Since
0.17.0Declaration
Swift
public var probabilities: Chances { get } -
The exact (double) average result from using the
roll()method.Declaration
Swift
public var doubleAverageResult: Double { get } -
Determines whether this
WeightedDiecan reach the targetRollusing the given comparison type.Since
0.15.0
Declaration
Swift
public func canReach(_ target: Roll, _ comparisonType: RollComparison) -> BoolParameters
targetThe target to check reachibility for.
comparisonTypeThe comparison to use when checking reachibility.
Return Value
Whether or not this WeightedDie can reach the target, using the given comparison.
-
Declaration
Swift
public static func == (lhs: WeightedDie, rhs: WeightedDie) -> Bool -
Declaration
Swift
public func hash(into hasher: inout Hasher) -
Declaration
Swift
public var description: String { get } -
Declaration
Swift
public var debugDescription: String { get } -
Returns a copy of the given
WeightedDiewith separate memory.Declaration
Swift
@available(*, deprecated, message: "CustomDie is now a struct; copying is not necessary") func copy() -> WeightedDieReturn Value
A copy of the given
WeightedDie, with the same number of sides, at a different memory location.
View on GitHub
WeightedDie Structure Reference