Method: OpenID::CryptUtil.random_string
- Defined in:
- lib/openid/cryptutil.rb
.random_string(length, chars = nil) ⇒ Object
Generate a random string of the given length, composed of the specified characters. If chars is nil, generate a string composed of characters in the range 0..255.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/openid/cryptutil.rb', line 62 def CryptUtil.random_string(length, chars=nil) s = "" unless chars.nil? length.times { s << chars[rand(chars.length)] } else length.times { s << rand(256).chr } end return s end |