fraction_life 0.0.1 → 0.0.2

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/fraction_life.rb +26 -9
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: be30985cbc5e7d2ec929a22129b92241c11ddda2
4
- data.tar.gz: c922ff83c709117c38c7928b10c9112dc559babc
3
+ metadata.gz: dce779fb4cb6c85054b8c6c26de44f5c3ff46693
4
+ data.tar.gz: 0b1c2de15443fcaa3016d233aee8c9f4b70a0a6b
5
5
  SHA512:
6
- metadata.gz: 75038153aee903c4bae7cba08fa01b7293630ae496f737373ee286f6c2a21d148fe2b508b50dd4bcb9250b7ca5c8117561cb85ae1fdaf3d4e8ac8c93c4253f67
7
- data.tar.gz: a0367e15d971e172823938e5af5bbb3d774c7e5d529a03e3cdd5617bf7dfb106146a51be9d59279e9ba381e6dd599c9e451ace95c7e9e18fc9fdae2ba8bf3a50
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fraction_life
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike O'Sullivan