Sha256: a93ffcdce29df26dd0060fb6236cf12d81b614e61f2dcd98e2b03c604d76ae28
Contents?: true
Size: 732 Bytes
Versions: 1
Compression:
Stored size: 732 Bytes
Contents
require "stig/generators/character" module Stig module Generators module String extend self # Public: Generates a random String. Characters are picked from a # character set (`set`). Size is variable, use a Range with equal start # and end for a fixed size. # # set - An Array of one character Strings (default: ASCII). # size - A maximum length Integer or Range (default: 25). # # Returns a String. def random(set = Character::ASCII, size = 25) result = "" rand(size).times do char = set.sample || raise(ArgumentError, "character set is empty") result << char end result end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
stig-0.1.0 | lib/stig/generators/string.rb |