composite_rng 0.1.0 → 0.1.1

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: 1f340e108ce670dca8fd91ec9089ae5753eae06e
4
- data.tar.gz: b992ad5f3defe4e2578090833730107b256bfc89
3
+ metadata.gz: b708a3140244ee9cd7919bd64f09693ff1e0898e
4
+ data.tar.gz: c8ab8c08c73c26c0f12bcfbbc4ebfe11237b9762
5
5
  SHA512:
6
- metadata.gz: 1731dee7aeb11ec2f9006853c038211c89afcaa4a5e4e9f4e6b3f74e24339218d39c2108e270feea0b05aa01a9f6277d365fb27b59e1397d2799f06d314f828d
7
- data.tar.gz: cf12a60cc2dba80842ef8f2e73dede341cb0a7e6766f1800a6bec6f16b00fbf3a2dd030f7e380818288f3670120f1d12a18d824985ea45dce084da9176f947a4
6
+ metadata.gz: c5acd1e444d66764fc2b2d5245be9bf12b8c693ea8d9461260da810628dd7aa8b8c7889474a22f12056977f70622669946f3cfc569f73779a22917d773cc6578
7
+ data.tar.gz: 33ad85e4dd8525b41ed8d3580b01133696b4ec3574cbce78f81bff40cbd471933e83d5bc5be81f047629d53d102c4b67ae5554a5910922520862439eb7ebbc4c
data/README.md CHANGED
@@ -1,53 +1,68 @@
1
1
  # CompositeRng
2
2
 
3
3
  The composite (psuedo) random number generator is a container for two other
4
- (psuedo) random number generators. By working together, these create higher
5
- quality pseudo-random number streams than either could by itself.
4
+ (psuedo) random number generators. By working together, these generators
5
+ create higher quality pseudo-random number streams than either could create
6
+ by itself.
6
7
 
7
- The two generators do not need to be the same type. In fact it helps to reduce
8
- any possible correlation between the parent and the child if they are
9
- completely different sorts of generators. It is really not a good idea for them
10
- to be either the same instance, or the same type with the same seed, because
11
- this negates the advantage of compositing generators.
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'composite_rng'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
12
17
 
13
- The generators used must comply to the following duck characteristics:
18
+ Or install it yourself as:
19
+
20
+ $ gem install composite_rng
14
21
 
15
- rand(max) - This method must compute a random integer from 0...max
22
+ The composite_rng gem itself is found at: ( https://rubygems.org/gems/composite_rng )
16
23
 
17
- The constructor takes four arguments:
18
- * The parent PRNG that is used to "educate" the child.
19
- * The child PRNG that is the actual generator of data.
20
- * The optional churn_limit factor that controls how much tutoring the child
21
- can receive. This optional parameter defaults to 16. This value may be read
22
- back with the churn_limit property. Valid values are 2..256
23
- * The optional init factor that controls the amount of initial tutoring the
24
- child receives initially. This defaults to 0 for none. Valid values are 0..256
24
+ ##Usage
25
25
 
26
- The following shows how this could work:
27
26
  ```ruby
28
- parent = Random.new #Get the built in Mersenne Twister MT19937 PRNG
29
- child = Random.new
30
- composite = CompositeRng.new(parent, child, 42, 11)
31
- # ...
32
- dice_roll = 1 + composite.rand(6)
33
- # ...
27
+ require 'composite_rng'
34
28
  ```
35
29
 
36
- It is also possible to use the default PRNG as follows:
30
+ Then in an appropriate place in the code:
31
+
37
32
  ```ruby
38
- parent = Object.new
33
+ @my_rng = CompositeRng.new(parent, child, churn, init)
34
+ ```
35
+ Where:
36
+ * parent is a random number generator used to educate the child.
37
+ * child is the random number generator used to generate the output.
38
+ * churn is the limit on the education process. Default 16, Range 2..256
39
+ * init is the number of initial churns done during initialization. Default 0, Range 0..256
40
+
41
+ The parent and child generators do not need to be the same type. In fact it
42
+ helps to reduce any possible correlation between the parent and the child
43
+ if they are completely different sorts of generators. It is a really bad
44
+ idea for them to be either the same instance, or the same type with the same
45
+ seed, because this negates the advantage of compositing generators.
46
+
47
+ To be used in a composite generator, both generators used must implement the
48
+ following method:
49
+
50
+ rand(max)
51
+
52
+ which method must return a pseudo-random integer in 0...max.
53
+
54
+ The following are examples of this class in action.
55
+ ```ruby
56
+ parent = Random.new #Get the built in Mersenne Twister MT19937 PRNG
39
57
  child = Random.new
40
- composite = CompositeRng.new(parent, child)
58
+ composite = CompositeRng.new(parent, child, 42, 11)
41
59
  # ...
42
60
  dice_roll = 1 + composite.rand(6)
43
61
  # ...
44
62
  ```
45
- This is because the default PRNG exists as methods of Object. Note that (as
46
- far as I can tell) only one instance of that PRNG exists, so it should only
47
- be used as parent or child but never both!.
48
63
 
49
- The composite generator also works with custom generator, that support rand(n)
50
- like my own Fibonacci generator:
64
+ The composite generator also works with custom generators that support rand(n).
65
+ For example my own Fibonacci generator:
51
66
 
52
67
  ```ruby
53
68
  parent = Random.new
@@ -77,24 +92,6 @@ more thorough job:
77
92
  crazy_string = 22.times.inject("") { |s| s << composite.churn.bytes(1) }
78
93
  ```
79
94
 
80
- ## Installation
81
-
82
- Add this line to your application's Gemfile:
83
-
84
- gem 'composite_rng'
85
-
86
- And then execute:
87
-
88
- $ bundle
89
-
90
- Or install it yourself as:
91
-
92
- $ gem install composite_rng
93
-
94
- The composite_rng gem itself is found at: ( https://rubygems.org/gems/composite_rng )
95
-
96
- The fibonacci_rng code lives at: ( https://github.com/PeterCamilleri/fibonacci_rng )
97
-
98
95
  ## Contributing
99
96
 
100
97
  #### Plan A
data/irbt.rb CHANGED
@@ -2,8 +2,6 @@
2
2
  # An IRB + composite_rng Test bed
3
3
 
4
4
  require 'irb'
5
- $force_alias_read_line_module = true
6
- require 'mini_readline'
7
5
 
8
6
  puts "Starting an IRB console with composite_rng loaded."
9
7
 
@@ -1,4 +1,4 @@
1
1
  class CompositeRng
2
2
  #The CompositeRng version.
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
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.1.0
4
+ version: 0.1.1
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-05-13 00:00:00.000000000 Z
11
+ date: 2016-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler