fibonacci_rng 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fibonacci_rng/generator.rb +2 -0
- data/lib/fibonacci_rng/seeder.rb +16 -1
- data/lib/fibonacci_rng/version.rb +1 -1
- data/tests/fibinacci_rng_tests.rb +17 -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: 5064c4df22e9527ed30a68a7c7b4470721fd2e6c
|
4
|
+
data.tar.gz: a4f2d50bb58bf04fac0f66f7dfd57b7f0be5a6a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a4c4f246d53887844cb1e0a42cce67a99519da7c6c6070a5ca7de651c8468a87925d93f5648ae72714bdbf196700dd8e02e10a412f7990786d20f0b97ebb9a30
|
7
|
+
data.tar.gz: 5896d20ae29c6798376fc6961c08e1bd2eceff8eb2626a2f08a3f71c7a2e345d3a8da97efb1c21818a4a81b27e25af371753fd08af28795fd7301927228e337a
|
data/lib/fibonacci_rng/seeder.rb
CHANGED
@@ -7,13 +7,28 @@ class FibonacciRng
|
|
7
7
|
def srand(seed=FibonacciRng.new_seed)
|
8
8
|
@seed = seed
|
9
9
|
@buffer = Array.new(@depth+2, 0)
|
10
|
-
seedsrc = (seed.to_s + seed
|
10
|
+
seedsrc = (seed.to_s + fudge(seed) + 'Leonardo Pisano').each_byte.cycle
|
11
11
|
indxsrc = (0...depth).cycle
|
12
12
|
do_reseed(indxsrc, seedsrc)
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
+
#A patch for the seeder class name bug.
|
18
|
+
#<br>Endemic Code Smells
|
19
|
+
#* :reek:UtilityFunction
|
20
|
+
def fudge(seed)
|
21
|
+
if seed.is_a?(Integer)
|
22
|
+
if (-1073741824..1073741823) === seed
|
23
|
+
"Fixnum"
|
24
|
+
else
|
25
|
+
"Bignum"
|
26
|
+
end
|
27
|
+
else
|
28
|
+
seed.class.to_s
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
17
32
|
#A class instance variable to hold the tickle value.
|
18
33
|
@tickle = '0'
|
19
34
|
|
@@ -173,4 +173,21 @@ class FibonacciRngTester < Minitest::Test
|
|
173
173
|
assert_equal('khto lk si', rng.string(10, 'Always look on the bright side of life.'))
|
174
174
|
end
|
175
175
|
|
176
|
+
def test_for_data_stability
|
177
|
+
#Make sure incompatibilities do not creep in.
|
178
|
+
expected = [184, 93, 0, 240, 34, 184, 4, 220, 126, 132,
|
179
|
+
13, 67, 166, 107, 165, 66, 68, 120, 102, 110,
|
180
|
+
212, 99, 80, 167, 9, 56, 47, 167, 127, 195,
|
181
|
+
169, 34, 184, 97, 136, 176, 214, 104, 218, 103,
|
182
|
+
180, 16, 83, 204, 128, 81, 63, 56, 237, 165,
|
183
|
+
0, 88, 129, 40, 152, 44, 189, 35, 205, 249,
|
184
|
+
77, 94, 142, 18, 60, 248, 49, 172, 235, 83,
|
185
|
+
84, 65, 181, 117, 16, 170, 222, 97, 130, 217]
|
186
|
+
|
187
|
+
prng = FibonacciRng.new("%s*08^_Tg{NnirtZ-94)q9z2l+~bB5")
|
188
|
+
result = Array.new(80) { prng.byte }
|
189
|
+
|
190
|
+
assert_equal(expected, result)
|
191
|
+
end
|
192
|
+
|
176
193
|
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.
|
4
|
+
version: 1.2.0
|
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-07-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest_visible
|