Module: RandomLogic
- Defined in:
- lib/random_logic.rb,
lib/random_logic/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.add ⇒ Object
Random number of addition Bias the value in the center.
-
.inverse(value) ⇒ Object
Inverse value.
-
.multiply ⇒ Object
Random number of multiplication Bias the value near 0.
-
.multiply_inverse ⇒ Object
Inversion of random number of multiplication Bias the value near 1.
-
.normal ⇒ Object
Normal random number.
-
.normal_rand ⇒ Object
Normal random with re-try logic when the random value was lower than 0 or higher than 1.
-
.sqrt ⇒ Object
Random number of square root Increase linearly frequency of occurrence from 0.0 to 1.0.
-
.sqrt_inverse ⇒ Object
Inversion of random number of square root Increase linearly frequency of occurrence from 1.0 to 0.0.
-
.square ⇒ Object
The square of the random number Further increasing the proportion of the value near 0.
-
.square_inverse ⇒ Object
Inversion of the square of the random number Further increasing the proportion of the value near 1.
Class Method Details
.add ⇒ Object
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 |
.multiply ⇒ Object
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_inverse ⇒ Object
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 |
.normal ⇒ Object
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_rand ⇒ Object
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 |
.sqrt ⇒ Object
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_inverse ⇒ Object
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 |
.square ⇒ Object
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_inverse ⇒ Object
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 |