Module: Xoroshiro

Defined in:
lib/xoroshiro.rb,
lib/xoroshiro/version.rb,
ext/xoroshiro/xoroshiro.c

Overview

The Xoroshiro256** pseudo-random number generator implemented as a Ruby C extension. For more information about the Xoroshiro family of generators see prng.di.unimi.it

Defined Under Namespace

Classes: Error, Random

Constant Summary collapse

BITMASK64 =
(1 << 64) - 1
CLASS_RAND =
Xoroshiro::Random.new
VERSION =
'0.2.1'

Class Method Summary collapse

Class Method Details

.gen_seed_state(seed) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/xoroshiro.rb', line 21

def self.gen_seed_state(seed)
  if seed.nil?
    # seed values from entropy via SecureRandom
    Array.new(4) { SecureRandom.hex(8).to_i(16) }
  else
    # seed values by sha26 digest of provided value
    digest = OpenSSL::Digest.hexdigest('sha256', seed.to_s).to_i(16)
    Array.new(4) { |i| (digest >> (i * 64)) & BITMASK64 }
  end
end

.rand(range = nil) ⇒ Object

Module-level rand method which can be used as a drop-in replacement for Kernel::rand.

Arguments

@param range [nil, Range, Numeric] as described in the Xoroshiro::Random.rand instance method.

Returns:

  • a random value corresponding to the range specification.



101
102
103
# File 'lib/xoroshiro.rb', line 101

def self.rand(range = nil)
  CLASS_RAND.rand(range)
end