Classes

The following classes are available globally.

  • A value generator class for random int values.

    See more

    Declaration

    Swift

    public class IntValue : RandomValue
  • A value generator class for random percentage values.

    See more

    Declaration

    Swift

    public class PercentageValue : RandomValue
  • A subclass for sharing utility functions between random value generator classes.

    Declaration

    Swift

    public class RandomValue
  • A random value generation utility.

    ** Configuration **

    The utility does not require any configuration to generate random values. For those, you can simply call Random.(type).value to retrieve the random value.

    However, there are many cases where a configuration for upper / lower bound, or min / max values.

    Reusable Configurations by Default

    Configuring a range sets up the shared instance to re-use that range configuration on all subsequent calls until modified.

    Example:

         // configure reusable IntRange
         let intRange = IntRange(lower: 4, upper: 100)
         Random.intRange = intRange
         // see below for Random.int usage examples.
    
         // configure reusable PercentageRange
         let pctRange = PercentageRange(min: 0.10, max: 0.98)
         Random.percentageRange = pctRange
         // see below for Random.percentage usage examples
    

    Overriding Current Configuration

    You can override the configuration at any time by setting up a new range just as above, however, you can also call any of the computed variables through an interface method and provide a new configuration dynamically.

    Examples:

    ** Random Int **

        // get random int with no limitations
        let randomInt = Random.int.value
    
        // get random int value below an upper limit
    
        // get random int value within a given range
    

    ** Random Percentage (Double) **

        // get random percentage with no limitations
        let randomPercent = Random.percentage.value
    
        // get random percentage value below an upper limit
    
        // get random percentage value within a given range
    
    See more

    Declaration

    Swift

    public class Random
  • A configuration object for random-swift.

    See more

    Declaration

    Swift

    public class RandomConfig