pool_of_entropy 0.0.3 → 0.0.4
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/.travis.yml +5 -1
- data/README.md +1 -0
- data/lib/pool_of_entropy.rb +5 -1
- data/lib/pool_of_entropy/version.rb +1 -1
- data/spec/core_prng_spec.rb +160 -160
- data/spec/pool_of_entropy_spec.rb +63 -63
- 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: 512c263491f2d05bebe3e96ac23d1a3c0e3d49e9
|
4
|
+
data.tar.gz: 9833ccfc16899dc106a5839e739a435bbac3b2b4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 971e11a66fa0b70be64e5d4a27d72aa6786552fa7dcd4f790bfdc8d8253486102db7cfb668583566951d04303dedf9f6664c0d4ca5b91881c84351ad7d263f61
|
7
|
+
data.tar.gz: a481cb8eef794fe07692743c007ac190c68e37d5eebaaec9645f7f52bdfc7c02815068b3672d63ec5468aee1f1e080f8417000e11f244c12c64a7ab371be4ed3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
[](http://badge.fury.io/rb/pool_of_entropy)
|
3
3
|
[](http://travis-ci.org/neilslater/pool_of_entropy)
|
4
4
|
[](https://coveralls.io/r/neilslater/pool_of_entropy?branch=master)
|
5
|
+
[](http://inch-ci.org/github/neilslater/pool_of_entropy)
|
5
6
|
[](https://codeclimate.com/github/neilslater/pool_of_entropy)
|
6
7
|
[](https://gemnasium.com/neilslater/pool_of_entropy)
|
7
8
|
|
data/lib/pool_of_entropy.rb
CHANGED
@@ -50,7 +50,11 @@ class PoolOfEntropy
|
|
50
50
|
# Cloning creates a deep copy with identical PRNG state and modifiers
|
51
51
|
# @return [PoolOfEntropy]
|
52
52
|
def clone
|
53
|
-
|
53
|
+
copy = super
|
54
|
+
copy.instance_variable_set( :@core_prng, @core_prng.clone )
|
55
|
+
copy.instance_variable_set( :@fixed_modifier, @fixed_modifier.clone ) if @fixed_modifier
|
56
|
+
copy.instance_variable_set( :@next_modifier_queue, @next_modifier_queue.map { |m| m.clone } )
|
57
|
+
copy
|
54
58
|
end
|
55
59
|
|
56
60
|
# Same functionality as Kernel#rand or Random#rand, but using
|
data/spec/core_prng_spec.rb
CHANGED
@@ -6,14 +6,14 @@ describe PoolOfEntropy::CorePRNG do
|
|
6
6
|
describe "#new" do
|
7
7
|
it "should instantiate a default object" do
|
8
8
|
prng = PoolOfEntropy::CorePRNG.new
|
9
|
-
prng.
|
10
|
-
prng.size.
|
9
|
+
expect( prng ).to be_a PoolOfEntropy::CorePRNG
|
10
|
+
expect( prng.size ).to be 1
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should allow setting number of blocks in pool" do
|
14
14
|
prng = PoolOfEntropy::CorePRNG.new( 10 )
|
15
|
-
prng.
|
16
|
-
prng.size.
|
15
|
+
expect( prng ).to be_a PoolOfEntropy::CorePRNG
|
16
|
+
expect( prng.size ).to be 10
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should fail with incorrect block number" do
|
@@ -29,9 +29,9 @@ describe PoolOfEntropy::CorePRNG do
|
|
29
29
|
|
30
30
|
it "should allow setting internal state" do
|
31
31
|
prng = PoolOfEntropy::CorePRNG.new( 1, "\x0" * 64 )
|
32
|
-
prng.
|
33
|
-
prng.size.
|
34
|
-
prng.state.
|
32
|
+
expect( prng ).to be_a PoolOfEntropy::CorePRNG
|
33
|
+
expect( prng.size ).to be 1
|
34
|
+
expect( prng.state ).to eql "\x0" * 64
|
35
35
|
end
|
36
36
|
|
37
37
|
it "should fail with bad state data" do
|
@@ -45,10 +45,10 @@ describe PoolOfEntropy::CorePRNG do
|
|
45
45
|
|
46
46
|
it "should allow setting mix_block_id" do
|
47
47
|
prng = PoolOfEntropy::CorePRNG.new( 3, "\x12" * 192, 1 )
|
48
|
-
prng.
|
49
|
-
prng.size.
|
50
|
-
prng.state.
|
51
|
-
prng.mix_block_id.
|
48
|
+
expect( prng ).to be_a PoolOfEntropy::CorePRNG
|
49
|
+
expect( prng.size ).to eql 3
|
50
|
+
expect( prng.state ).to eql "\x12" * 192
|
51
|
+
expect( prng.mix_block_id ).to eql 1
|
52
52
|
end
|
53
53
|
end
|
54
54
|
end
|
@@ -60,15 +60,15 @@ describe PoolOfEntropy::CorePRNG do
|
|
60
60
|
prng_orig = PoolOfEntropy::CorePRNG.new
|
61
61
|
prng_copy = prng_orig.clone
|
62
62
|
|
63
|
-
prng_copy.size.
|
64
|
-
prng_copy.state.
|
65
|
-
prng_copy.mix_block_id.
|
63
|
+
expect( prng_copy.size ).to eql prng_orig.size
|
64
|
+
expect( prng_copy.state ).to eql prng_orig.state
|
65
|
+
expect( prng_copy.mix_block_id ).to eql prng_orig.mix_block_id
|
66
66
|
end
|
67
67
|
|
68
68
|
it "should deep clone the internal state string" do
|
69
69
|
prng_orig = PoolOfEntropy::CorePRNG.new
|
70
70
|
prng_copy = prng_orig.clone
|
71
|
-
prng_copy.state.
|
71
|
+
expect( prng_copy.state ).to_not be prng_orig.state
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
@@ -77,25 +77,25 @@ describe PoolOfEntropy::CorePRNG do
|
|
77
77
|
prng = PoolOfEntropy::CorePRNG.new
|
78
78
|
init_state = prng.state.clone
|
79
79
|
prng.update( 'boo' )
|
80
|
-
prng.state.
|
80
|
+
expect( prng.state ).to_not eql init_state
|
81
81
|
end
|
82
82
|
|
83
83
|
it "should not change the length of the internal state" do
|
84
84
|
prng = PoolOfEntropy::CorePRNG.new
|
85
85
|
prng.update( 'boo' )
|
86
|
-
prng.state.length.
|
86
|
+
expect( prng.state.length ).to eql 64
|
87
87
|
prng.update( 'boowgkjwrhqgioueqrhgiue2hguirhqwiughreuioghreuifhqwoifhr3iufghfwrgrwgetdfwd' )
|
88
|
-
prng.state.length.
|
88
|
+
expect( prng.state.length ).to eql 64
|
89
89
|
|
90
90
|
prng = PoolOfEntropy::CorePRNG.new( 5 )
|
91
91
|
prng.update( 'boo' )
|
92
|
-
prng.state.length.
|
92
|
+
expect( prng.state.length ).to eql 5 * 64
|
93
93
|
prng.update( 'getdfwd' * 1000 )
|
94
|
-
prng.state.length.
|
94
|
+
expect( prng.state.length ).to eql 5 * 64
|
95
95
|
prng.update( 'boefewfweo' )
|
96
|
-
prng.state.length.
|
96
|
+
expect( prng.state.length ).to eql 5 * 64
|
97
97
|
prng.update( 'geefewftdfwd' * 1000 )
|
98
|
-
prng.state.length.
|
98
|
+
expect( prng.state.length ).to eql 5 * 64
|
99
99
|
end
|
100
100
|
|
101
101
|
it "should only change 64 bytes of state at a time" do
|
@@ -103,22 +103,22 @@ describe PoolOfEntropy::CorePRNG do
|
|
103
103
|
init_state = prng.state.clone
|
104
104
|
|
105
105
|
prng.update( 'boo' )
|
106
|
-
prng.state[64,4*64].
|
106
|
+
expect( prng.state[64,4*64] ).to eql init_state[64,4*64]
|
107
107
|
next_state = prng.state.clone
|
108
108
|
|
109
109
|
prng.update( 'getdfwd' * 1000 )
|
110
|
-
prng.state[128,3*64].
|
111
|
-
prng.state[0,1*64].
|
110
|
+
expect( prng.state[128,3*64] ).to eql init_state[128,3*64]
|
111
|
+
expect( prng.state[0,1*64] ).to eql next_state[0,1*64]
|
112
112
|
next_state = prng.state.clone
|
113
113
|
|
114
114
|
prng.update( 'boefewfweo' )
|
115
|
-
prng.state[192,2*64].
|
116
|
-
prng.state[0,2*64].
|
115
|
+
expect( prng.state[192,2*64] ).to eql init_state[192,2*64]
|
116
|
+
expect( prng.state[0,2*64] ).to eql next_state[0,2*64]
|
117
117
|
next_state = prng.state.clone
|
118
118
|
|
119
119
|
prng.update( 'geefewftdfwd' * 1000 )
|
120
|
-
prng.state[256,1*64].
|
121
|
-
prng.state[0,3*64].
|
120
|
+
expect( prng.state[256,1*64] ).to eql init_state[256,1*64]
|
121
|
+
expect( prng.state[0,3*64] ).to eql next_state[0,3*64]
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -163,40 +163,40 @@ describe PoolOfEntropy::CorePRNG do
|
|
163
163
|
|
164
164
|
describe "#read_bytes" do
|
165
165
|
it "always returns a 16 byte string" do
|
166
|
-
100.times { prng.read_bytes.length.
|
166
|
+
100.times { expect( prng.read_bytes.length ).to eql 16 }
|
167
167
|
end
|
168
168
|
|
169
169
|
it "has a high probability of returning a different string each time" do
|
170
|
-
Set[ *(1..100).map {prng.read_bytes} ].size.
|
170
|
+
expect( Set[ *(1..100).map {prng.read_bytes} ].size ).to eql 100
|
171
171
|
end
|
172
172
|
|
173
173
|
describe "with adjustments" do
|
174
174
|
it "always returns a 16 byte string" do
|
175
|
-
100.times { prng.read_bytes('654321').length.
|
175
|
+
100.times { expect( prng.read_bytes('654321').length ).to eql 16 }
|
176
176
|
end
|
177
177
|
|
178
178
|
it "has a high probability of returning a different string each time" do
|
179
|
-
Set[ *(1..100).map {prng.read_bytes('654321')} ].size.
|
179
|
+
expect( Set[ *(1..100).map {prng.read_bytes('654321')} ].size ).to eql 100
|
180
180
|
end
|
181
181
|
|
182
182
|
it "changes output, but does not include adjustments in changes to state" do
|
183
183
|
prng_copy = prng.clone
|
184
184
|
10.times do
|
185
|
-
prng.read_bytes('Hello!').
|
186
|
-
prng.state.
|
187
|
-
prng.read_bytes('Hello!').
|
188
|
-
prng.state.
|
189
|
-
prng.read_bytes.
|
190
|
-
prng.state.
|
191
|
-
prng.read_bytes('Hello!').
|
192
|
-
prng.state.
|
193
|
-
prng.read_bytes('Hello','Goodbye').
|
194
|
-
prng.state.
|
185
|
+
expect( prng.read_bytes('Hello!') ).to eql prng_copy.read_bytes('Hello!')
|
186
|
+
expect( prng.state ).to eql prng_copy.state
|
187
|
+
expect( prng.read_bytes('Hello!') ).to_not eql prng_copy.read_bytes('Goodbye!')
|
188
|
+
expect( prng.state ).to eql prng_copy.state
|
189
|
+
expect( prng.read_bytes ).to_not eql prng_copy.read_bytes('Goodbye!')
|
190
|
+
expect( prng.state ).to eql prng_copy.state
|
191
|
+
expect( prng.read_bytes('Hello!') ).to_not eql prng_copy.read_bytes
|
192
|
+
expect( prng.state ).to eql prng_copy.state
|
193
|
+
expect( prng.read_bytes('Hello','Goodbye') ).to_not eql prng_copy.read_bytes
|
194
|
+
expect( prng.state ).to eql prng_copy.state
|
195
195
|
# Verify that output remains same for next rolls
|
196
|
-
prng.read_bytes('Foobar','Wibble').
|
197
|
-
prng.state.
|
198
|
-
prng.read_bytes.
|
199
|
-
prng.state.
|
196
|
+
expect( prng.read_bytes('Foobar','Wibble') ).to eql prng_copy.read_bytes('Foobar','Wibble')
|
197
|
+
expect( prng.state ).to eql prng_copy.state
|
198
|
+
expect( prng.read_bytes ).to eql prng_copy.read_bytes
|
199
|
+
expect( prng.state ).to eql prng_copy.state
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
@@ -206,46 +206,46 @@ describe PoolOfEntropy::CorePRNG do
|
|
206
206
|
it "always returns a 32 digit hex string" do
|
207
207
|
100.times do
|
208
208
|
hex = prng.read_hex
|
209
|
-
hex.length.
|
210
|
-
hex.
|
209
|
+
expect( hex.length ).to eql 32
|
210
|
+
expect( hex ).to match /\A[0-9a-f]{32}\z/
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
214
|
it "has a high probability of returning a different string each time" do
|
215
|
-
Set[ *(1..100).map {prng.read_hex} ].size.
|
215
|
+
expect( Set[ *(1..100).map {prng.read_hex} ].size ).to eql 100
|
216
216
|
end
|
217
217
|
|
218
218
|
describe "with adjustments" do
|
219
219
|
it "always returns a 32 digit hex string" do
|
220
220
|
100.times do
|
221
221
|
hex = prng.read_hex('QWertyeu')
|
222
|
-
hex.length.
|
223
|
-
hex.
|
222
|
+
expect( hex.length ).to eql 32
|
223
|
+
expect( hex ).to match /\A[0-9a-f]{32}\z/
|
224
224
|
end
|
225
225
|
end
|
226
226
|
|
227
227
|
it "has a high probability of returning a different string each time" do
|
228
|
-
Set[ *(1..100).map {prng.read_hex('654321')} ].size.
|
228
|
+
expect( Set[ *(1..100).map {prng.read_hex('654321')} ].size ).to eql 100
|
229
229
|
end
|
230
230
|
|
231
231
|
it "changes output, but does not include adjustments in changes to state" do
|
232
232
|
prng_copy = prng.clone
|
233
233
|
10.times do
|
234
|
-
prng.read_hex('Hello!').
|
235
|
-
prng.state.
|
236
|
-
prng.read_hex('Hello!').
|
237
|
-
prng.state.
|
238
|
-
prng.read_hex.
|
239
|
-
prng.state.
|
240
|
-
prng.read_hex('Hello!').
|
241
|
-
prng.state.
|
242
|
-
prng.read_hex('Hello','Goodbye').
|
243
|
-
prng.state.
|
234
|
+
expect( prng.read_hex('Hello!') ).to eql prng_copy.read_hex('Hello!')
|
235
|
+
expect( prng.state ).to eql prng_copy.state
|
236
|
+
expect( prng.read_hex('Hello!') ).to_not eql prng_copy.read_hex('Goodbye!')
|
237
|
+
expect( prng.state ).to eql prng_copy.state
|
238
|
+
expect( prng.read_hex ).to_not eql prng_copy.read_hex('Goodbye!')
|
239
|
+
expect( prng.state ).to eql prng_copy.state
|
240
|
+
expect( prng.read_hex('Hello!') ).to_not eql prng_copy.read_hex
|
241
|
+
expect( prng.state ).to eql prng_copy.state
|
242
|
+
expect( prng.read_hex('Hello','Goodbye') ).to_not eql prng_copy.read_hex
|
243
|
+
expect( prng.state ).to eql prng_copy.state
|
244
244
|
# Verify that output remains same for next rolls
|
245
|
-
prng.read_hex('Foobar','Wibble').
|
246
|
-
prng.state.
|
247
|
-
prng.read_hex.
|
248
|
-
prng.state.
|
245
|
+
expect( prng.read_hex('Foobar','Wibble') ).to eql prng_copy.read_hex('Foobar','Wibble')
|
246
|
+
expect( prng.state ).to eql prng_copy.state
|
247
|
+
expect( prng.read_hex ).to eql prng_copy.read_hex
|
248
|
+
expect( prng.state ).to eql prng_copy.state
|
249
249
|
end
|
250
250
|
end
|
251
251
|
end
|
@@ -255,46 +255,46 @@ describe PoolOfEntropy::CorePRNG do
|
|
255
255
|
it "always returns a 128-bit unsigned integer" do
|
256
256
|
100.times do
|
257
257
|
num = prng.read_bignum
|
258
|
-
num.
|
259
|
-
num.
|
258
|
+
expect( num ).to be >= 0
|
259
|
+
expect( num ).to be < 2**128
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
263
263
|
it "has a high probability of returning a different number each time" do
|
264
|
-
Set[ *(1..100).map {prng.read_bignum} ].size.
|
264
|
+
expect( Set[ *(1..100).map {prng.read_bignum} ].size ).to eql 100
|
265
265
|
end
|
266
266
|
|
267
267
|
describe "with adjustments" do
|
268
268
|
it "always returns a 128-bit unsigned integer" do
|
269
269
|
100.times do
|
270
270
|
num = prng.read_bignum( 'Biggest' )
|
271
|
-
num.
|
272
|
-
num.
|
271
|
+
expect( num ).to be >= 0
|
272
|
+
expect( num ).to be < 2**128
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
276
276
|
it "has a high probability of returning a different number each time" do
|
277
|
-
Set[ *(1..100).map {prng.read_bignum('654321')} ].size.
|
277
|
+
expect( Set[ *(1..100).map {prng.read_bignum('654321')} ].size ).to eql 100
|
278
278
|
end
|
279
279
|
|
280
280
|
it "changes output, but does not include adjustments in changes to state" do
|
281
281
|
prng_copy = prng.clone
|
282
282
|
10.times do
|
283
|
-
prng.read_bignum('Hello!').
|
284
|
-
prng.state.
|
285
|
-
prng.read_bignum('Hello!').
|
286
|
-
prng.state.
|
287
|
-
prng.read_bignum.
|
288
|
-
prng.state.
|
289
|
-
prng.read_bignum('Hello!').
|
290
|
-
prng.state.
|
291
|
-
prng.read_bignum('Hello','Goodbye').
|
292
|
-
prng.state.
|
283
|
+
expect( prng.read_bignum('Hello!') ).to eql prng_copy.read_bignum('Hello!')
|
284
|
+
expect( prng.state ).to eql prng_copy.state
|
285
|
+
expect( prng.read_bignum('Hello!') ).to_not eql prng_copy.read_bignum('Goodbye!')
|
286
|
+
expect( prng.state ).to eql prng_copy.state
|
287
|
+
expect( prng.read_bignum ).to_not eql prng_copy.read_bignum('Goodbye!')
|
288
|
+
expect( prng.state ).to eql prng_copy.state
|
289
|
+
expect( prng.read_bignum('Hello!') ).to_not eql prng_copy.read_bignum
|
290
|
+
expect( prng.state ).to eql prng_copy.state
|
291
|
+
expect( prng.read_bignum('Hello','Goodbye') ).to_not eql prng_copy.read_bignum
|
292
|
+
expect( prng.state ).to eql prng_copy.state
|
293
293
|
# Verify that output remains same for next rolls
|
294
|
-
prng.read_bignum('Foobar','Wibble').
|
295
|
-
prng.state.
|
296
|
-
prng.read_bignum.
|
297
|
-
prng.state.
|
294
|
+
expect( prng.read_bignum('Foobar','Wibble') ).to eql prng_copy.read_bignum('Foobar','Wibble')
|
295
|
+
expect( prng.state ).to eql prng_copy.state
|
296
|
+
expect( prng.read_bignum ).to eql prng_copy.read_bignum
|
297
|
+
expect( prng.state ).to eql prng_copy.state
|
298
298
|
end
|
299
299
|
end
|
300
300
|
end
|
@@ -304,48 +304,48 @@ describe PoolOfEntropy::CorePRNG do
|
|
304
304
|
it "always returns a Float between 0.0 (inclusive) and 1.0 (exclusive)" do
|
305
305
|
100.times do
|
306
306
|
num = prng.read_float
|
307
|
-
num.
|
308
|
-
num.
|
309
|
-
num.
|
307
|
+
expect( num ).to be_a Float
|
308
|
+
expect( num ).to be >= 0.0
|
309
|
+
expect( num ).to be < 1.0
|
310
310
|
end
|
311
311
|
end
|
312
312
|
|
313
313
|
it "has a high probability of returning a different Float each time" do
|
314
|
-
Set[ *(1..100).map {prng.read_float} ].size.
|
314
|
+
expect( Set[ *(1..100).map {prng.read_float} ].size ).to eql 100
|
315
315
|
end
|
316
316
|
|
317
317
|
describe "with adjustments" do
|
318
318
|
it "always returns a Float between 0.0 (inclusive) and 1.0 (exclusive)" do
|
319
319
|
100.times do
|
320
320
|
num = prng.read_float('Boom')
|
321
|
-
num.
|
322
|
-
num.
|
323
|
-
num.
|
321
|
+
expect( num ).to be_a Float
|
322
|
+
expect( num ).to be >= 0.0
|
323
|
+
expect( num ).to be < 1.0
|
324
324
|
end
|
325
325
|
end
|
326
326
|
|
327
327
|
it "has a high probability of returning a different Float each time" do
|
328
|
-
Set[ *(1..100).map {prng.read_float('654321')} ].size.
|
328
|
+
expect( Set[ *(1..100).map {prng.read_float('654321')} ].size ).to eql 100
|
329
329
|
end
|
330
330
|
|
331
331
|
it "changes output, but does not include adjustments in changes to state" do
|
332
332
|
prng_copy = prng.clone
|
333
333
|
10.times do
|
334
|
-
prng.read_float('Hello!').
|
335
|
-
prng.state.
|
336
|
-
prng.read_float('Hello!').
|
337
|
-
prng.state.
|
338
|
-
prng.read_float.
|
339
|
-
prng.state.
|
340
|
-
prng.read_float('Hello!').
|
341
|
-
prng.state.
|
342
|
-
prng.read_float('Hello','Goodbye').
|
343
|
-
prng.state.
|
334
|
+
expect( prng.read_float('Hello!') ).to eql prng_copy.read_float('Hello!')
|
335
|
+
expect( prng.state ).to eql prng_copy.state
|
336
|
+
expect( prng.read_float('Hello!') ).to_not eql prng_copy.read_float('Goodbye!')
|
337
|
+
expect( prng.state ).to eql prng_copy.state
|
338
|
+
expect( prng.read_float ).to_not eql prng_copy.read_float('Goodbye!')
|
339
|
+
expect( prng.state ).to eql prng_copy.state
|
340
|
+
expect( prng.read_float('Hello!') ).to_not eql prng_copy.read_float
|
341
|
+
expect( prng.state ).to eql prng_copy.state
|
342
|
+
expect( prng.read_float('Hello','Goodbye') ).to_not eql prng_copy.read_float
|
343
|
+
expect( prng.state ).to eql prng_copy.state
|
344
344
|
# Verify that output remains same for next rolls
|
345
|
-
prng.read_float('Foobar','Wibble').
|
346
|
-
prng.state.
|
347
|
-
prng.read_float.
|
348
|
-
prng.state.
|
345
|
+
expect( prng.read_float('Foobar','Wibble') ).to eql prng_copy.read_float('Foobar','Wibble')
|
346
|
+
expect( prng.state ).to eql prng_copy.state
|
347
|
+
expect( prng.read_float ).to eql prng_copy.read_float
|
348
|
+
expect( prng.state ).to eql prng_copy.state
|
349
349
|
end
|
350
350
|
end
|
351
351
|
end
|
@@ -355,84 +355,84 @@ describe PoolOfEntropy::CorePRNG do
|
|
355
355
|
it "always returns an integer between 0 (inclusive) and supplied top (exclusive)" do
|
356
356
|
100.times do
|
357
357
|
num = prng.generate_integer( 10 )
|
358
|
-
num.
|
359
|
-
num.
|
360
|
-
num.
|
358
|
+
expect( num ).to be_a Fixnum
|
359
|
+
expect( num ).to be >= 0
|
360
|
+
expect( num ).to be < 10
|
361
361
|
end
|
362
362
|
|
363
363
|
100.times do
|
364
364
|
num = prng.generate_integer( 100 )
|
365
|
-
num.
|
366
|
-
num.
|
367
|
-
num.
|
365
|
+
expect( num ).to be_a Fixnum
|
366
|
+
expect( num ).to be >= 0
|
367
|
+
expect( num ).to be < 100
|
368
368
|
end
|
369
369
|
|
370
370
|
100.times do
|
371
371
|
num = prng.generate_integer( 1000 )
|
372
|
-
num.
|
373
|
-
num.
|
374
|
-
num.
|
372
|
+
expect( num ).to be_a Fixnum
|
373
|
+
expect( num ).to be >= 0
|
374
|
+
expect( num ).to be < 1000
|
375
375
|
end
|
376
376
|
|
377
377
|
100.times do
|
378
378
|
num = prng.generate_integer( 647218456 )
|
379
|
-
num.
|
380
|
-
num.
|
381
|
-
num.
|
379
|
+
expect( num ).to be_a Fixnum
|
380
|
+
expect( num ).to be >= 0
|
381
|
+
expect( num ).to be < 647218456
|
382
382
|
end
|
383
383
|
end
|
384
384
|
|
385
385
|
it "can generate integers larger than 2**128" do
|
386
386
|
results = (0..100).map do
|
387
387
|
num = prng.generate_integer( 2 ** 1024 )
|
388
|
-
num.
|
389
|
-
num.
|
388
|
+
expect( num ).to be >= 0
|
389
|
+
expect( num ).to be < 2 ** 1024
|
390
390
|
num
|
391
391
|
end
|
392
|
-
results.select { |n| n > 2 ** 1020 }.count.
|
392
|
+
expect( results.select { |n| n > 2 ** 1020 }.count ).to be > 50
|
393
393
|
end
|
394
394
|
|
395
395
|
it "with a large enough value for top, has a high probability of returning a different integer each time" do
|
396
|
-
Set[ *(1..100).map {prng.generate_integer( 2**75 - 7 )} ].size.
|
396
|
+
expect( Set[ *(1..100).map {prng.generate_integer( 2**75 - 7 )} ].size ).to eql 100
|
397
397
|
end
|
398
398
|
|
399
399
|
it "covers a distribution 0...top" do
|
400
|
-
Set[ *(1..100).map {prng.generate_integer(10)} ].size.
|
400
|
+
expect( Set[ *(1..100).map {prng.generate_integer(10)} ].size ).to eql 10
|
401
401
|
end
|
402
402
|
|
403
403
|
describe "with adjustments" do
|
404
404
|
it "always returns an integer between 0 (inclusive) and supplied top (exclusive)" do
|
405
405
|
100.times do
|
406
406
|
num = prng.generate_integer( 10, 'jkffwe' )
|
407
|
-
num.
|
408
|
-
num.
|
409
|
-
num.
|
407
|
+
expect( num ).to be_a Fixnum
|
408
|
+
expect( num ).to be >= 0
|
409
|
+
expect( num ).to be < 10
|
410
410
|
end
|
411
411
|
|
412
412
|
100.times do
|
413
413
|
num = prng.generate_integer( 100, 'jkffweefewg' )
|
414
|
-
num.
|
415
|
-
num.
|
416
|
-
num.
|
414
|
+
expect( num ).to be_a Fixnum
|
415
|
+
expect( num ).to be >= 0
|
416
|
+
expect( num ).to be < 100
|
417
417
|
end
|
418
418
|
|
419
419
|
100.times do
|
420
420
|
num = prng.generate_integer( 1000, 'jkffweefewg', 'efhwjkfgw' )
|
421
|
-
num.
|
422
|
-
num.
|
423
|
-
num.
|
421
|
+
expect( num ).to be_a Fixnum
|
422
|
+
expect( num ).to be >= 0
|
423
|
+
expect( num ).to be < 1000
|
424
424
|
end
|
425
425
|
|
426
426
|
100.times do
|
427
427
|
num = prng.generate_integer( 647218456, 'j*****g', 'efhwjkfgw' )
|
428
|
-
num.
|
429
|
-
num.
|
430
|
-
num.
|
428
|
+
expect( num ).to be_a Fixnum
|
429
|
+
expect( num ).to be >= 0
|
430
|
+
expect( num ).to be < 647218456
|
431
431
|
end
|
432
432
|
end
|
433
433
|
|
434
434
|
it "with a large enough value for top, has a high probability of returning a different integer each time" do
|
435
|
-
Set[ *(1..100).map {prng.generate_integer( 2**80 - 5, '654321')} ].size.
|
435
|
+
expect( Set[ *(1..100).map {prng.generate_integer( 2**80 - 5, '654321')} ].size ).to eql 100
|
436
436
|
end
|
437
437
|
|
438
438
|
it "changes output, but does not include adjustments in changes to state" do
|
@@ -440,21 +440,21 @@ describe PoolOfEntropy::CorePRNG do
|
|
440
440
|
big = 2 ** 64 - 3
|
441
441
|
small = 20
|
442
442
|
10.times do
|
443
|
-
prng.generate_integer( small, 'Hello!').
|
444
|
-
prng.state.
|
445
|
-
prng.generate_integer( big, 'Hello!').
|
446
|
-
prng.state.
|
447
|
-
prng.generate_integer( big ).
|
448
|
-
prng.state.
|
449
|
-
prng.generate_integer( big, 'Hello!').
|
450
|
-
prng.state.
|
451
|
-
prng.generate_integer( big, 'Hello','Goodbye').
|
452
|
-
prng.state.
|
443
|
+
expect( prng.generate_integer( small, 'Hello!') ).to eql prng_copy.generate_integer( small, 'Hello!')
|
444
|
+
expect( prng.state ).to eql prng_copy.state
|
445
|
+
expect( prng.generate_integer( big, 'Hello!') ).to_not eql prng_copy.generate_integer( big, 'Goodbye!')
|
446
|
+
expect( prng.state ).to eql prng_copy.state
|
447
|
+
expect( prng.generate_integer( big ) ).to_not eql prng_copy.generate_integer( big, 'Goodbye!')
|
448
|
+
expect( prng.state ).to eql prng_copy.state
|
449
|
+
expect( prng.generate_integer( big, 'Hello!') ).to_not eql prng_copy.generate_integer( big )
|
450
|
+
expect( prng.state ).to eql prng_copy.state
|
451
|
+
expect( prng.generate_integer( big, 'Hello','Goodbye') ).to_not eql prng_copy.generate_integer( big )
|
452
|
+
expect( prng.state ).to eql prng_copy.state
|
453
453
|
# Verify that output remains same for next rolls
|
454
|
-
prng.generate_integer( small, 'Foobar','Wibble').
|
455
|
-
prng.state.
|
456
|
-
prng.generate_integer( big ).
|
457
|
-
prng.state.
|
454
|
+
expect( prng.generate_integer( small, 'Foobar','Wibble') ).to eql prng_copy.generate_integer( small, 'Foobar','Wibble')
|
455
|
+
expect( prng.state ).to eql prng_copy.state
|
456
|
+
expect( prng.generate_integer( big ) ).to eql prng_copy.generate_integer( big )
|
457
|
+
expect( prng.state ).to eql prng_copy.state
|
458
458
|
end
|
459
459
|
end
|
460
460
|
end
|
@@ -474,10 +474,10 @@ describe PoolOfEntropy::CorePRNG do
|
|
474
474
|
:int => prngs[4].generate_integer( 1_000_000_000 ),
|
475
475
|
]
|
476
476
|
end
|
477
|
-
results.sort_by { |h| h[:int] }.
|
478
|
-
results.sort_by { |h| h[:float] }.
|
479
|
-
results.sort_by { |h| h[:num] }.
|
480
|
-
results.sort_by { |h| h[:float] }.
|
477
|
+
expect( results.sort_by { |h| h[:int] } ).to eql results.sort_by { |h| h[:hex] }
|
478
|
+
expect( results.sort_by { |h| h[:float] } ).to eql results.sort_by { |h| h[:hex] }
|
479
|
+
expect( results.sort_by { |h| h[:num] } ).to eql results.sort_by { |h| h[:bytes] }
|
480
|
+
expect( results.sort_by { |h| h[:float] } ).to eql results.sort_by { |h| h[:int] }
|
481
481
|
end
|
482
482
|
end
|
483
483
|
|
@@ -487,7 +487,7 @@ describe PoolOfEntropy::CorePRNG do
|
|
487
487
|
describe "using predictable sequences" do
|
488
488
|
it "generates expected hex strings from simple zeroed pool" do
|
489
489
|
prng = PoolOfEntropy::CorePRNG.new( 1, "\x0" * 64 )
|
490
|
-
(0..24).map { prng.read_hex }.
|
490
|
+
expect( (0..24).map { prng.read_hex } ).to eql [ "da0cd77eb1c84458ddcc91e36b9dcb35",
|
491
491
|
"498ec24d1126440047eed396d836b5e1", "0b90df55c5e7c1513b072367eae4a4ce",
|
492
492
|
"f12b5b54b5594e785bbb9a4ac50ccec8", "d506bd4e201a00dc30499bd8e59a30d8",
|
493
493
|
"2557893cf995fe43bd00721fce6ab16a", "41ee50244cdd02334bafc3e9d8f564d9",
|
@@ -504,7 +504,7 @@ describe PoolOfEntropy::CorePRNG do
|
|
504
504
|
|
505
505
|
it "generates expected hex strings from simple zeroed pool and an adjustment" do
|
506
506
|
prng = PoolOfEntropy::CorePRNG.new( 1, "\x0" * 64 )
|
507
|
-
(0..24).map { prng.read_hex( 'bananas' ) }.
|
507
|
+
expect( (0..24).map { prng.read_hex( 'bananas' ) } ).to eql [
|
508
508
|
"fed9de9a612f4157ebb49582ca557a50", "a7adc2374a4df2ed67846ac09a3b6645",
|
509
509
|
"cbdf8bbbe6145751fe14004719915160", "8cd84be95376f72918c305bdea43e36d",
|
510
510
|
"9e08e80ff40c942f0cf4d479b5378fa0", "54d80c5330873f9733a0adef0197220f",
|
@@ -522,7 +522,7 @@ describe PoolOfEntropy::CorePRNG do
|
|
522
522
|
|
523
523
|
it "generates expected hex strings from simple zeroed pool and alternating adjustments" do
|
524
524
|
prng = PoolOfEntropy::CorePRNG.new( 1, "\x0" * 64 )
|
525
|
-
(0..24).map { |x| x.odd? ? prng.read_hex( 'bananas', x.to_s ) : prng.read_hex }.
|
525
|
+
expect( (0..24).map { |x| x.odd? ? prng.read_hex( 'bananas', x.to_s ) : prng.read_hex } ).to eql [
|
526
526
|
"da0cd77eb1c84458ddcc91e36b9dcb35", "de4b20a0560263090c6fe11ebba6256e",
|
527
527
|
"0b90df55c5e7c1513b072367eae4a4ce", "0c92d534160cb268cb3282a9dd3f1efe",
|
528
528
|
"d506bd4e201a00dc30499bd8e59a30d8", "089f799236a9cf64f22f1deafbe28214",
|
@@ -6,17 +6,17 @@ describe PoolOfEntropy do
|
|
6
6
|
describe "#new" do
|
7
7
|
it "should instantiate a default object" do
|
8
8
|
pool = PoolOfEntropy.new
|
9
|
-
pool.
|
9
|
+
expect( pool ).to be_a PoolOfEntropy
|
10
10
|
end
|
11
11
|
|
12
12
|
it "should allow setting number of blocks in pool" do
|
13
13
|
[1,3,5,8,13,21,34,55,89,144,233].each do |s|
|
14
14
|
pool = PoolOfEntropy.new( :size => 12 )
|
15
|
-
pool.
|
15
|
+
expect( pool ).to be_a PoolOfEntropy
|
16
16
|
num = pool.rand()
|
17
|
-
num.
|
18
|
-
num.
|
19
|
-
num.
|
17
|
+
expect( num ).to be_a Float
|
18
|
+
expect( num ).to be >= 0.0
|
19
|
+
expect( num ).to be < 1.0
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -38,30 +38,30 @@ describe PoolOfEntropy do
|
|
38
38
|
|
39
39
|
it "should default to unpredicatble internal state" do
|
40
40
|
pool = PoolOfEntropy.new()
|
41
|
-
pool.
|
42
|
-
(10..20).map { |x| pool.rand(x) }.
|
41
|
+
expect( pool ).to be_a PoolOfEntropy
|
42
|
+
expect( (10..20).map { |x| pool.rand(x) } ).to_not eql [8, 3, 0, 12, 11, 2, 4, 8, 1, 11, 18]
|
43
43
|
end
|
44
44
|
|
45
45
|
it "should accept { :blank => false } as explicit statement of default" do
|
46
46
|
pool = PoolOfEntropy.new( :blank => false )
|
47
|
-
pool.
|
48
|
-
(10..20).map { |x| pool.rand(x) }.
|
47
|
+
expect( pool ).to be_a PoolOfEntropy
|
48
|
+
expect( (10..20).map { |x| pool.rand(x) } ).to_not eql [8, 3, 0, 12, 11, 2, 4, 8, 1, 11, 18]
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should allow an initial blank internal state" do
|
52
52
|
pool = PoolOfEntropy.new( :blank => true )
|
53
|
-
pool.
|
54
|
-
(10..20).map { |x| pool.rand(x) }.
|
53
|
+
expect( pool ).to be_a PoolOfEntropy
|
54
|
+
expect( (10..20).map { |x| pool.rand(x) } ).to eql [8, 3, 0, 12, 11, 2, 4, 8, 1, 11, 18]
|
55
55
|
end
|
56
56
|
|
57
57
|
it "should accept and use :seeds array" do
|
58
58
|
pool = PoolOfEntropy.new( :blank => true, :seeds => ['foo'] )
|
59
|
-
pool.
|
60
|
-
(10..20).map { |x| pool.rand(x) }.
|
59
|
+
expect( pool ).to be_a PoolOfEntropy
|
60
|
+
expect( (10..20).map { |x| pool.rand(x) } ).to eql [9, 1, 3, 7, 8, 12, 14, 5, 11, 5, 6]
|
61
61
|
|
62
62
|
pool = PoolOfEntropy.new( :blank => true, :seeds => ['foo', 'bar'] )
|
63
|
-
pool.
|
64
|
-
(10..20).map { |x| pool.rand(x) }.
|
63
|
+
expect( pool ).to be_a PoolOfEntropy
|
64
|
+
expect( (10..20).map { |x| pool.rand(x) } ).to eql [8, 1, 5, 8, 2, 7, 11, 8, 8, 13, 14]
|
65
65
|
end
|
66
66
|
|
67
67
|
it "should fail if :seeds param is not an array" do
|
@@ -117,7 +117,7 @@ describe PoolOfEntropy do
|
|
117
117
|
|
118
118
|
pool_copy = pool.clone
|
119
119
|
100.times do
|
120
|
-
pool_copy.rand().
|
120
|
+
expect( pool_copy.rand() ).to eql pool.rand()
|
121
121
|
end
|
122
122
|
end
|
123
123
|
end
|
@@ -128,20 +128,20 @@ describe PoolOfEntropy do
|
|
128
128
|
it "should call PoolOfEntropy::CorePRNG::read_bytes internally" do
|
129
129
|
allow_any_instance_of( PoolOfEntropy::CorePRNG).
|
130
130
|
to receive( :read_bytes ).and_return( "\x1e\xfe" * 8 )
|
131
|
-
20.times { pool.rand.
|
131
|
+
20.times { expect( pool.rand ).to eql 0.12106507972838931 }
|
132
132
|
end
|
133
133
|
|
134
134
|
it "should return a Float between 0.0 and 1.0" do
|
135
135
|
100.times do
|
136
136
|
num = pool.rand
|
137
|
-
num.
|
138
|
-
num.
|
139
|
-
num.
|
137
|
+
expect( num ).to be_a Float
|
138
|
+
expect( num ).to be >= 0.0
|
139
|
+
expect( num ).to be < 1.0
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
143
143
|
it "should return a different Float each time (with high probability) " do
|
144
|
-
Set[ *(1..100).map{ pool.rand } ].size.
|
144
|
+
expect( Set[ *(1..100).map{ pool.rand } ].size ).to eql 100
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
@@ -149,27 +149,27 @@ describe PoolOfEntropy do
|
|
149
149
|
it "should call PoolOfEntropy::CorePRNG::read_bytes internally" do
|
150
150
|
allow_any_instance_of( PoolOfEntropy::CorePRNG).
|
151
151
|
to receive( :read_bytes ).and_return( "\x1e\xfe" * 8 )
|
152
|
-
20.times { pool.rand(20).
|
152
|
+
20.times { expect( pool.rand(20) ).to eql 2 }
|
153
153
|
end
|
154
154
|
|
155
155
|
it "should return an Integer between 0 and x (excluding x)" do
|
156
156
|
[ 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 ].each do |x|
|
157
157
|
100.times do
|
158
158
|
num = pool.rand( x )
|
159
|
-
num.
|
160
|
-
num.
|
161
|
-
num.
|
159
|
+
expect( num ).to be_a Fixnum
|
160
|
+
expect( num ).to be >= 0
|
161
|
+
expect( num ).to be < x
|
162
162
|
end
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
166
|
# This is a very weak test of randomness, see DIEHARDER_TEST.md
|
167
167
|
it "should select values without obvious bias" do
|
168
|
-
Set[ *(1..200).map{ pool.rand( 20 ) } ].size.
|
168
|
+
expect( Set[ *(1..200).map{ pool.rand( 20 ) } ].size ).to eql 20
|
169
169
|
end
|
170
170
|
|
171
171
|
it "should return a different Integer each time (with high probability for large x) " do
|
172
|
-
Set[ *(1..100).map{ pool.rand( 2**64 ) } ].size.
|
172
|
+
expect( Set[ *(1..100).map{ pool.rand( 2**64 ) } ].size ).to eql 100
|
173
173
|
end
|
174
174
|
end
|
175
175
|
|
@@ -177,22 +177,22 @@ describe PoolOfEntropy do
|
|
177
177
|
it "should call PoolOfEntropy::CorePRNG::read_bytes internally" do
|
178
178
|
allow_any_instance_of( PoolOfEntropy::CorePRNG).
|
179
179
|
to receive( :read_bytes ).and_return( "\x1e\xfe" * 8 )
|
180
|
-
20.times { pool.rand( 7..28 ).
|
180
|
+
20.times { expect( pool.rand( 7..28 ) ).to eql 9 }
|
181
181
|
end
|
182
182
|
|
183
183
|
it "should return an Integer that is a member of the range" do
|
184
184
|
[ 1..2, 2..5, 3..8, 5..13, 21..34, 55..89 ].each do |r|
|
185
185
|
100.times do
|
186
186
|
num = pool.rand( r )
|
187
|
-
num.
|
188
|
-
num.
|
189
|
-
num.
|
187
|
+
expect( num ).to be_a Fixnum
|
188
|
+
expect( num ).to be >= r.min
|
189
|
+
expect( num ).to be <= r.max
|
190
190
|
end
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
194
|
it "should return a different Integer each time (with high probability for large range) " do
|
195
|
-
Set[ *(1..100).map{ pool.rand( 100000000000..200000000000 ) } ].size.
|
195
|
+
expect( Set[ *(1..100).map{ pool.rand( 100000000000..200000000000 ) } ].size ).to eql 100
|
196
196
|
end
|
197
197
|
|
198
198
|
end
|
@@ -205,7 +205,7 @@ describe PoolOfEntropy do
|
|
205
205
|
pool_copy = pool.clone
|
206
206
|
100.times do
|
207
207
|
modifier = SecureRandom.hex
|
208
|
-
pool_copy.modify_next( modifier ).rand.
|
208
|
+
expect( pool_copy.modify_next( modifier ).rand ).to_not eql pool.rand
|
209
209
|
end
|
210
210
|
end
|
211
211
|
|
@@ -213,7 +213,7 @@ describe PoolOfEntropy do
|
|
213
213
|
pool_copy = pool.clone
|
214
214
|
100.times do
|
215
215
|
modifier = SecureRandom.hex
|
216
|
-
pool_copy.modify_next( modifier ).rand.
|
216
|
+
expect( pool_copy.modify_next( modifier ).rand ).to eql pool.modify_next( modifier ).rand
|
217
217
|
end
|
218
218
|
end
|
219
219
|
|
@@ -221,8 +221,8 @@ describe PoolOfEntropy do
|
|
221
221
|
pool_copy = pool.clone
|
222
222
|
100.times do
|
223
223
|
modifier = SecureRandom.hex
|
224
|
-
pool_copy.modify_next( modifier ).rand.
|
225
|
-
pool_copy.rand.
|
224
|
+
expect( pool_copy.modify_next( modifier ).rand ).to_not eql pool.rand
|
225
|
+
expect( pool_copy.rand ).to eql pool.rand
|
226
226
|
end
|
227
227
|
end
|
228
228
|
|
@@ -234,20 +234,20 @@ describe PoolOfEntropy do
|
|
234
234
|
# Syntax for all-at-once
|
235
235
|
pool_copy.modify_next( *modifiers )
|
236
236
|
modifiers.each do |modifier|
|
237
|
-
pool_copy.rand.
|
237
|
+
expect( pool_copy.rand ).to eql pool.modify_next( modifier ).rand
|
238
238
|
end
|
239
239
|
# Assert we're back in sync without modifiers
|
240
|
-
pool_copy.rand.
|
240
|
+
expect( pool_copy.rand ).to eql pool.rand
|
241
241
|
|
242
242
|
# Adding to queue one-at-a-time
|
243
243
|
modifiers.each do |modifier|
|
244
244
|
pool_copy.modify_next( modifier )
|
245
245
|
end
|
246
246
|
modifiers.each do |modifier|
|
247
|
-
pool_copy.rand.
|
247
|
+
expect( pool_copy.rand ).to eql pool.modify_next( modifier ).rand
|
248
248
|
end
|
249
249
|
# Assert we're back in sync without modifiers
|
250
|
-
pool_copy.rand.
|
250
|
+
expect( pool_copy.rand ).to eql pool.rand
|
251
251
|
end
|
252
252
|
end
|
253
253
|
|
@@ -255,11 +255,11 @@ describe PoolOfEntropy do
|
|
255
255
|
pool_copy = pool.clone
|
256
256
|
10.times do
|
257
257
|
pool_copy.modify_next( 'hello', nil, 'goodbye' )
|
258
|
-
pool_copy.rand.
|
259
|
-
pool_copy.rand.
|
260
|
-
pool_copy.rand.
|
261
|
-
pool_copy.rand.
|
262
|
-
pool_copy.rand.
|
258
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
259
|
+
expect( pool_copy.rand ).to eql pool.rand
|
260
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
261
|
+
expect( pool_copy.rand ).to eql pool.rand
|
262
|
+
expect( pool_copy.rand ).to eql pool.rand
|
263
263
|
end
|
264
264
|
end
|
265
265
|
end # modify_next
|
@@ -269,9 +269,9 @@ describe PoolOfEntropy do
|
|
269
269
|
pool_copy = pool.clone
|
270
270
|
10.times do
|
271
271
|
modifier = SecureRandom.hex
|
272
|
-
pool_copy.modify_all( modifier ).rand.
|
272
|
+
expect( pool_copy.modify_all( modifier ).rand ).to_not eql pool.rand
|
273
273
|
10.times do
|
274
|
-
pool_copy.rand.
|
274
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
275
275
|
end
|
276
276
|
end
|
277
277
|
end
|
@@ -280,9 +280,9 @@ describe PoolOfEntropy do
|
|
280
280
|
pool_copy = pool.clone
|
281
281
|
10.times do
|
282
282
|
modifier = SecureRandom.hex
|
283
|
-
pool_copy.modify_all( modifier ).rand.
|
283
|
+
expect( pool_copy.modify_all( modifier ).rand ).to eql pool.modify_all( modifier ).rand
|
284
284
|
10.times do
|
285
|
-
pool_copy.rand.
|
285
|
+
expect( pool_copy.rand ).to eql pool.rand
|
286
286
|
end
|
287
287
|
end
|
288
288
|
end
|
@@ -291,7 +291,7 @@ describe PoolOfEntropy do
|
|
291
291
|
pool_copy = pool.clone
|
292
292
|
100.times do
|
293
293
|
modifier = SecureRandom.hex
|
294
|
-
pool_copy.modify_all( modifier ).rand.
|
294
|
+
expect( pool_copy.modify_all( modifier ).rand ).to eql pool.modify_next( modifier ).rand
|
295
295
|
end
|
296
296
|
end
|
297
297
|
|
@@ -299,11 +299,11 @@ describe PoolOfEntropy do
|
|
299
299
|
pool_copy = pool.clone
|
300
300
|
10.times do
|
301
301
|
modifier = SecureRandom.hex
|
302
|
-
pool_copy.modify_all( modifier ).rand.
|
303
|
-
pool_copy.rand.
|
302
|
+
expect( pool_copy.modify_all( modifier ).rand ).to_not eql pool.rand
|
303
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
304
304
|
pool_copy.modify_all( nil )
|
305
305
|
10.times do
|
306
|
-
pool_copy.rand.
|
306
|
+
expect( pool_copy.rand ).to eql pool.rand
|
307
307
|
end
|
308
308
|
end
|
309
309
|
end
|
@@ -317,10 +317,10 @@ describe PoolOfEntropy do
|
|
317
317
|
10.times do
|
318
318
|
modifiers = (0..5).map { SecureRandom.hex }
|
319
319
|
pool_copy.modify_next( *modifiers )
|
320
|
-
pool_copy.rand.
|
320
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
321
321
|
pool_copy.clear_all_modifiers
|
322
322
|
10.times do
|
323
|
-
pool_copy.rand.
|
323
|
+
expect( pool_copy.rand ).to eql pool.rand
|
324
324
|
end
|
325
325
|
end
|
326
326
|
end
|
@@ -329,11 +329,11 @@ describe PoolOfEntropy do
|
|
329
329
|
pool_copy = pool.clone
|
330
330
|
10.times do
|
331
331
|
modifier = SecureRandom.hex
|
332
|
-
pool_copy.modify_all( modifier ).rand.
|
333
|
-
pool_copy.rand.
|
332
|
+
expect( pool_copy.modify_all( modifier ).rand ).to_not eql pool.rand
|
333
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
334
334
|
pool_copy.clear_all_modifiers
|
335
335
|
10.times do
|
336
|
-
pool_copy.rand.
|
336
|
+
expect( pool_copy.rand ).to eql pool.rand
|
337
337
|
end
|
338
338
|
end
|
339
339
|
end
|
@@ -343,11 +343,11 @@ describe PoolOfEntropy do
|
|
343
343
|
10.times do
|
344
344
|
modifier = SecureRandom.hex
|
345
345
|
pool_copy.modify_next( *(0..5).map { SecureRandom.hex } )
|
346
|
-
pool_copy.modify_all( modifier ).rand.
|
347
|
-
pool_copy.rand.
|
346
|
+
expect( pool_copy.modify_all( modifier ).rand ).to_not eql pool.rand
|
347
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
348
348
|
pool_copy.clear_all_modifiers
|
349
349
|
10.times do
|
350
|
-
pool_copy.rand.
|
350
|
+
expect( pool_copy.rand ).to eql pool.rand
|
351
351
|
end
|
352
352
|
end
|
353
353
|
end
|
@@ -359,7 +359,7 @@ describe PoolOfEntropy do
|
|
359
359
|
pool_copy = pool.clone
|
360
360
|
pool_copy.add_to_pool( 'Some user data!' )
|
361
361
|
100.times do
|
362
|
-
pool_copy.rand.
|
362
|
+
expect( pool_copy.rand ).to_not eql pool.rand
|
363
363
|
end
|
364
364
|
end
|
365
365
|
|
@@ -372,7 +372,7 @@ describe PoolOfEntropy do
|
|
372
372
|
pool.add_to_pool( user_data )
|
373
373
|
|
374
374
|
10.times do
|
375
|
-
pool_copy.rand.
|
375
|
+
expect( pool_copy.rand ).to eql pool.rand
|
376
376
|
end
|
377
377
|
end
|
378
378
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pool_of_entropy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Neil Slater
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yard
|