End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Random::Formatter#alphanumeric
alphanumeric(n=nil)
lib/random/formatter.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.1.3/lib/random/formatter.rb, line 212
def alphanumeric(n=nil)
n = 16 if n.nil?
choose(ALPHANUMERIC, n)
end
Random::Formatter#alphanumeric generates a random alphanumeric string.
The argument n specifies the length, in characters, of the alphanumeric string to be generated.
If n is not specified or is nil, 16 is assumed. It may be larger in the future.
The result may contain A-Z, a-z and 0-9.
Example
require 'random/formatter' prng.alphanumeric #=> "2BuBuLf3WfSKyQbR" prng.alphanumeric(10) #=> "i6K93NdqiH"