Issue #10849 has been updated by Nobuyoshi Nakada.
> The length of the result string is about 4/3 of _n_.
I don't like this interface.
~~~ruby
def self.choose(source, length)
size = source.size
length.times.map {source[random_number(size)]}.join('')
end
GRAPH = [*'!'..'~']
def self.graph(length)
choose(GRAPH, length)
end
ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9']
# SecureRandom.alphanumeric generates a random alphanumeric string.
#
# The argument _n_ specifies the length of the random number to be
# generated.
#
# The result may contain A-Z, a-z and 0-9.
#
# p SecureRandom.alphanumeric #=> "2BuBuLf3WfSKyQbRccA"
# p SecureRandom.alphanumeric #=> "6BbW0pxO0YENxn38HMUbcQ"
#
# If a secure random number generator is not available,
# +NotImplementedError+ is raised.
def self.alphanumeric(length)
choose(ALPHANUMERIC, length)
end
~~~
----------------------------------------
Feature #10849: Adding an alphanumeric function to SecureRandom
https://bugs.ruby-lang.org/issues/10849#change-51482