Module ThreadSafe::Util::XorShiftRandom
In: lib/thread_safe/util/xor_shift_random.rb

A xorshift random number (positive +Fixnum+s) generator, provides reasonably cheap way to generate thread local random numbers without contending for the global +Kernel.rand+.

Usage:

  x = XorShiftRandom.get # uses Kernel.rand to generate an initial seed
  while true
    if (x = XorShiftRandom.xorshift).odd? # thread-localy generate a next random number
      do_something_at_random
    end
  end

Methods

get   xorshift   xorshift  

Constants

MAX_XOR_SHIFTABLE_INT = MAX_INT - 1

Public Instance methods

Generates an initial non-zero positive Fixnum via +Kernel.rand+.

using the "yˆ=y>>a; yˆ=y<<b; yˆ=y>>c;" transform with the (a,b,c) tuple with values (3,1,14) to minimise Bignum overflows

using the "yˆ=y>>a; yˆ=y<<b; yˆ=y>>c;" transform with the (a,b,c) tuple with values (1,1,54) to minimise Bignum overflows

[Validate]