Skip to content

Commit

Permalink
Merge pull request #24 from nobu/doc
Browse files Browse the repository at this point in the history
Add missing documents
  • Loading branch information
nobu authored Dec 12, 2023
2 parents 156cbb8 + ddf2672 commit 4421014
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .document
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LICENSE.txt
README.md
docs/
lib/
10 changes: 10 additions & 0 deletions docs/random.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions lib/random/formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions lib/securerandom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -78,6 +86,9 @@ def gen_random_urandom(n)
end
end

# :startdoc:

# Generate random data bytes for Random::Formatter
public :gen_random
end
end
Expand Down

0 comments on commit 4421014

Please sign in to comment.