fraction_life 0.0.2 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fraction_life.rb +9 -18
  3. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dce779fb4cb6c85054b8c6c26de44f5c3ff46693
4
- data.tar.gz: 0b1c2de15443fcaa3016d233aee8c9f4b70a0a6b
3
+ metadata.gz: c7f86fd0c0a7ba8aa4a2e88fc7f0936ca318b550
4
+ data.tar.gz: b564edca74a7dd06b7aedc56718d007d814bab02
5
5
  SHA512:
6
- metadata.gz: 073a63f13d6ec8e0227166f0ee95bc540593e8de5269f5d4561b830b9d0f78fecd0748ca5770f7ba9458b877bd4a3f606ba655f679a74ee99bce31cb75456cac
7
- data.tar.gz: ac9fe2c17eff8020aebd47fe599ccbd1d841a4d3a380a533b48de0cd494bd3cfdb7e3b7217d5d2afda180b33f23a5f19d37dea65d5afa163e4cbca58b9b78e25
6
+ metadata.gz: 59eea21b07f6d4a31062c1f778612e60b2361506896b6b04715f13ff3bb1f4b59d98684737d1a6c24ec756a4bdcc283631a7585752eb1a808a61480b22fb87f7
7
+ data.tar.gz: 87f9ffb6635bc74901a19cba35a49840664a7b4fb4f679d604936191f86274e4f79fda841b9bded56b37dfcc77fb75be4803bf7741c3b40bffd42bce1c3576f1
@@ -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, start=1)
15
+ def self.generate(odds=0.5)
16
+ rv = 1
17
+
28
18
  # check random value
29
- if rand() <= odds
30
- return start
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.2
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-04 00:00:00.000000000 Z
11
+ date: 2018-11-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Returns an integer with each value half the probability of the previous
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: []