Module: RandomLogic
- Defined in:
- lib/random_logic.rb,
lib/random_logic/version.rb
Constant Summary collapse
- VERSION =
"0.1.0"
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.
- .name ⇒ Object
-
.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
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 |
.multiply ⇒ Object
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_inverse ⇒ Object
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 |
.name ⇒ Object
5 6 7 |
# File 'lib/random_logic.rb', line 5 def self.name "RandomLogin" end |
.normal ⇒ Object
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_rand ⇒ Object
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 |
.sqrt ⇒ Object
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_inverse ⇒ Object
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 |
.square ⇒ Object
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_inverse ⇒ Object
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 |