pseudo_random 1.0.1 → 2.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea6d1ceeeffde9f6428fbc99f74a8a3531c654aa42406592112da203b8c4aafb
4
- data.tar.gz: ca518011da7918a0526ea200e3dd6873b98ffae7c770fcc55b199323e0763e26
3
+ metadata.gz: 62b608038d538d7b3b2214254d4e4c710e12850447f61946e7160fcb8f7431db
4
+ data.tar.gz: f15a95f68ae4a7abec4b36f2b7b66128472e7a27290c0c83e853f09ae439f034
5
5
  SHA512:
6
- metadata.gz: 33d3304a9b75f9107fab384a3aed3d7cb21d26733fbb72a1ac0323e40604dbc2948bf7be208bbe4bf95ce174d7a759fb2ed54d9f7451ae4469e8b61849d4e4e9
7
- data.tar.gz: 7332ebea107f056678cae26fb02f0520f42d4e47d866fc4432af1e4083ef72d11829c22406016a40bc4bc00351927b0ac37cf6148f25f33e59c6ba2edf66bdfd
6
+ metadata.gz: cb223bd31b10081e99f70306d078a10ee29b705223e8b861353f43cb3a40a1897eb4c999b4b22290fe1a727df8e30daab3e2b041a8faedb630fc3d8f85b70449
7
+ data.tar.gz: b2a176e1dfea1b430771ba69cac292b441779f8e5c9321c468a8e7b462c42525324f18d7d05baad334c076d9ea140fa835bf8275a2ec362d369b446e2791c219
data/.rubocop.yml CHANGED
@@ -6,6 +6,7 @@ AllCops:
6
6
  Exclude:
7
7
  - 'pseudo_random.gemspec'
8
8
  - 'vendor/**/*'
9
+ - 'lib/**/*.so'
9
10
 
10
11
  ##################### Layout #################################
11
12
  Layout/LineLength:
data/CHANGELOG.md CHANGED
@@ -16,6 +16,28 @@ Deprecations: A deprecated feature will remain for at least one MINOR release af
16
16
 
17
17
  ## [Unreleased]
18
18
 
19
+ ## [2.0.1] - 2025-12-20
20
+
21
+ ### Fixed
22
+
23
+ - Fixed README examples to match actual execution results
24
+ - Updated all code examples with correct output values
25
+ - Examples now accurately reflect the deterministic behavior of the library
26
+
27
+ ## [2.0.0] - 2025-12-06
28
+
29
+ ### Changed
30
+
31
+ - **Breaking Change**: `PseudoRandom.rand` method now requires keyword arguments
32
+ - Old API (deprecated): `PseudoRandom.rand(seed)` - positional argument
33
+ - New API: `PseudoRandom.rand(seed: your_seed)` - keyword argument
34
+ - The old positional argument API will raise an `ArgumentError` with a deprecation message
35
+ - This change unifies the API style with other one-off convenience methods (`hex`, `alphabetic`, `alphanumeric`)
36
+
37
+ ### Fixed
38
+
39
+ - Fixed rubocop warnings
40
+
19
41
  ## [1.0.1] - 2025-09-06
20
42
 
21
43
  ### Added
@@ -49,6 +71,8 @@ Deprecations: A deprecated feature will remain for at least one MINOR release af
49
71
  - Initial release: Deterministic pseudo-random generator (numbers / hex / alphabetic / alphanumeric string generation)
50
72
  - Support for arbitrary object seeds
51
73
 
52
- [Unreleased]: https://github.com/aYosukeMakita/pseudo_random/compare/v1.0.1...HEAD
74
+ [Unreleased]: https://github.com/aYosukeMakita/pseudo_random/compare/v2.0.1...HEAD
75
+ [2.0.1]: https://github.com/aYosukeMakita/pseudo_random/compare/v2.0.0...v2.0.1
76
+ [2.0.0]: https://github.com/aYosukeMakita/pseudo_random/compare/v1.0.1...v2.0.0
53
77
  [1.0.1]: https://github.com/aYosukeMakita/pseudo_random/compare/v1.0.0...v1.0.1
54
78
  [1.0.0]: https://github.com/aYosukeMakita/pseudo_random/releases/tag/v1.0.0
data/README.md CHANGED
@@ -132,30 +132,42 @@ generator = PseudoRandom.new(42)
132
132
 
133
133
  # Float in [0.0, 1.0)
134
134
  random_float = generator.rand
135
- puts random_float # => 0.6394267984578837
135
+ puts random_float # => 0.8731369804701281
136
136
 
137
137
  # Integer in [0, 9]
138
138
  random_int = generator.rand(10)
139
- puts random_int # => 6
139
+ puts random_int # => 9
140
140
 
141
141
  # Float in [0.0, 10.0)
142
142
  random_float_range = generator.rand(10.0)
143
- puts random_float_range # => 9.66814512009282
143
+ puts random_float_range # => 3.440017825456998
144
144
 
145
145
  # Integer in [1, 100]
146
146
  random_range = generator.rand(1..100)
147
- puts random_range # => 64
147
+ puts random_range # => 41
148
148
  ```
149
149
 
150
- ### Convenience one-off method
150
+ ### Convenience one-off methods
151
151
 
152
152
  ```ruby
153
- # One-off random number (legacy convenience)
154
- result = PseudoRandom.rand(42)
155
- puts result # => 0.6394267984578837
153
+ # One-off random number
154
+ result = PseudoRandom.rand(seed: 42)
155
+ puts result # => 0.8731369804701281
156
156
 
157
- # Create a new generator explicitly
158
- generator = PseudoRandom.new(42)
157
+ # One-off hex string
158
+ hex = PseudoRandom.hex(seed: 'my_seed', length: 16)
159
+ puts hex # => "cee117d6757980b7"
160
+
161
+ # One-off alphabetic string
162
+ alpha = PseudoRandom.alphabetic(seed: 'my_seed', length: 12)
163
+ puts alpha # => "aZikVznxlLXj"
164
+
165
+ # One-off alphanumeric string
166
+ alnum = PseudoRandom.alphanumeric(seed: 'my_seed', length: 10)
167
+ puts alnum # => "Q3a2S8sXED"
168
+
169
+ # These are equivalent to creating a generator and calling the method once:
170
+ # PseudoRandom.hex(seed: 'my_seed', length: 16) == PseudoRandom.new('my_seed').hex(16)
159
171
  ```
160
172
 
161
173
  ### Diverse seed types
@@ -165,23 +177,23 @@ You can pass any Ruby object as a seed to `PseudoRandom.new`. The object will be
165
177
  ```ruby
166
178
  # String seed
167
179
  generator1 = PseudoRandom.new("hello")
168
- puts generator1.rand # => 0.1915194503788923
180
+ puts generator1.rand # => 0.37097030662852004
169
181
 
170
182
  # Array seed
171
183
  generator2 = PseudoRandom.new([1, 2, 3])
172
- puts generator2.rand # => 0.04548605918364251
184
+ puts generator2.rand # => 0.41837699041143994
173
185
 
174
186
  # Hash seed
175
187
  generator3 = PseudoRandom.new({ name: "John", age: 30 })
176
- puts generator3.rand # => 0.7550896311312906
188
+ puts generator3.rand # => 0.5869273234945404
177
189
 
178
190
  # Time seed
179
191
  generator4 = PseudoRandom.new(Time.new(2023, 1, 1))
180
- puts generator4.rand # => 0.4320558086698993
192
+ puts generator4.rand # => 0.6345803634459501
181
193
 
182
194
  # Omitted seed (uses hash of nil)
183
195
  generator5 = PseudoRandom.new
184
- puts generator5.rand # => 0.8501480898450888
196
+ puts generator5.rand # => 0.9527695090684619
185
197
  ```
186
198
 
187
199
  ### Hex string generation
@@ -191,15 +203,15 @@ generator = PseudoRandom.new("secret")
191
203
 
192
204
  # 8 hex characters
193
205
  hex_string = generator.hex(8)
194
- puts hex_string # => "a1b2c3d4"
206
+ puts hex_string # => "0b628b64"
195
207
 
196
208
  # 10 hex characters
197
209
  hex_string_10 = generator.hex(10)
198
- puts hex_string_10 # => "a50ee918e5"
210
+ puts hex_string_10 # => "6f291838f3"
199
211
 
200
212
  # 16 hex characters
201
213
  long_hex = generator.hex(16)
202
- puts long_hex # => "a1b2c3d4e5f67890"
214
+ puts long_hex # => "afef24ef63f4e104"
203
215
 
204
216
  # Empty string (length 0)
205
217
  empty_hex = generator.hex(0)
@@ -219,11 +231,11 @@ gen2 = PseudoRandom.new("test")
219
231
  end
220
232
 
221
233
  # Example output:
222
- # gen1: 0.5985762380674765, gen2: 0.5985762380674765
223
- # gen1: 0.8325673044064309, gen2: 0.8325673044064309
224
- # gen1: 0.24136065771243595, gen2: 0.24136065771243595
225
- # gen1: 0.7392418174919607, gen2: 0.7392418174919607
226
- # gen1: 0.9853406830436152, gen2: 0.9853406830436152
234
+ # gen1: 0.7714906738735868, gen2: 0.7714906738735868
235
+ # gen1: 0.9245604822851962, gen2: 0.9245604822851962
236
+ # gen1: 0.4030548732252476, gen2: 0.4030548732252476
237
+ # gen1: 0.07008281657880167, gen2: 0.07008281657880167
238
+ # gen1: 0.8898582626604018, gen2: 0.8898582626604018
227
239
  ```
228
240
 
229
241
  ### Practical examples
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PseudoRandom
4
- VERSION = '1.0.1'
4
+ VERSION = '2.0.1'
5
5
  end
data/lib/pseudo_random.rb CHANGED
@@ -169,12 +169,48 @@ module PseudoRandom
169
169
  Generator.new(seed)
170
170
  end
171
171
 
172
- # Generates a single pseudo-random number based on the given seed (backward compatibility)
173
- def self.rand(seed)
172
+ # Generates a single pseudo-random number based on the given seed (one-off convenience)
173
+ # @param seed [Object] the seed value for the generator
174
+ # @return [Float] a float in [0.0, 1.0)
175
+ def self.rand(positional_arg = nil, seed: nil)
176
+ if !positional_arg.nil? && seed.nil?
177
+ raise ArgumentError,
178
+ 'PseudoRandom.rand(seed) is deprecated in v2.0.0. ' \
179
+ "Use PseudoRandom.rand(seed: #{positional_arg.inspect}) instead."
180
+ end
181
+ raise ArgumentError, 'missing keyword: seed. Usage: PseudoRandom.rand(seed: your_seed)' if seed.nil?
182
+
174
183
  generator = new(seed)
175
184
  generator.rand
176
185
  end
177
186
 
187
+ # Generates a single hexadecimal string based on the given seed (one-off convenience)
188
+ # @param seed [Object] the seed value for the generator
189
+ # @param length [Integer] the number of hexadecimal characters to generate
190
+ # @return [String] a hexadecimal string with lowercase a-f
191
+ def self.hex(seed:, length:)
192
+ generator = new(seed)
193
+ generator.hex(length)
194
+ end
195
+
196
+ # Generates a single alphabetic string based on the given seed (one-off convenience)
197
+ # @param seed [Object] the seed value for the generator
198
+ # @param length [Integer] the number of alphabetic characters to generate
199
+ # @return [String] a string containing uppercase letters (A-Z) and lowercase letters (a-z)
200
+ def self.alphabetic(seed:, length:)
201
+ generator = new(seed)
202
+ generator.alphabetic(length)
203
+ end
204
+
205
+ # Generates a single alphanumeric string based on the given seed (one-off convenience)
206
+ # @param seed [Object] the seed value for the generator
207
+ # @param length [Integer] the number of alphanumeric characters to generate
208
+ # @return [String] a string containing A-Z, a-z, and 0-9
209
+ def self.alphanumeric(seed:, length:)
210
+ generator = new(seed)
211
+ generator.alphanumeric(length)
212
+ end
213
+
178
214
  # Returns true if native C++ extension is loaded and available
179
215
  def self.native_extension_loaded?
180
216
  NATIVE_EXTENSION_LOADED
@@ -20,5 +20,9 @@ module PseudoRandom
20
20
  end
21
21
 
22
22
  def self.new: (?untyped seed) -> Generator
23
- def self.rand: (untyped seed) -> Float
23
+ def self.rand: (?untyped positional_arg, ?seed: untyped) -> Float
24
+ def self.hex: (seed: untyped, length: Integer) -> String
25
+ def self.alphabetic: (seed: untyped, length: Integer) -> String
26
+ def self.alphanumeric: (seed: untyped, length: Integer) -> String
27
+ def self.native_extension_loaded?: () -> bool
24
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pseudo_random
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - aYosukeMakita