Class: GSLng::RNG Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/gslng/rng/rng.rb,
lib/gslng/rng/uniform.rb,
lib/gslng/rng/gaussian.rb

Overview

This class is abstract.

You should use any of the descendant classes which implement the #sample method.

Random Number Generator class

Direct Known Subclasses

Gaussian, Uniform

Defined Under Namespace

Classes: Gaussian, Uniform

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(generator_type = nil) ⇒ RNG

Create a Generator of the given type

Parameters:

  • generator_type (Symbol) (defaults to: nil)

    the algorithm to use (without the gsl_rng prefix). Default is :mt19937.

See Also:


8
9
10
11
12
13
14
# File 'lib/gslng/rng/rng.rb', line 8

def initialize(generator_type = nil)
  @type = generator_type
  if (@type.nil?) then @type = :mt19937 end # update comment above if changed
  
  type = GSLng.backend.send(:"gsl_rng_#{@type}")
  @ptr = FFI::AutoPointer.new(GSLng.backend.gsl_rng_alloc(type), RNG.method(:release))
end

Class Method Details

.release(ptr) ⇒ Object


16
17
18
# File 'lib/gslng/rng/rng.rb', line 16

def self.release(ptr)
  GSLng.backend.gsl_rng_free(ptr)
end

Instance Method Details

#initialize_copyObject


20
21
22
23
# File 'lib/gslng/rng/rng.rb', line 20

def initialize_copy
  type = GSLng.backend.send(:"gsl_rng_#{@type}")
  @ptr = FFI::AutoPointer.new(GSLng.backend.gsl_rng_alloc(type), RNG.method(:release))
end