PercentageValue

public class PercentageValue : RandomValue

A value generator class for random percentage values.

  • Returns a random Double between 0.0 and 1.0 with no limitations on decimal places on the output.

    Example:

        // Usage
        let randomPercent = Random.percentage.value
    
        // internally, if the initial random value was
        0.59483093929
        // the output would be the same
    
        print(randomPercent) // 0.59483093929
    

    Declaration

    Swift

    public var value: Double { get }

    Return Value

    Double between 0.0 and 1.0

  • Returns a random Double between 0.0 and 1.0 rounded to the number of maximum decimal places.

    Example:

        // Usage
        let randomPercent = Random.percentage.value(maxDecimalPlaces: 4)
    
        // internally, if the initial random value was
        0.59483093929
        // the output would be:
        0.5948
    
        print(randomPercent) // 0.5948
    

    Note

    If no value is specified for maxDecimalPlaces the default value of 10 will be used

    Declaration

    Swift

    public func value(roundedTo maxDecimalPlaces: Int) -> Double

    Parameters

    maxDecimalPlaces

    an Int specifying how many decimal places to limit the returned value by.

    Return Value

    Double between 0.0 and 1.0

  • Dynamically returns a random Double value below the upper limit in Range.

    Note

    Note:

    • If a randomly generated value exceeds the upper,range.max is returned.

    Declaration

    Swift

    public func withUpperLimit(of range: PercentageRange, maxDecimalPlaces: Int?) -> Double

    Parameters

    range

    a PercentageRange configuration that defines the min and max range of the return value.

    maxDecimalPlaces

    an optional configuration that limits the return value to the number of max places specified.

    Return Value

    Double representing a random value between 0.0 and range.max

  • A computed variable that returns random Double value between 0.0 and 1.0, respecting upper and lower percentage bound configuration.

    Precondition

    Random.percentageRange must be set

    Note

    Note:

    Rules:

    Warning

    If a value is not set withRandom.percentageRange = newValue, before using this computed property, then 0.0 will be returned.

    Declaration

    Swift

    public var withUpperLimit: Double { get }

    Return Value

    Double representing a random value within the configured range, or nil if a range is not configured.

  • Dynamically returns a random Double value between 0 and 1 by PercentageRange provided.

    Note

    Note:

    Declaration

    Swift

    public func withinRange(_ range: PercentageRange) -> Double

    Parameters

    range

    a PercentageRange configuration that defines the min and max of the range

    Return Value

    Double representing a random value between min and max of Range

  • Dynamically returns a random Double value between 0.0 and 1.0 by PercentageRange provided, and if configured, limited to the specified number of decminal places.

    Note

    Note:

    • If a randomly generated value exceeds the max,PercentageRange.max is returned.

    • If a randomly generated value is less than the min, PercentageRange.min is returned.

    • If no maxDecimalPlaces are provided, no limitation will be applied to the return value.

    Declaration

    Swift

    public func withinRange(_ range: PercentageRange, maxDecimalPlaces: Int?) -> Double

    Parameters

    range

    a PercentageRange configuration that defines the min and max of the range

    maxDecimalPlaces

    an optional configuration that limits the return value to the number of max places specified.

    Return Value

    Double representing a random value between min and max of Range

  • A computed variable that returns random Double value between 0 and 1, respecting upper and lower percentage bound configuration.

    Precondition

    Random.percentageRange must be set

    Note

    Note:

    Rules:

    Warning

    If a value is not set withRandom.percentageRange, 0.0 will be returned.

    Declaration

    Swift

    public var withinRange: Double { get }

    Return Value

    Double representing a random value within the configured range, or nil if a range is not configured.