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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 23271d0dc1c22f357e9a6f80b9b2ea3437d085f8
4
- data.tar.gz: 4d8285af029c793e6e9146d73d58d18bac70e43d
3
+ metadata.gz: 19f44541d4ae2cc3d474a5dd4d08d40a439911d6
4
+ data.tar.gz: 1ca34b3ff58b59e0064c558107281dfb053cd289
5
5
  SHA512:
6
- metadata.gz: 704d5ede09b0cbb603c17bc5b5b017cf82f66767b73a5c3d9548b2e7a79b6da17460213dcbaa9d4b9a0aed2c61bf2b5e2bf88b9dd718f4b08d8464be47222975
7
- data.tar.gz: 6523421fa314649fdbe373b19798320221581275ab4e418b2c957159c75285451569000eadac14acada8f781d35577b174370766577a5dee255306f845d5de9d
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 by using:
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
- #An accessor for the depth!
33
+ #The depth of the Fibonacci array.
38
34
  attr_reader :depth
39
35
 
40
- #An accessor for the seed value!
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
- @hidden.dice(1 + max.max - min) + min
66
- elsif max == 0
67
- @hidden.float
59
+ dice(1 + max.max - min) + min
60
+ elsif max.zero?
61
+ float
68
62
  else
69
- @hidden.dice(max.to_i)
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
@@ -2,5 +2,5 @@
2
2
 
3
3
  #The class of Fibonacci inspired random number generators.
4
4
  class FibonacciRng
5
- VERSION = "0.0.8"
5
+ VERSION = "0.1.0"
6
6
  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: 0.0.8
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-02-18 00:00:00.000000000 Z
11
+ date: 2016-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest_visible