Class: Distem::Events::RngStreamRandomGenerator

Inherits:
RandomGenerator show all
Defined in:
lib/distem/events/rngstreamrandomgenerator.rb

Instance Method Summary (collapse)

Constructor Details

- (RngStreamRandomGenerator) initialize(seed = nil)

Class which use a RngStream to generate random numbers Better from a statistical point of view, because each stream is independant. This can't be the case with the rand function, because there is only one stream.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/distem/events/rngstreamrandomgenerator.rb', line 10

def initialize(seed = nil)
  @stream = RandomExtension::RngStream.new
  if seed
    if seed.is_a?(Array)
      raise "Invalid seed array size, must be >= 6" if seed.length < 6
      @stream.set_seed(seed)
    elsif seed.is_a?(Numeric)
      seed_array = [ seed, seed, seed, seed, seed, seed]
      @stream.set_seed(seed_array)
    else
      raise "Invalid seed type"
    end
  end
end

Instance Method Details

- (Object) advance_state(displacement)



29
30
31
32
# File 'lib/distem/events/rngstreamrandomgenerator.rb', line 29

def advance_state(displacement)
  @stream.advance_state(displacement)
  return self
end

- (Object) rand_U01



25
26
27
# File 'lib/distem/events/rngstreamrandomgenerator.rb', line 25

def rand_U01
  return @stream.randU01
end