IntValue

public class IntValue : RandomValue

A value generator class for random int values.

  • Returns a random Int using arc4random

    Declaration

    Swift

    public var value: Int { get }
  • Dynamically returns a random Int value below the upper limit in Range.

    Note

    Note:

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

    Declaration

    Swift

    public func withUpperLimit(of range: IntRange) -> Int

    Parameters

    range

    a IntRange configuration that defines the upper and lower limits of the range (only upper is used in this method)/

    Return Value

    Int representing a random value between 0 and Range.upper

  • 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 withUpperLimit: Int { get }

    Return Value

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

  • Dynamically returns a random Int value between Range.upper and Range.lower.

    Note

    Note:

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

    • If a randomly generated value is less than the lower, IntRange.lower is returned.

    • The returned value is exclusive of the upper value, meaning if an upper value is 4, for example, the maximum possible value returned would be 3.

    • The returned value is inclusive of the lower value, meaning, if a lower value is 1, for example, it is possible that the returned value could be 1.

    Example:

            // usage
            let range = IntRange(lower: 1, upper: 50)
            let randomInt = Random.int.withinRange(range) // an Int > 1 and < 50 (49 max).
    

    Declaration

    Swift

    public func withinRange(_ range: IntRange) -> Int

    Parameters

    range

    a IntRange configuration that defines the upper and lower bounds of the range.

    Return Value

    Int representing a random value between Range.lower and Range.upper.

  • 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.

    Example:

            // usage
            let randomInt = Random.int.withinRange
    

    Declaration

    Swift

    public var withinRange: Int { get }

    Return Value

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