summaryrefslogtreecommitdiff
path: root/lib/random
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2023-08-29 10:56:56 +0900
committerNobuyoshi Nakada <[email protected]>2023-08-29 10:56:56 +0900
commit7e5c662a6f2e8435f8103bc16185bed6759cc557 ()
treec8e6fb7cbc431e59400cf6f9200a335462b4ce88 /lib/random
parentc4fc9477aa5f77a69a40b619b7144f2b118b772e (diff)
[Feature #18183] Add `chars:` option to `Random#alphanumeric`
-rw-r--r--lib/random/formatter.rb13
1 files changed, 10 insertions, 3 deletions
@@ -226,11 +226,13 @@ module Random::Formatter
#
# 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.
#
# require 'random/formatter'
#
@@ -238,8 +240,13 @@ module Random::Formatter
# # or
# prng = Random.new
# prng.alphanumeric(10) #=> "i6K93NdqiH"
- def alphanumeric(n=nil)
n = 16 if n.nil?
- choose(ALPHANUMERIC, n)
end
end