fraction_life 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fraction_life.rb +26 -9
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dce779fb4cb6c85054b8c6c26de44f5c3ff46693
|
4
|
+
data.tar.gz: 0b1c2de15443fcaa3016d233aee8c9f4b70a0a6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 073a63f13d6ec8e0227166f0ee95bc540593e8de5269f5d4561b830b9d0f78fecd0748ca5770f7ba9458b877bd4a3f606ba655f679a74ee99bce31cb75456cac
|
7
|
+
data.tar.gz: ac9fe2c17eff8020aebd47fe599ccbd1d841a4d3a380a533b48de0cd494bd3cfdb7e3b7217d5d2afda180b33f23a5f19d37dea65d5afa163e4cbca58b9b78e25
|
data/lib/fraction_life.rb
CHANGED
@@ -1,10 +1,30 @@
|
|
1
|
-
|
2
|
-
# FractionLife
|
3
|
-
#
|
1
|
+
##
|
2
|
+
# FractionLife module is a weighted randomizer that returns a single integer.
|
3
|
+
# The randomizer is called with the <tt>generate</tt> method:
|
4
|
+
#
|
5
|
+
# FractionLife.generate()
|
6
|
+
#
|
7
|
+
# Half the time that call returns 1. Of the other half of the time, half the
|
8
|
+
# time it returns 2. Of the other half of *that* time, half the time it returns
|
9
|
+
# 3, etc. So the chances of any given integer n being returned is .5 ^ n.
|
10
|
+
|
4
11
|
module FractionLife
|
12
|
+
|
13
|
+
##
|
14
|
+
# <tt>generate</tt> is FractionLife's only method. It returns a random
|
15
|
+
# integer as described above.
|
16
|
+
#
|
17
|
+
# If the <tt>odds</tt> param is given, that value is used to indicate the
|
18
|
+
# probability of each iteration returning a value. So, for example, this
|
19
|
+
# call:
|
20
|
+
#
|
21
|
+
# FractionLife.generate(0.75)
|
22
|
+
#
|
23
|
+
# has a .75 chance of returning 1.
|
24
|
+
#
|
25
|
+
# The <tt>start</tt> param indicates what integer to start at.
|
26
|
+
|
5
27
|
def self.generate(odds=0.5, start=1)
|
6
|
-
# $tm.hrm
|
7
|
-
|
8
28
|
# check random value
|
9
29
|
if rand() <= odds
|
10
30
|
return start
|
@@ -12,7 +32,4 @@ module FractionLife
|
|
12
32
|
return self.generate(odds, start+1)
|
13
33
|
end
|
14
34
|
end
|
15
|
-
end
|
16
|
-
#
|
17
|
-
# FractionLife
|
18
|
-
#---------------------------------------------------------------------------
|
35
|
+
end
|