Sample code for 30+ languages & platforms
Swift

Generating Random Integer in Range

See more PRNG Examples

Demonstrates how to generate random integers in a specified range.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var success: Bool = false

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    success = false

    let fortuna = CkoPrng()!

    // Generate random integers between 12 and 24 inclusive
    var i: Int
    for i = 0; i <= 100; i++ {
        print("\(fortuna.randomInt(low: 12, high: 24).intValue)")
    }


}