Class: Budik::Rng

Inherits:
Object
  • Object
show all
Defined in:
lib/budik/rng.rb

Overview

‘Rng’ class provides various methods for random number generation.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRng

Loads RNG options including method.



14
15
16
17
# File 'lib/budik/rng.rb', line 14

def initialize
  @options = Config.instance.options['rng']
  @method = @options['method']
end

Instance Attribute Details

#methodObject

Gets RNG options and method.



20
21
22
# File 'lib/budik/rng.rb', line 20

def method
  @method
end

#optionsObject

Gets RNG options and method.



20
21
22
# File 'lib/budik/rng.rb', line 20

def options
  @options
end

Instance Method Details

#generate(items) ⇒ Object

Generates random number.

  • Args:

    • items -> Total number of items (Fixnum).

  • Returns:

    • Fixnum (0…items)



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/budik/rng.rb', line 29

def generate(items)
  case @method
  when 'hwrng'
    hwrng(@options['hwrng'], items)
  when 'random.org'
    random_org(@options['random.org'], items)
  when 'rand-hwrng-seed'
    swrng(items, hwrng(@options['hwrng'], 2**64))
  else
    swrng(items)
  end
end