Class AppMath::Ran
In: random.rb
Parent: Object

Class of random generators. The real numbers delivered by different random generators are intended to be statistically independent. Each random generator has its own interval within which the output values are uniformly distributed.

Methods

local_seed   new   ran  

Attributes

iv  [R] 

Public Class methods

The arguments have to determine an interval in which the random values lie. This is named @iv. If there is no argument we have @iv = [0,1]. If there is one argument, it has to be an instance of Iv and then becomes @iv. If there are two arguments they need to be convertible to R and then become the boundaries of @iv.

[Source]

    # File random.rb, line 35
35:   def initialize(*arg)
36:     n = arg.size
37:     case n
38:     when 0
39:       @iv = Iv.new(0,1)
40:     when 1
41:       a0 = arg[0]
42:       fail "argument must be an Iv" unless a0.class == Iv
43:       @iv = a0
44:     when 2
45:       a0 = arg[0]; a1 = arg[1]
46:       @iv = Iv.new(a0,a1)
47:     else
48:       fail "0,1,or 2 arguments needed, not #{n}"
49:     end
50:     x = R.ran(@@seed)
51:     i = (@@swing * x).to_i
52:     @local_seed = i
53:     @@seed += 1
54:   end

Public Instance methods

Returns the local seed for control purposes. Should not be needed.

[Source]

    # File random.rb, line 66
66:   def local_seed
67:     @local_seed
68:   end

Returns a point (value) from interval @iv by ‘random selection’. The underlying mechanism is the sine-floor generator defined in method R.ran.

[Source]

    # File random.rb, line 59
59:   def ran
60:     p = R.ran(@local_seed)
61:     @local_seed += 1
62:     @iv.put(p)
63:   end

[Validate]