Generate Unique Random String With Letters And Numbers In Lower Case

前端 未结 11 2078
感情败类
感情败类 2020-12-23 09:45

How can I fix this code so it generates unique random letters and numbers in lower case?

api_string = (0...32).map{65.+(rand(25)).chr}.join    
11条回答
  •  渐次进展
    2020-12-23 10:26

    CHARS = (?0..?9).to_a + (?a..?z).to_a
    api_string = 32.times.inject("") {|s, i| s << CHARS[rand(CHARS.size)]}
    

提交回复
热议问题