fibonacci_rng 0.0.8 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -2
- data/lib/fibonacci_rng.rb +19 -16
- data/lib/fibonacci_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: 19f44541d4ae2cc3d474a5dd4d08d40a439911d6
|
4
|
+
data.tar.gz: 1ca34b3ff58b59e0064c558107281dfb053cd289
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20d6b5c324da8f31b804584f7862fe470cd669aaca2082c5f64c321a606e84bf528c76199d2b1f6980d80a0e60321b46489db613d7037332aaead28468d4c1da
|
7
|
+
data.tar.gz: 07fc2949e518d780f3a938440354ab4c0f2d30ba0a3600c3b44c77b07d29d88f6480c024a27d5774bccb55da352d4b825082bb6e497e1d2e34418c5abff87cab
|
data/README.md
CHANGED
@@ -29,9 +29,10 @@ Then in an appropriate place in the code:
|
|
29
29
|
|
30
30
|
@my_rng = FibonacciRng.new(depth, seed_value)
|
31
31
|
|
32
|
-
Where depth is an optional integer value between 3 and are you kidding and
|
32
|
+
Where depth is an optional integer value between 3 and "are you kidding" and
|
33
33
|
the seed value is a number or string or other object that has a repeatable
|
34
|
-
value. You can also get a "random" generator of the default depth
|
34
|
+
value. You can also get a "random" generator of the default depth (8) and a
|
35
|
+
randomized seed by using:
|
35
36
|
|
36
37
|
@my_rng = FibonacciRng.new
|
37
38
|
|
data/lib/fibonacci_rng.rb
CHANGED
@@ -5,17 +5,11 @@ require "fibonacci_rng/version"
|
|
5
5
|
#The class of Fibonacci inspired random number generators.
|
6
6
|
class FibonacciRng
|
7
7
|
|
8
|
-
#A class instance variable to hold the tickle value.
|
9
|
-
@tickle = '0'
|
10
|
-
|
11
|
-
#Create the default seed string.
|
12
|
-
def self.new_seed
|
13
|
-
Time.now.to_s + @tickle.succ!
|
14
|
-
end
|
15
|
-
|
16
8
|
#Get a random number from the class based generator. This exists only
|
17
9
|
#for compatibility purposes. It is far better to create instances of
|
18
10
|
#generators than to use a shared, global one.
|
11
|
+
#<br>Returns
|
12
|
+
#* The computed pseudo-random value.
|
19
13
|
def self.rand(max=0)
|
20
14
|
(@hidden ||= FibonacciRng.new).rand(max)
|
21
15
|
end
|
@@ -23,6 +17,8 @@ class FibonacciRng
|
|
23
17
|
#Initialize the class based generator. This exists only
|
24
18
|
#for compatibility purposes. It is far better to create instances of
|
25
19
|
#generators than to use a shared, global one.
|
20
|
+
#<br>Returns
|
21
|
+
#* The old seed value.
|
26
22
|
def self.srand(seed=FibonacciRng.new_seed, depth=8)
|
27
23
|
old = (@hidden && @hidden.seed)
|
28
24
|
@hidden = FibonacciRng.new(seed, depth)
|
@@ -34,10 +30,10 @@ class FibonacciRng
|
|
34
30
|
WORD = 0xFFFF
|
35
31
|
BASE = (CHOP+1).to_f
|
36
32
|
|
37
|
-
#
|
33
|
+
#The depth of the Fibonacci array.
|
38
34
|
attr_reader :depth
|
39
35
|
|
40
|
-
#
|
36
|
+
#The seed value used by this generator.
|
41
37
|
attr_reader :seed
|
42
38
|
|
43
39
|
#Initialize the PRN generator
|
@@ -58,15 +54,13 @@ class FibonacciRng
|
|
58
54
|
|
59
55
|
#A (mostly) compatible access point for random numbers.
|
60
56
|
def rand(max=0)
|
61
|
-
@hidden ||= FibonacciRng.new
|
62
|
-
|
63
57
|
if max.is_a?(Range)
|
64
58
|
min = max.min
|
65
|
-
|
66
|
-
elsif max
|
67
|
-
|
59
|
+
dice(1 + max.max - min) + min
|
60
|
+
elsif max.zero?
|
61
|
+
float
|
68
62
|
else
|
69
|
-
|
63
|
+
dice(max.to_i)
|
70
64
|
end
|
71
65
|
end
|
72
66
|
|
@@ -114,6 +108,15 @@ class FibonacciRng
|
|
114
108
|
end
|
115
109
|
|
116
110
|
private
|
111
|
+
|
112
|
+
#A class instance variable to hold the tickle value.
|
113
|
+
@tickle = '0'
|
114
|
+
|
115
|
+
#Create the default seed string.
|
116
|
+
def self.new_seed
|
117
|
+
Time.now.to_s + @tickle.succ!
|
118
|
+
end
|
119
|
+
|
117
120
|
#Do the work of reseeding the PRNG
|
118
121
|
def do_reseed(indxsrc, seedsrc)
|
119
122
|
1024.times do
|
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: 0.0
|
4
|
+
version: 0.1.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-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest_visible
|