How can I generate an n-character pseudo random string containing only A-Z
, 0-9
like SecureRandom.base64 without "+"
, "/"
, and "="
? For example:
(0..n).map {(('1'..'9').to_a + ('A'..'Z').to_a)[rand(36)]}.join
Answer
Array.new(n){[*"A".."Z", *"0".."9"].sample}.join
No comments:
Post a Comment