生成指定长度的随机字符串
作者:
古月思吉 | 来源:发表于
2018-11-12 17:02 被阅读0次extension String{
static let random_str_characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
static func randomStr(len : Int) -> String{
var ranStr = ""
for _ in 0..<len {
let index = Int(arc4random_uniform(UInt32(random_str_characters.count)))
ranStr.append(random_str_characters[random_str_characters.index(random_str_characters.startIndex, offsetBy: index)])
}
return ranStr
}
}
本文标题:生成指定长度的随机字符串
本文链接:https://www.haomeiwen.com/subject/emmcfqtx.html
网友评论