Module: Gem::SecureRandom

Extended by:
Random::Formatter
Defined in:
lib/rubygems/vendor/securerandom/lib/securerandom.rb

Overview

Secure random number generator interface.

This library is an interface to secure random number generators which are suitable for generating session keys in HTTP cookies, etc.

You can use this library in your application by requiring it:

require 'rubygems/vendor/securerandom/lib/securerandom'

It supports the following secure random number generators:

  • openssl

  • /dev/urandom

  • Win32

Gem::SecureRandom is extended by the Gem::Random::Formatter module which defines the following methods:

  • alphanumeric

  • base64

  • choose

  • gen_random

  • hex

  • rand

  • random_bytes

  • random_number

  • urlsafe_base64

  • uuid

These methods are usable as class methods of Gem::SecureRandom such as Gem::SecureRandom.hex.

If a secure random number generator is not available, NotImplementedError is raised.

Constant Summary collapse

VERSION =

The version

"0.3.1"

Constants included from Random::Formatter

Random::Formatter::ALPHANUMERIC

Class Method Summary collapse

Methods included from Random::Formatter

alphanumeric, base64, hex, random_bytes, urlsafe_base64, uuid, uuid_v7

Class Method Details

.bytes(n) ⇒ Object

Returns a random binary string containing size bytes.

See Random.bytes



50
51
52
# File 'lib/rubygems/vendor/securerandom/lib/securerandom.rb', line 50

def bytes(n)
  return gen_random(n)
end