fibonacci_rng 0.4.2 → 0.4.3

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: c178772afcc6c24037cf6b161276603f52e16c27
4
- data.tar.gz: 921d717758b803609d2e4db12153542d1129c0f9
3
+ metadata.gz: 24192194041fbb6a8a907907c3d80c793a25eb1a
4
+ data.tar.gz: afc6ce49588ec4aaeb8de9b1ead78bbec947f3ed
5
5
  SHA512:
6
- metadata.gz: eab6f383927f08b52f9c82ffd8a428ba7ae091bda1c35c56444cb04df6c9188ca32d2ffefa8a14ea6726ae249ccd3eeced18ca5468df2fdb51a623ca95f71bab
7
- data.tar.gz: 99114d55d8493734d1ca608c5f3f151677e51b72a40dd0f1d69360b34170d86b13548ae6ddf903be48327102dcbdc4752d875f8246b63e01febe6fe6f3749924
6
+ metadata.gz: b8c839b0aad4e0defdc304bdb6bbdbf40a3db783711c2961345468e7e76d119bc78db0a147a763a283b42495c228e7b0017ee6b05a1d84e75d1cfa024472206a
7
+ data.tar.gz: e331373058f17ef81d5b43808f48c62e29a752de076620a2bdb9b1ad3cfcd75bdf20acae5ee032250aee3c69de302ded79a406ca560adafbb148ba9a9278c1f0
data/README.md CHANGED
@@ -93,6 +93,10 @@ In addition, here are some other options:
93
93
  @my_rng.byte # A "random" integer between 0 and 255
94
94
  @my_rng.word # A "random" integer between 0 and 65535
95
95
  @my_rng.float # A "random" float between 0 and less than 1.
96
+ @my_rng.string(10) # A "random" string of 10 characters in length.
97
+
98
+ # A "random" string of 10 characters in length from the string 'abcdefg'.
99
+ @my_rng.string(10, 'abcdefg')
96
100
  ```
97
101
 
98
102
  and also available are these helpful methods:
@@ -154,6 +158,19 @@ salt_string = salter.hash_string
154
158
 
155
159
  Each time any of these is run, a different salt string will be generated.
156
160
 
161
+ #### Deprecated Methods
162
+
163
+ * bytes - This method would seem to generate an array of random bytes. It does
164
+ not. That's why it's deprecated. Instead it generates a string with random
165
+ byte code values. Plays havoc with encodings too. To get an array of len random
166
+ byte values, try this example:
167
+
168
+ ```ruby
169
+ generator = FibonacciRng.new
170
+ random_bytes = Array.new(len) { generator.byte }
171
+ ```
172
+
173
+
157
174
  ## Contributing
158
175
 
159
176
  1. Fork it
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.required_ruby_version = '>= 1.9.3'
25
25
 
26
- spec.add_development_dependency 'minitest_visible', ">= 0.1.0"
26
+ spec.add_development_dependency 'minitest_visible', ">= 0.1.1"
27
27
  spec.add_development_dependency "bundler", "~> 1.3"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency 'reek', "~> 1.3.8"
@@ -34,7 +34,7 @@ class FibonacciRng
34
34
  @buffer[0] & BYTE
35
35
  end
36
36
 
37
- #Get a string of random bytes
37
+ #[Deprecated] Get a string of random bytes
38
38
  def bytes(length)
39
39
  result = ""
40
40
  length.times {result << byte.chr}
@@ -53,4 +53,15 @@ class FibonacciRng
53
53
  @buffer[0].to_f / BASE
54
54
  end
55
55
 
56
+ #The printable seven bit ASCII characters.
57
+ ASCII_7_BIT = (' '..'~').to_a.join
58
+
59
+ #Create a random string
60
+ def string(length, set=ASCII_7_BIT)
61
+ set_length = set.length
62
+ result = ""
63
+ length.times {result << set[dice(set_length)]}
64
+ result
65
+ end
66
+
56
67
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  #The class of Fibonacci inspired random number generators.
4
4
  class FibonacciRng
5
- VERSION = "0.4.2"
5
+ VERSION = "0.4.3"
6
6
  end
@@ -149,4 +149,12 @@ class FibonacciRngTester < Minitest::Test
149
149
  assert_equal(10_000, result.length)
150
150
  end
151
151
 
152
+ def test_building_strings
153
+ rng = FibonacciRng.new(0)
154
+
155
+ assert_equal('8{4y5+-N+c', rng.string(10))
156
+ assert_equal('1149049996', rng.string(10, '0123456789'))
157
+ assert_equal('tfes oAy', rng.string(10, 'Always look on the bright side of life.'))
158
+ end
159
+
152
160
  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.4.2
4
+ version: 0.4.3
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-03-22 00:00:00.000000000 Z
11
+ date: 2016-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest_visible
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.1.0
19
+ version: 0.1.1
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.1.0
26
+ version: 0.1.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement