Class: Mext::RandomGenerator

Inherits:
Object
  • Object
show all
Defined in:
lib/mext/random_generator.rb

Overview

Mext::RandomGenerator

singleton seedable version of the default Random Generator

Constant Summary collapse

MEXT_SEED_TAG =
'MEXT_SEED'

Instance Method Summary collapse

Constructor Details

#initializeRandomGenerator

Returns a new instance of RandomGenerator.



14
15
16
17
# File 'lib/mext/random_generator.rb', line 14

def initialize
  @mext_seed = ENV[MEXT_SEED_TAG] ? ENV[MEXT_SEED_TAG] : (ENV[MEXT_SEED_TAG] = (rand()*10e20).to_i.to_s)
  self.seed = @mext_seed
end

Instance Method Details

#rObject



27
28
29
# File 'lib/mext/random_generator.rb', line 27

def r
  Math.send(:rand)
end

#seedObject



19
20
21
# File 'lib/mext/random_generator.rb', line 19

def seed
  @mext_seed.to_i
end

#seed=(val) ⇒ Object



23
24
25
# File 'lib/mext/random_generator.rb', line 23

def seed=(val)
  Math.send(:srand, val.to_i)
end