Class: MultiThreadedSimpleRandom

Inherits:
SimpleRandom show all
Defined in:
lib/simple-random/multi_threaded_simple_random.rb

Class Method Summary collapse

Methods inherited from SimpleRandom

#beta, #cauchy, #chi_square, #dirichlet, #exponential, #gamma, #initialize, #inverse_gamma, #laplace, #log_normal, #normal, #set_seed, #student_t, #triangular, #uniform, #weibull

Constructor Details

This class inherits a constructor from SimpleRandom

Class Method Details

.instanceObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simple-random/multi_threaded_simple_random.rb', line 7

def instance

  unless @instances
    extend MonitorMixin

    self.synchronize do
      @instances ||= {}
    end
  end

  instance_id = Thread.current.object_id

  unless @instances[instance_id]
    self.synchronize do
      @instances[instance_id] ||= new
    end
  end

  @instances[instance_id]
end