Skip to content
instance method

Random::Formatter#choose

choose(source, n)

Generate a string that randomly draws from a source array of characters.

The argument source specifies the array of characters from which to generate the string. The argument n specifies the length, in characters, of the string to be generated.

The result may contain whatever characters are in the source array.

Example
require 'random/formatter'

prng.choose([*'l'..'r'], 16) #=> "lmrqpoonmmlqlron"
prng.choose([*'0'..'9'], 5)  #=> "27309"
See also #base64 #gen_random #alphanumeric #hex also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0