PercentageValue
public class PercentageValue : RandomValue
A value generator class for random percentage values.
-
Returns a random
Doublebetween 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.59483093929Declaration
Swift
public var value: Double { get }Return Value
Doublebetween 0.0 and 1.0 -
Returns a random
Doublebetween 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.5948Note
If no value is specified formaxDecimalPlacesthe default value of10will be usedDeclaration
Swift
public func value(roundedTo maxDecimalPlaces: Int) -> DoubleParameters
maxDecimalPlacesan
Intspecifying how many decimal places to limit the returned value by.Return Value
Doublebetween 0.0 and 1.0 -
Dynamically returns a random
Doublevalue below the upper limit inRange.Note
Note:
If a randomly generated value exceeds the upper,
range.maxis returned.
Declaration
Swift
public func withUpperLimit(of range: PercentageRange, maxDecimalPlaces: Int?) -> DoubleParameters
rangea
PercentageRangeconfiguration that defines the min and max range of the return value.maxDecimalPlacesan optional configuration that limits the return value to the number of max places specified.
Return Value
Doublerepresenting a random value between 0.0 andrange.max -
A computed variable that returns random
Doublevalue between 0.0 and 1.0, respecting upper and lower percentage bound configuration.Precondition
Random.percentageRangemust be setNote
Note:
Rules:
- If a randomly generated value exceeds the max,
PercentageRange.maxis returned. - If a randomly generated value is less than the min,
PercentageRange.minis returned.
Warning
If a value is not set with
Random.percentageRange = newValue, before using this computed property, then 0.0 will be returned.Declaration
Swift
public var withUpperLimit: Double { get }Return Value
Doublerepresenting a random value within the configured range, ornilif a range is not configured. - If a randomly generated value exceeds the max,
-
Dynamically returns a random Double value between 0 and 1 by
PercentageRangeprovided.Note
Note:
If a randomly generated value exceeds the max,
PercentageRange.maxis returned.If a randomly generated value is less than the min,
PercentageRange.minis returned.
Declaration
Swift
public func withinRange(_ range: PercentageRange) -> DoubleParameters
rangea
PercentageRangeconfiguration that defines the min and max of the rangeReturn Value
Doublerepresenting a random value between min and max ofRange -
Dynamically returns a random Double value between 0.0 and 1.0 by
PercentageRangeprovided, and if configured, limited to the specified number of decminal places.Note
Note:
If a randomly generated value exceeds the max,
PercentageRange.maxis returned.If a randomly generated value is less than the min,
PercentageRange.minis returned.If no maxDecimalPlaces are provided, no limitation will be applied to the return value.
Declaration
Swift
public func withinRange(_ range: PercentageRange, maxDecimalPlaces: Int?) -> DoubleParameters
rangea
PercentageRangeconfiguration that defines the min and max of the rangemaxDecimalPlacesan optional configuration that limits the return value to the number of max places specified.
Return Value
Doublerepresenting a random value between min and max ofRange -
A computed variable that returns random Double value between 0 and 1, respecting upper and lower percentage bound configuration.
Precondition
Random.percentageRangemust be setNote
Note:
Rules:
- If a randomly generated value exceeds the max,
PercentageRange.maxis returned. - If a randomly generated value is less than the min,
PercentageRange.minis returned.
Warning
If a value is not set with
Random.percentageRange, 0.0 will be returned.Declaration
Swift
public var withinRange: Double { get }Return Value
Doublerepresenting a random value within the configured range, ornilif a range is not configured. - If a randomly generated value exceeds the max,
PercentageValue Class Reference