###CODE1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27// Playground - noun: a place where people can play
import UIKit
//Step 1.
var pwCharacters = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","1","2","3","4","5","6","7","8","9","0","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","!","@","#","$","%","^","&","*"]
//Step 2.
func randomPassword(passwordLength: Int) -> String {
var password = ""
var unsignedArrayCount = UInt32(pwCharacters.count)
for var i = 0; i < passwordLength; i++ {
var unsignedRandomNumber = arc4random_uniform(unsignedArrayCount)
var randomNumber = Int(unsignedRandomNumber)
password += pwCharacters[randomNumber]
}
return password
}
//Step 3
//任意生成1000位密码
randomPassword(1000)
//任意生成15密码
var password = "\(randomPassword(5))-\(randomPassword(5))-\(randomPassword(5))"
###References
One Thousand Character Password