fraction_life 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/fraction_life.rb +9 -18
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7f86fd0c0a7ba8aa4a2e88fc7f0936ca318b550
|
4
|
+
data.tar.gz: b564edca74a7dd06b7aedc56718d007d814bab02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59eea21b07f6d4a31062c1f778612e60b2361506896b6b04715f13ff3bb1f4b59d98684737d1a6c24ec756a4bdcc283631a7585752eb1a808a61480b22fb87f7
|
7
|
+
data.tar.gz: 87f9ffb6635bc74901a19cba35a49840664a7b4fb4f679d604936191f86274e4f79fda841b9bded56b37dfcc77fb75be4803bf7741c3b40bffd42bce1c3576f1
|
data/lib/fraction_life.rb
CHANGED
@@ -1,13 +1,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
|
-
|
11
1
|
module FractionLife
|
12
2
|
|
13
3
|
##
|
@@ -21,15 +11,16 @@ module FractionLife
|
|
21
11
|
# FractionLife.generate(0.75)
|
22
12
|
#
|
23
13
|
# has a .75 chance of returning 1.
|
24
|
-
#
|
25
|
-
# The <tt>start</tt> param indicates what integer to start at.
|
26
14
|
|
27
|
-
def self.generate(odds=0.5
|
15
|
+
def self.generate(odds=0.5)
|
16
|
+
rv = 1
|
17
|
+
|
28
18
|
# check random value
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
return self.generate(odds, start+1)
|
19
|
+
while rand() > odds
|
20
|
+
rv += 1
|
33
21
|
end
|
22
|
+
|
23
|
+
# return
|
24
|
+
return rv
|
34
25
|
end
|
35
|
-
end
|
26
|
+
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fraction_life
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike O'Sullivan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: Returns
|
13
|
+
description: Returns a random integer from 1 to infinity. Half the time it returns
|
14
|
+
1. Each successive succesive integer is half the probably of the previous.
|
14
15
|
email: miko@idocs.com
|
15
16
|
executables: []
|
16
17
|
extensions: []
|