Class: OPE::PRNG

Inherits:
Object
  • Object
show all
Defined in:
lib/ope-rb/prng.rb

Instance Method Summary collapse

Constructor Details

#initialize(coin) ⇒ PRNG

Returns a new instance of PRNG.



8
9
10
11
12
# File 'lib/ope-rb/prng.rb', line 8

def initialize(coin)
  coin = coin.to_s
  coin += '0' while coin.bytesize < 24
  @prng = DRBG::HMAC.new(coin, 128)
end

Instance Method Details

#drawObject



14
15
16
17
# File 'lib/ope-rb/prng.rb', line 14

def draw
  n = @prng.generate(4, 128).unpack('H*')[0]
  n.byteslice(0, 8).hex.to_f / 2**32
end