pseudo_random 1.0.1 → 2.0.0

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: e4970f4efb26dab591b3993a5f32aa7c7dbbdc5c95c902b0ec17cc4bed992d30
4
+ data.tar.gz: 21d3fbe2944dee77e0bdcd119a5c4e36a35216d51da00e2f12a06e71f05db1c0
5
5
  SHA512:
6
- metadata.gz: 33d3304a9b75f9107fab384a3aed3d7cb21d26733fbb72a1ac0323e40604dbc2948bf7be208bbe4bf95ce174d7a759fb2ed54d9f7451ae4469e8b61849d4e4e9
7
- data.tar.gz: 7332ebea107f056678cae26fb02f0520f42d4e47d866fc4432af1e4083ef72d11829c22406016a40bc4bc00351927b0ac37cf6148f25f33e59c6ba2edf66bdfd
6
+ metadata.gz: 50e2ddda1158f48552b8817974c1e3f95e3cbe021307fbb9e84e8f29b1c0175adb2cf3a37da418f4fe0978b5d1a4498c34f13a3dd9ef00d4814c4682f9c37f4d
7
+ data.tar.gz: c6c820faf822459093a3bb9be9d4617256fa0c03acb310ed97bdd0d97100f0d4558bc204d94710f4d7107cbff9351597dc78ee22708b0fb12ad2ad560cae2761
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,20 @@ Deprecations: A deprecated feature will remain for at least one MINOR release af
16
16
 
17
17
  ## [Unreleased]
18
18
 
19
+ ## [2.0.0] - 2025-12-06
20
+
21
+ ### Changed
22
+
23
+ - **Breaking Change**: `PseudoRandom.rand` method now requires keyword arguments
24
+ - Old API (deprecated): `PseudoRandom.rand(seed)` - positional argument
25
+ - New API: `PseudoRandom.rand(seed: your_seed)` - keyword argument
26
+ - The old positional argument API will raise an `ArgumentError` with a deprecation message
27
+ - This change unifies the API style with other one-off convenience methods (`hex`, `alphabetic`, `alphanumeric`)
28
+
29
+ ### Fixed
30
+
31
+ - Fixed rubocop warnings
32
+
19
33
  ## [1.0.1] - 2025-09-06
20
34
 
21
35
  ### Added
@@ -49,6 +63,7 @@ Deprecations: A deprecated feature will remain for at least one MINOR release af
49
63
  - Initial release: Deterministic pseudo-random generator (numbers / hex / alphabetic / alphanumeric string generation)
50
64
  - Support for arbitrary object seeds
51
65
 
52
- [Unreleased]: https://github.com/aYosukeMakita/pseudo_random/compare/v1.0.1...HEAD
66
+ [Unreleased]: https://github.com/aYosukeMakita/pseudo_random/compare/v2.0.0...HEAD
67
+ [2.0.0]: https://github.com/aYosukeMakita/pseudo_random/compare/v1.0.1...v2.0.0
53
68
  [1.0.1]: https://github.com/aYosukeMakita/pseudo_random/compare/v1.0.0...v1.0.1
54
69
  [1.0.0]: https://github.com/aYosukeMakita/pseudo_random/releases/tag/v1.0.0
data/README.md CHANGED
@@ -147,15 +147,27 @@ random_range = generator.rand(1..100)
147
147
  puts random_range # => 64
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)
153
+ # One-off random number
154
+ result = PseudoRandom.rand(seed: 42)
155
155
  puts result # => 0.6394267984578837
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 # => "a1b2c3d4e5f67890"
160
+
161
+ # One-off alphabetic string
162
+ alpha = PseudoRandom.alphabetic(seed: 'my_seed', length: 12)
163
+ puts alpha # => "AbCdEfGhIjKl"
164
+
165
+ # One-off alphanumeric string
166
+ alnum = PseudoRandom.alphanumeric(seed: 'my_seed', length: 10)
167
+ puts alnum # => "A1b2C3d4E5"
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
@@ -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.0'
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - aYosukeMakita