Module: RandomLogic

Defined in:
lib/random_logic.rb,
lib/random_logic/version.rb

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.addObject

Random number of addition Bias the value in the center



12
13
14
# File 'lib/random_logic.rb', line 12

def self.add
  rand + rand / 2
end

.inverse(value) ⇒ Object

Inverse value



6
7
8
# File 'lib/random_logic.rb', line 6

def self.inverse(value)
  1.0 - value
end

.multiplyObject

Random number of multiplication Bias the value near 0



18
19
20
# File 'lib/random_logic.rb', line 18

def self.multiply
  rand * rand
end

.multiply_inverseObject

Inversion of random number of multiplication Bias the value near 1



24
25
26
# File 'lib/random_logic.rb', line 24

def self.multiply_inverse
  inverse(rand * rand)
end

.normalObject

Normal random number



54
55
56
57
# File 'lib/random_logic.rb', line 54

def self.normal
  value = Math.sqrt(-2.0 * Math.log(rand)) * Math.sin(2.0 * Math::PI * rand)
  (value + 3) / 6
end

.normal_randObject

Normal random with re-try logic when the random value was lower than 0 or higher than 1



60
61
62
63
64
65
# File 'lib/random_logic.rb', line 60

def self.normal_rand
  while (true) do
    value = normal
    return value if (0 <= value && value < 1)
  end
end

.sqrtObject

Random number of square root Increase linearly frequency of occurrence from 0.0 to 1.0.



43
44
45
# File 'lib/random_logic.rb', line 43

def self.sqrt
  Math.sqrt rand
end

.sqrt_inverseObject

Inversion of random number of square root Increase linearly frequency of occurrence from 1.0 to 0.0.



49
50
51
# File 'lib/random_logic.rb', line 49

def self.sqrt_inverse
  inverse(sqrt)
end

.squareObject

The square of the random number Further increasing the proportion of the value near 0



30
31
32
33
# File 'lib/random_logic.rb', line 30

def self.square
  r = rand * rand
  r * r
end

.square_inverseObject

Inversion of the square of the random number Further increasing the proportion of the value near 1



37
38
39
# File 'lib/random_logic.rb', line 37

def self.square_inverse
  inverse(square)
end