fibonacci_rng 1.0.1 → 1.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: 21f5b3081ee28c32daf5ae90cba9e99cb2d7343b
4
- data.tar.gz: bfa73f2a5979e51fb5d05ad7df4d801d1d1e62b3
3
+ metadata.gz: 5fdabb723bc231c0172f6fa824c8fa6cd6948a78
4
+ data.tar.gz: 2de8db50e6075474582a78e6475e01b5b591ef14
5
5
  SHA512:
6
- metadata.gz: d5b763aa1e08b9d14677f1b6bf6e8dee8bac807348f368f27dcd2f8025ac1d8e692c71f66859dfb412269fec312b7ea8b978f9ebbc46a4691833ecd69377d562
7
- data.tar.gz: 38b70bbf54128e8af1290ca7b98e43b984e04dba4c2d57e0e8f076511aca1acbd8a27a5ef3452793f81d57f5852cf1c831d7b292f66dc049a0e4b034faef0086
6
+ metadata.gz: 89eecfb7a41a6e24ce0b1cd9d583f720ff4ff74a12438fa5b4b557bf23de911fe96cf054e63435a72328a57342122b7751afe4bb97181117f258bc0a9ded250f
7
+ data.tar.gz: 3c2164cb23b043b1be8ed21dbdcc4c129bd3f5da818564c3d658c9944bf9a7dfd4a51918427fc6df8a7f592c2384aa5ee68b81b62d08d4d64aa45554a27a6eb7
data/README.md CHANGED
@@ -29,6 +29,12 @@ Or install it yourself as:
29
29
 
30
30
  $ gem install fibonacci_rng
31
31
 
32
+ The fibonacci_rng gem itself is found at: ( https://rubygems.org/gems/fibonacci_rng )
33
+
34
+ A C++ version of this generator also exists and may be found at
35
+ ( https://github.com/PeterCamilleri/Fibonacci_CPP )
36
+
37
+
32
38
  ## Usage
33
39
 
34
40
  ```ruby
@@ -38,23 +44,26 @@ require 'fibonacci_rng'
38
44
  Then in an appropriate place in the code:
39
45
 
40
46
  ```ruby
41
- @my_rng = FibonacciRng.new(depth, seed_value)
47
+ @my_rng = FibonacciRng.new(depth, seed)
42
48
  ```
43
49
 
44
- Where depth is an optional integer value between 2 and 99 and the seed value
45
- is a number or string or other object that has a repeatable value. You can
46
- also get a "random" generator of the default depth (8) and a randomized
47
- seed. Here is an overview of the available options.
50
+ Where:
51
+ * depth is an optional integer value between 2 and 256. Defaults to 8.
52
+ * seed is an optional number or string or other object that has a repeatable
53
+ value and responds to the to_s method. Defaults to a value derived from system
54
+ entropy.
55
+
56
+ Here is an overview of the available options.
48
57
 
49
58
  ```ruby
50
59
  #Method #1
51
60
  @my_rng = FibonacciRng.new # Random seed, depth = 8
52
61
 
53
62
  #Method #2
54
- @my_rng = FibonacciRng.new(seed) # Specified seed, depth = 8
63
+ @my_rng = FibonacciRng.new('seed') # Specified seed = 'seed', depth = 8
55
64
 
56
65
  #Method #3
57
- @my_rng = FibonacciRng.new(seed, 12) # Specified seed, depth = 12
66
+ @my_rng = FibonacciRng.new('seed', 12) # Specified seed = 'seed', depth = 12
58
67
 
59
68
  #Method #4
60
69
  @my_rng = FibonacciRng.new(FibonacciRng.new_seed, 12) # Random seed, depth = 12
@@ -63,17 +72,31 @@ seed. Here is an overview of the available options.
63
72
  In addition, keyword arguments are emulated (as of Version 0.4.0) so these
64
73
  additional options also are available:
65
74
 
75
+ * depth: value -- an integer value between 2 and 256. Defaults to 8.
76
+ * seed: value -- a number or string or other object that has a repeatable value and
77
+ responds to the to_s method. Defaults to a value derived from system entropy.
78
+ * init: value -- the number of initial training cycles used to seed the
79
+ generator. The allowed range is 1 to 1,000,000. By default the init value is
80
+ 32*depth+768. This setting is only available with keyword arguments.
81
+
82
+ The following are examples of constructors with keyword arguments.
83
+
66
84
  ```ruby
67
85
  #Method #5
68
- @my_rng = FibonacciRng.new(seed: seed) # Specified seed, depth = 8
86
+ @my_rng = FibonacciRng.new(seed: 'seed') # Specified seed = 'seed', depth = 8
69
87
 
70
88
  #Method #6
71
- @my_rng = FibonacciRng.new(seed: seed, depth: 12) # Specified seed, depth = 12
89
+ @my_rng = FibonacciRng.new(seed: 'seed', depth: 12) # Specified seed = 'seed', depth = 12
72
90
 
73
91
  #Method #7
74
92
  @my_rng = FibonacciRng.new(depth: 12) # Random seed, depth = 12
93
+
94
+ #Method #8
95
+ @my_rng = FibonacciRng.new(seed: 'seed', init: 2048) # Specified seed = 'seed' with 2048 passes.
96
+
75
97
  ```
76
- Note: Mixing positional and keyword arguments will not, in general, work.
98
+ Note: Mixing positional and keyword arguments will not, in general, work. So
99
+ don't do it!
77
100
 
78
101
  #### Generating Pseudo Random Data
79
102
 
data/irbt.rb ADDED
@@ -0,0 +1,20 @@
1
+ # coding: utf-8
2
+ # An IRB + fibonacci_rng Test bed
3
+
4
+ require 'irb'
5
+ $force_alias_read_line_module = true
6
+ require 'mini_readline'
7
+
8
+ puts "Starting an IRB console with fibonacci_rng loaded."
9
+
10
+ if ARGV[0] == 'local'
11
+ require_relative 'lib/fibonacci_rng'
12
+ puts "fibonacci_rng loaded locally: #{FibonacciRng::VERSION}"
13
+
14
+ ARGV.shift
15
+ else
16
+ require 'fibonacci_rng'
17
+ puts "fibonacci_rng loaded from gem: #{FibonacciRng::VERSION}"
18
+ end
19
+
20
+ IRB.start
data/lib/fibonacci_rng.rb CHANGED
@@ -14,7 +14,8 @@ class FibonacciRng
14
14
  BYTE = 0xFF
15
15
  WORD = 0xFFFF
16
16
  BASE = (CHOP+1).to_f
17
- DEPTHS = 2..99
17
+ DEPTHS = 2..256
18
+ INITS = 1..1_000_000
18
19
 
19
20
  #The depth of the Fibonacci array.
20
21
  attr_reader :depth
@@ -22,12 +23,16 @@ class FibonacciRng
22
23
  #The seed value used by this generator.
23
24
  attr_reader :seed
24
25
 
26
+ #The init value used by this generator.
27
+ attr_reader :init
28
+
25
29
  #Initialize the PRN generator
26
30
  def initialize(arg_a=nil, arg_b=nil)
27
31
  #Extract the parameters.
28
32
  if arg_a.is_a?(Hash)
29
33
  seed = arg_a[:seed]
30
34
  @depth = arg_a[:depth]
35
+ @init = arg_a[:init]
31
36
  else
32
37
  seed = arg_a
33
38
  @depth = arg_b
@@ -38,8 +43,15 @@ class FibonacciRng
38
43
  @depth ||= 8
39
44
 
40
45
  #Validate the depth.
41
- unless DEPTHS === depth
42
- fail "Invalid depth value #{depth}. Allowed values are #{DEPTHS}"
46
+ unless DEPTHS === @depth
47
+ fail "Invalid depth value #{@depth}. Allowed values are #{DEPTHS}"
48
+ end
49
+
50
+ @init ||= 32 * @depth + 768
51
+
52
+ #Validate the depth.
53
+ unless INITS === @init
54
+ fail "Invalid init value #{@init}. Allowed values are #{INITS}"
43
55
  end
44
56
 
45
57
  #Build the generator.
@@ -27,7 +27,7 @@ class FibonacciRng
27
27
 
28
28
  #Do the work of reseeding the PRNG
29
29
  def do_reseed(indxsrc, seedsrc)
30
- (32*@depth+768).times do
30
+ @init.times do
31
31
  @buffer[indxsrc.next] += seedsrc.next
32
32
  do_spin
33
33
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  #The class of Fibonacci inspired random number generators.
4
4
  class FibonacciRng
5
- VERSION = "1.0.1"
5
+ VERSION = "1.1.0"
6
6
  end
data/rakefile.rb CHANGED
@@ -16,6 +16,11 @@ task :reek do |t|
16
16
  `reek --no-color lib > reek.txt`
17
17
  end
18
18
 
19
+ desc "Run an IRB Session with fibonacci_rng loaded."
20
+ task :console do
21
+ system "ruby irbt.rb local"
22
+ end
23
+
19
24
  desc "What version of the Fibonacci is this?"
20
25
  task :vers do |t|
21
26
  puts
@@ -41,6 +41,10 @@ class FibonacciRngTester < Minitest::Test
41
41
  gen = FibonacciRng.new(depth: 12, seed: 'seed')
42
42
  assert_equal(12, gen.depth)
43
43
  assert_equal('seed', gen.seed)
44
+
45
+ gen = FibonacciRng.new(seed: 'seed', init: 2048)
46
+ assert_equal('seed', gen.seed)
47
+ assert_equal(2048, gen.init)
44
48
  end
45
49
 
46
50
  def test_that_rejects_bad_parms
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.0.1
4
+ version: 1.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-05-02 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest_visible
@@ -108,6 +108,7 @@ files:
108
108
  - README.md
109
109
  - fibonacci.reek
110
110
  - fibonacci_rng.gemspec
111
+ - irbt.rb
111
112
  - lib/fibonacci_rng.rb
112
113
  - lib/fibonacci_rng/generator.rb
113
114
  - lib/fibonacci_rng/hasher.rb