Class: ERV::RNG
Class Method Summary collapse
Class Method Details
.make_rng(seed = nil) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/erv/rng.rb', line 12 def self.make_rng(seed = nil) # if not explicitly provided, seed is taken from the (lower quality) # pseudo-random Kernel::rand generator if RUBY_PLATFORM == 'java' # this is a somewhat ugly workaround in order to avoid ambibuities in # the constructor method that will be called (we basically explicit the # signature of the constructor that we want to use) constructor = org.apache.commons.math3.random.MersenneTwister.java_class.constructor(Java::long) rng = constructor.new_instance(seed || Kernel::rand(2**31 - 1)) else rng = seed ? GSL::Rng.alloc(GSL::Rng::MT19937, seed) : GSL::Rng.alloc(GSL::Rng::MT19937, Kernel::rand(2**31 - 1)) end end |