bogdan barbulescu bogdan barbulescu - 1 year ago 101
Swift Question

Generate number of 9 digits in Swift

How can I generate a 9 digits number in Swift.
I have tried random() function, but the size of the generated number is different every time the function is called.
I have also tried this code enter link description here , but it is deprecated.

Answer Source
import Foundation

func random9DigitString() -> String {
    let min: UInt32 = 100_000_000
    let max: UInt32 = 999_999_999
    let i = min + arc4random_uniform(max - min + 1)
    return String(i)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download