Class: Mext::RandomGenerator
- Inherits:
-
Object
- Object
- Mext::RandomGenerator
- 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
-
#initialize ⇒ RandomGenerator
constructor
A new instance of RandomGenerator.
- #r ⇒ Object
- #seed ⇒ Object
- #seed=(val) ⇒ Object
Constructor Details
#initialize ⇒ RandomGenerator
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
#r ⇒ Object
27 28 29 |
# File 'lib/mext/random_generator.rb', line 27 def r Math.send(:rand) end |
#seed ⇒ Object
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 |