Answers for "create randstring in swift"

1

random string swift

func randomString(of length: Int) -> String {
    let letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
    var s = ""
    for _ in 0 ..< length {
        s.append(letters.randomElement()!)
    }
    return s
}
Posted by: Guest on June-13-2020
3

random number swift

let randInt = Int.random(in: 0...100)

// The range can be a closed (a...b) or half open (a..<b) range.
Posted by: Guest on June-16-2020

Code answers related to "Swift"

Browse Popular Code Answers by Language