fibonacci_rng 1.2.0 → 1.2.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/.gitignore +1 -0
- data/README.md +6 -3
- data/lib/fibonacci_rng.rb +1 -0
- data/lib/fibonacci_rng/generator.rb +8 -0
- data/lib/fibonacci_rng/seeder.rb +2 -0
- data/lib/fibonacci_rng/version.rb +1 -1
- data/tests/fibinacci_rng_tests.rb +55 -0
- 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: 22cbdf19766e5f31416393eeabb3a5b60aa68fa9
|
4
|
+
data.tar.gz: e6deeb3eaeaca2700613ed28b74dbcc83ce67c3e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 641404c311f664c1b56c37415054d133ea6376afafaacd44ddb1456f33bfd81b6262ac366a96d92de2142e543dd53ca23f971200323e99d3575ec334ca273187
|
7
|
+
data.tar.gz: accb5987d69ba8c2623ef7fcdecdf69a409c8be30a140d9d84a082fa3aea68ab8ab72138490ddd39c5c6c9fb1e14d15b4c7ee0f0e5aa2bf822f3a258a29a9a71
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -120,7 +120,8 @@ In addition, here are some other options:
|
|
120
120
|
@my_rng.dice(100) # A "random" integer between 0 and 99
|
121
121
|
@my_rng.byte # A "random" integer between 0 and 255
|
122
122
|
@my_rng.word # A "random" integer between 0 and 65535
|
123
|
-
@my_rng.float # A "random" float between 0 and less than 1.
|
123
|
+
@my_rng.float # A quick "random" float between 0 and less than 1.
|
124
|
+
@my_rng.double # A better "random" float between 0 and less than 1.
|
124
125
|
@my_rng.string(10) # A "random" string of 10 characters in length.
|
125
126
|
|
126
127
|
# A "random" string of 10 characters in length from the string 'abcdefg'.
|
@@ -136,6 +137,9 @@ and also available are these helpful methods:
|
|
136
137
|
@my_rng.spin # Spin the generator once.
|
137
138
|
```
|
138
139
|
|
140
|
+
Note: reseed is an alias of the srand method. The reseed method is preferred
|
141
|
+
due to its clearer name.
|
142
|
+
|
139
143
|
If more than one stream of numbers is required, it is best to use multiple
|
140
144
|
instances of FibonacciRng objects rather than rely on one. This will help avoid
|
141
145
|
the two streams of data being correlated.
|
@@ -192,8 +196,7 @@ Each time any of these is run, a different salt string will be generated.
|
|
192
196
|
not. However, it doesn't matter either. The bytes method was added to improve
|
193
197
|
interoperability with the standard Random class. Thus deprecating it was a
|
194
198
|
mistake. This note serves to announce that the bytes method is not going away.
|
195
|
-
|
196
|
-
comment is in error.
|
199
|
+
|
197
200
|
|
198
201
|
## Theory of Operation
|
199
202
|
|
data/lib/fibonacci_rng.rb
CHANGED
@@ -53,6 +53,14 @@ class FibonacciRng
|
|
53
53
|
@buffer[0].to_f / BASE
|
54
54
|
end
|
55
55
|
|
56
|
+
#Get a better pseudo random float
|
57
|
+
def double
|
58
|
+
do_spin
|
59
|
+
part_one = @buffer[0].to_f * BASE
|
60
|
+
do_spin
|
61
|
+
(part_one + @buffer[0].to_f) / DOUBLE
|
62
|
+
end
|
63
|
+
|
56
64
|
#The printable seven bit ASCII characters.
|
57
65
|
ASCII_7_BIT = (' '..'~').to_a.join
|
58
66
|
|
data/lib/fibonacci_rng/seeder.rb
CHANGED
@@ -186,8 +186,63 @@ class FibonacciRngTester < Minitest::Test
|
|
186
186
|
|
187
187
|
prng = FibonacciRng.new("%s*08^_Tg{NnirtZ-94)q9z2l+~bB5")
|
188
188
|
result = Array.new(80) { prng.byte }
|
189
|
+
assert_equal(expected, result)
|
189
190
|
|
191
|
+
prng.reseed("%s*08^_Tg{NnirtZ-94)q9z2l+~bB5")
|
192
|
+
result = Array.new(80) { prng.byte }
|
190
193
|
assert_equal(expected, result)
|
194
|
+
|
195
|
+
|
196
|
+
expected = [0.466758593916893, 0.8060004059225321,
|
197
|
+
0.8063845634460449, 0.8676037490367889,
|
198
|
+
0.350975576788187, 0.2556227296590805,
|
199
|
+
0.4873242452740669, 0.07484667748212814,
|
200
|
+
0.2968141995370388, 0.5417192056775093,
|
201
|
+
0.4288134817034006, 0.26460993848741055,
|
202
|
+
0.13613684102892876, 0.27074786089360714,
|
203
|
+
0.11685592867434025, 0.814235333353281,
|
204
|
+
0.6137734726071358, 0.9152738898992538,
|
205
|
+
0.6325213424861431, 0.22782298550009727,
|
206
|
+
0.6877559795975685, 0.9354030545800924,
|
207
|
+
0.18385234475135803, 0.5579136144369841,
|
208
|
+
0.7501311469823122, 0.04208622872829437,
|
209
|
+
0.31922253780066967, 0.6471036206930876,
|
210
|
+
0.4305369835346937, 0.2239683922380209,
|
211
|
+
0.9770196247845888, 0.3727417625486851]
|
212
|
+
|
213
|
+
prng.reseed("%s*08^_Tg{NnirtZ-94)q9z2l+~bB5")
|
214
|
+
result = Array.new(32) { prng.float }
|
215
|
+
#assert_equal(expected, result)
|
216
|
+
|
217
|
+
(0...32).each do |i|
|
218
|
+
assert_in_delta(expected[i], result[i], 1.0e-16)
|
219
|
+
end
|
220
|
+
|
221
|
+
expected = [0.46675859541818576, 0.8063845650620829,
|
222
|
+
0.3509755772643215, 0.48732424541347974,
|
223
|
+
0.29681420054606944, 0.428813482196275,
|
224
|
+
0.13613684153323594, 0.11685593019097174,
|
225
|
+
0.6137734743119663, 0.6325213429104964,
|
226
|
+
0.6877559813398925, 0.18385234579055312,
|
227
|
+
0.7501311470607039, 0.31922253900599407,
|
228
|
+
0.43053698395186735, 0.9770196254788744,
|
229
|
+
0.105776653432334, 0.17992045162625886,
|
230
|
+
0.7068137351637119, 0.09374992924495854,
|
231
|
+
0.4741257221497737, 0.2717329622804037,
|
232
|
+
0.6427948478921109, 0.048162101812947195,
|
233
|
+
0.649627174383166, 0.27438020721066836,
|
234
|
+
0.9478733559036244, 0.6199505789910625,
|
235
|
+
0.8043054302444751, 0.9363898295339244,
|
236
|
+
0.6613804354420972, 0.5876014495519649]
|
237
|
+
|
238
|
+
prng.reseed("%s*08^_Tg{NnirtZ-94)q9z2l+~bB5")
|
239
|
+
result = Array.new(32) { prng.double }
|
240
|
+
#assert_equal(expected, result)
|
241
|
+
|
242
|
+
(0...32).each do |i|
|
243
|
+
assert_in_delta(expected[i], result[i], 1.0e-16)
|
244
|
+
end
|
245
|
+
|
191
246
|
end
|
192
247
|
|
193
248
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fibonacci_rng
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.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-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest_visible
|