Skip to content

Instantly share code, notes, and snippets.

@WrathChaos
Last active March 3, 2020 07:47
Show Gist options
  • Save WrathChaos/0c1cf35065b3b9730f8d7376dc6ac65a to your computer and use it in GitHub Desktop.
Save WrathChaos/0c1cf35065b3b9730f8d7376dc6ac65a to your computer and use it in GitHub Desktop.
var fourDigitNumber: String {
 var result = ""
 repeat {
     // Create a string with a random number 0...9999
     result = String(format:"%04d", arc4random_uniform(10000) )
 } while Set<Character>(result.characters).count < 4
 return result
}

// USAGE       
let password = fourDigitNumber
print("Generated Password : \(password)")
@kosratdev
Copy link

Set<Character>(result.characters).count is deprecated use result.count

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment