Module: RandomLogic

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

Constant Summary collapse

VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.addObject

Random number of addition Bias the value in the center



15
16
17
# File 'lib/random_logic.rb', line 15

def self.add
  rand + rand / 2
end

.inverse(value) ⇒ Object

Inverse value



9
10
11
# File 'lib/random_logic.rb', line 9

def self.inverse(value)
  1.0 - value
end

.multiplyObject

Random number of multiplication Bias the value near 0



21
22
23
# File 'lib/random_logic.rb', line 21

def self.multiply
  rand * rand
end

.multiply_inverseObject

Inversion of random number of multiplication Bias the value near 1



27
28
29
# File 'lib/random_logic.rb', line 27

def self.multiply_inverse
  inverse(rand * rand)
end

.nameObject



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

def self.name
  "RandomLogin"
end

.normalObject

Normal random number



57
58
59
60
# File 'lib/random_logic.rb', line 57

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



63
64
65
66
67
68
# File 'lib/random_logic.rb', line 63

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.



46
47
48
# File 'lib/random_logic.rb', line 46

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.



52
53
54
# File 'lib/random_logic.rb', line 52

def self.sqrt_inverse
  inverse(sqrt)
end

.squareObject

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



33
34
35
36
# File 'lib/random_logic.rb', line 33

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



40
41
42
# File 'lib/random_logic.rb', line 40

def self.square_inverse
  inverse(square)
end