composite_rng 0.1.0 → 0.1.1
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/README.md +47 -50
- data/irbt.rb +0 -2
- data/lib/composite_rng/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b708a3140244ee9cd7919bd64f09693ff1e0898e
|
4
|
+
data.tar.gz: c8ab8c08c73c26c0f12bcfbbc4ebfe11237b9762
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
5
|
-
quality pseudo-random number streams than either could
|
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
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install composite_rng
|
14
21
|
|
15
|
-
|
22
|
+
The composite_rng gem itself is found at: ( https://rubygems.org/gems/composite_rng )
|
16
23
|
|
17
|
-
|
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
|
-
|
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
|
-
|
30
|
+
Then in an appropriate place in the code:
|
31
|
+
|
37
32
|
```ruby
|
38
|
-
|
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
|
50
|
-
|
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
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.
|
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-
|
11
|
+
date: 2016-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|