module Bundler::Random::Formatter

def urlsafe_base64(n=nil, padding=false)

See RFC 3548 for the definition of URL-safe base64.

prng.urlsafe_base64(nil, true) #=> "-M8rLhr7JEpJlqFGUMmOxg=="
prng.urlsafe_base64(nil, true) #=> "i0XQ-7gglIsHGV2_BNPrdQ=="

prng.urlsafe_base64 #=> "UZLdOkzop70Ddx-IJR0ABg"
prng = Random.new
# or
Random.urlsafe_base64 #=> "b4GOKm4pOYU_-BOXcrUGDg"

require 'bundler/vendor/securerandom/lib/random/formatter'

"=" is also used if _padding_ is true.
The result may contain A-Z, a-z, 0-9, "-" and "_".

By default, padding is not generated because "=" may be used as a URL delimiter.
Otherwise padding is generated.
If it is false or nil, padding is not generated.
The boolean argument _padding_ specifies the padding.

It may be larger in the future.
If _n_ is not specified or is nil, 16 is assumed.

to be generated. The length of the result string is about 4/3 of _n_.
The argument _n_ specifies the length, in bytes, of the random number

Generate a random URL-safe base64 string.
def urlsafe_base64(n=nil, padding=false)
  s = [random_bytes(n)].pack("m0")
  s.tr!("+/", "-_")
  s.delete!("=") unless padding
  s
end