diff --git a/.document b/.document new file mode 100644 index 0000000..48aceb6 --- /dev/null +++ b/.document @@ -0,0 +1,4 @@ +LICENSE.txt +README.md +docs/ +lib/ diff --git a/docs/random.rb b/docs/random.rb new file mode 100644 index 0000000..5b7f5dd --- /dev/null +++ b/docs/random.rb @@ -0,0 +1,10 @@ +# This file is only for RDoc + +# Random provides an interface to Ruby's pseudo-random number generator, or +# PRNG. +# +# See also Random::Formatter module that adds convenience methods to generate +# various forms of random data. + +class Random +end diff --git a/lib/random/formatter.rb b/lib/random/formatter.rb index e7ee4db..befa1d0 100644 --- a/lib/random/formatter.rb +++ b/lib/random/formatter.rb @@ -292,6 +292,7 @@ def uuid_v7(extra_timestamp_bits: 0) end end + # Internal interface to Random; Generate random data _n_ bytes. private def gen_random(n) self.bytes(n) end @@ -339,7 +340,9 @@ def uuid_v7(extra_timestamp_bits: 0) result end + # The default character list for #alphanumeric. ALPHANUMERIC = [*'A'..'Z', *'a'..'z', *'0'..'9'] + # Generate a random alphanumeric string. # # The argument _n_ specifies the length, in characters, of the alphanumeric diff --git a/lib/securerandom.rb b/lib/securerandom.rb index 9afd8a0..43732a6 100644 --- a/lib/securerandom.rb +++ b/lib/securerandom.rb @@ -40,19 +40,27 @@ module SecureRandom + # The version VERSION = "0.3.0" class << self + # Returns a random binary string containing +size+ bytes. + # + # See Random.bytes def bytes(n) return gen_random(n) end private + # :stopdoc: + + # Implementation using OpenSSL def gen_random_openssl(n) return OpenSSL::Random.random_bytes(n) end + # Implementation using system random device def gen_random_urandom(n) ret = Random.urandom(n) unless ret @@ -78,6 +86,9 @@ def gen_random_urandom(n) end end + # :startdoc: + + # Generate random data bytes for Random::Formatter public :gen_random end end