IntValue
public class IntValue : RandomValue
A value generator class for random int values.
-
Returns a random Int using
arc4randomDeclaration
Swift
public var value: Int { get } -
Dynamically returns a random
Intvalue below the upper limit inRange.Note
Note:
If a randomly generated value exceeds the upper,
range.upperis returned.
Declaration
Swift
public func withUpperLimit(of range: IntRange) -> IntParameters
rangea
IntRangeconfiguration that defines the upper and lower limits of the range (only upper is used in this method)/Return Value
Intrepresenting a random value between 0 andRange.upper -
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 withUpperLimit: Int { 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
Intvalue betweenRange.upperandRange.lower.Note
Note:
If a randomly generated value exceeds the upper,
IntRange.upperis returned.If a randomly generated value is less than the lower,
IntRange.loweris 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) -> IntParameters
rangea
IntRangeconfiguration that defines the upper and lower bounds of the range.Return Value
Intrepresenting a random value betweenRange.lowerandRange.upper. -
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.Example:
// usage let randomInt = Random.int.withinRangeDeclaration
Swift
public var withinRange: Int { 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,
IntValue Class Reference