composite_rng 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f396507dbca6e987cfa25c886a4f19d43f97ac65
4
- data.tar.gz: 81a4458332e1722aab3a4b6071ef4855445346b4
3
+ metadata.gz: 7c30e36b6d59c807536035ad3fdbaefa8dccb420
4
+ data.tar.gz: 3ff2d418c856aa7af2b76af17e5f9d3950caa6d8
5
5
  SHA512:
6
- metadata.gz: 09c2e901a722205421eb0b18f95b02b81f84ed0bcb45abc34f185876a23da41587369328e4e23a79d07d7f5124775590ccbec3f98c03595ecbf36fe326bc6088
7
- data.tar.gz: beb18e79a48d6916c1612a15dfd409b6077e5e240a4458c95949517947a26ab4c5ed2bf1b43d620e361c24014f6222407196d688e90379bd0c71ff52ca0bae03
6
+ metadata.gz: 8282ef4f619b086e53fc1663cc843008b194f533baa72d0806d499d4ef4e3c5bdad1c50e9a49de39d1825d379c5275d697edc0c00dbe0275214ddfa2c185e7c4
7
+ data.tar.gz: 495bef03e18c3860c9e50cb023fe50e70b792d66f9d066ee830697e2c290d9668a0a273b4b7ba8b82d609862f1ca98d66bfddaa4c9ad355670b1777dd2120652
data/README.md CHANGED
@@ -8,37 +8,68 @@ The two generators do NOT need to be the same type. While not a good idea,
8
8
  they may even be the same instance, or the same type with the same seed, but
9
9
  this negates the advantage of compositing them.
10
10
 
11
- The generators used most comply to the following duck characteristics:
11
+ The generators used must comply to the following duck characteristics:
12
12
 
13
13
  rand(max) - This method must compute a random integer from 0...max
14
14
 
15
15
  That's all! The following shows how this could work:
16
-
17
- parent = Random.new #Get the built in Mersenne Twister MT19937 PRNG
18
- child = Random.new
19
- composite = CompositeRng.new(parent, child)
20
- # ...
21
- dice_roll = composite(6)
22
- # ...
16
+ ```ruby
17
+ parent = Random.new #Get the built in Mersenne Twister MT19937 PRNG
18
+ child = Random.new
19
+ composite = CompositeRng.new(parent, child, 42)
20
+ # ...
21
+ dice_roll = 1 + composite.rand(6)
22
+ # ...
23
+ ```
24
+ The constructor takes three arguements:
25
+ * The parent PRNG that is used to "educate" the child.
26
+ * The child PRNG that is the actual generator of data.
27
+ * The churn factor that controls how much tutoring the child is to receive.
28
+ This optional parameter defaults to 16.
23
29
 
24
30
  It is also possible to use the default PRNG as follows:
25
-
26
- parent = Object.new
27
- child = Random.new
28
- composite = CompositeRng.new(parent, child)
29
- # ...
30
- dice_roll = composite(6)
31
- # ...
32
-
31
+ ```ruby
32
+ parent = Object.new
33
+ child = Random.new
34
+ composite = CompositeRng.new(parent, child)
35
+ # ...
36
+ dice_roll = 1 + composite.rand(6)
37
+ # ...
38
+ ```
33
39
  This is because the default PRNG exists as methods of Object. Note that (as
34
40
  far as I can tell) only one instance of that PRNG exists, so it should only
35
41
  be used as parent or child but never both!.
36
42
 
37
- Most PRNGs provide more resources beyond the basic "rand" method. Access to
38
- these other methods is provided by using the churn method. An example,
39
- accessing the bytes method of the Random class follows:
43
+ The composite generator also works with custom generator, that support rand(n)
44
+ like my own Fibonacci generator:
45
+
46
+ ```ruby
47
+ parent = Random.new
48
+ child = FibonacciRng.new(depth: 12)
49
+ composite = CompositeRng.new(parent, child)
50
+ # ...
51
+ dice_roll = 1 + composite.rand(6)
52
+ # ...
53
+ ```
40
54
 
41
- crazy_string = composite.churn.bytes(22) # Get a string of 22 random chars.
55
+ #### Accessing advanced methods with churn
56
+
57
+ Most PRNGs provide more resources beyond the basic "rand" method. Access to
58
+ these other methods is provided by using the churn method. The churn method
59
+ returns the child PRNG after it has received a suitable period of instruction
60
+ from the parent PRNG. An example, accessing the bytes method of the Random
61
+ class follows:
62
+ ```ruby
63
+ # Get a string of 22 random chars.
64
+ crazy_string = composite.churn.bytes(22)
65
+ ```
66
+ While this code seems to work, it really is weak tea. The issue is that the
67
+ education process is only carried out once. The following code does a much
68
+ more thorough job:
69
+ ```ruby
70
+ # Get a string of 22 random chars.
71
+ crazy_string = 22.times.inject("") { |s| s << composite.churn.bytes(1) }
72
+ ```
42
73
 
43
74
  ## Installation
44
75
 
@@ -54,10 +85,19 @@ Or install it yourself as:
54
85
 
55
86
  $ gem install composite_rng
56
87
 
88
+ The composite_rng gem itself is found at: ( https://rubygems.org/gems/composite_rng )
89
+
57
90
  ## Contributing
58
91
 
59
- 1. Fork it
92
+ #### Plan A
93
+
94
+ 1. Fork it ( https://github.com/PeterCamilleri/composite_rng/fork )
60
95
  2. Create your feature branch (`git checkout -b my-new-feature`)
61
96
  3. Commit your changes (`git commit -am 'Add some feature'`)
62
97
  4. Push to the branch (`git push origin my-new-feature`)
63
98
  5. Create new Pull Request
99
+
100
+ #### Plan B
101
+
102
+ Go to the GitHub repository and raise an issue calling attention to some
103
+ aspect that could use some TLC or a suggestion or an idea.
data/irbt.rb ADDED
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ # An IRB + composite_rng Test bed
3
+
4
+ require 'irb'
5
+ $force_alias_read_line_module = true
6
+ require 'mini_readline'
7
+
8
+ puts "Starting an IRB console with composite_rng loaded."
9
+
10
+ if ARGV[0] == 'local'
11
+ require_relative 'lib/composite_rng'
12
+ puts "composite_rng loaded locally: #{CompositeRng::VERSION}"
13
+
14
+ ARGV.shift
15
+ else
16
+ require 'composite_rng'
17
+ puts "composite_rng loaded from gem: #{CompositeRng::VERSION}"
18
+ end
19
+
20
+ begin
21
+ require 'fibonacci_rng'
22
+ puts "fibonacci_rng loaded from gem: #{FibonacciRng::VERSION}"
23
+ rescue
24
+ puts "fibonacci_rng not loaded."
25
+ end
26
+
27
+ IRB.start
@@ -1,4 +1,4 @@
1
1
  class CompositeRng
2
2
  #The CompositeRng version.
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
data/lib/composite_rng.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "composite_rng/version"
1
+ require_relative "composite_rng/version"
2
2
 
3
3
  #A class of random number generators that work by nesting other PRNGs.
4
4
  class CompositeRng
@@ -32,14 +32,7 @@ end
32
32
 
33
33
  desc "Fire up an IRB session with composite_rng preloaded."
34
34
  task :console do
35
- require 'irb'
36
- require 'irb/completion'
37
-
38
- require './lib/composite_rng'
39
- puts "Starting an IRB console for composite_rng."
40
-
41
- ARGV.clear
42
- IRB.start
35
+ system "ruby irbt.rb local"
43
36
  end
44
37
 
45
38
  desc "What version of the composite_rng is this?"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: composite_rng
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Camilleri
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-18 00:00:00.000000000 Z
11
+ date: 2016-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -105,10 +105,11 @@ files:
105
105
  - Gemfile
106
106
  - LICENSE.txt
107
107
  - README.md
108
- - Rakefile
109
108
  - composite_rng.gemspec
109
+ - irbt.rb
110
110
  - lib/composite_rng.rb
111
111
  - lib/composite_rng/version.rb
112
+ - rakefile.rb
112
113
  - reek.txt
113
114
  - tests/composite_rng_tests.rb
114
115
  homepage: http://teuthida-technologies.com/