module RandomLogic

Constants

VERSION

Public Class Methods

add() click to toggle source

Random number of addition Bias the value in the center

# File lib/random_logic.rb, line 12
def self.add
  rand + rand / 2
end
inverse(value) click to toggle source

Inverse value

# File lib/random_logic.rb, line 6
def self.inverse(value)
  1.0 - value
end
multiply() click to toggle source

Random number of multiplication Bias the value near 0

# File lib/random_logic.rb, line 18
def self.multiply
  rand * rand
end
multiply_inverse() click to toggle source

Inversion of random number of multiplication Bias the value near 1

# File lib/random_logic.rb, line 24
def self.multiply_inverse
  inverse(rand * rand)
end
normal() click to toggle source

Normal random number

# 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_rand() click to toggle source

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

# 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
sqrt() click to toggle source

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

# File lib/random_logic.rb, line 43
def self.sqrt
  Math.sqrt rand
end
sqrt_inverse() click to toggle source

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

# File lib/random_logic.rb, line 49
def self.sqrt_inverse
  inverse(sqrt)
end
square() click to toggle source

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

# File lib/random_logic.rb, line 30
def self.square
  r = rand * rand
  r * r
end
square_inverse() click to toggle source

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

# File lib/random_logic.rb, line 37
def self.square_inverse
  inverse(square)
end