Module: PseudoRandom

Defined in:
lib/pseudo_random.rb,
lib/pseudo_random/seed.rb,
lib/pseudo_random/version.rb

Defined Under Namespace

Modules: Seed Classes: Error, Generator

Constant Summary collapse

VERSION =
'2.0.0'

Class Method Summary collapse

Class Method Details

.alphabetic(seed:, length:) ⇒ String

Generates a single alphabetic string based on the given seed (one-off convenience)



200
201
202
203
# File 'lib/pseudo_random.rb', line 200

def self.alphabetic(seed:, length:)
  generator = new(seed)
  generator.alphabetic(length)
end

.alphanumeric(seed:, length:) ⇒ String

Generates a single alphanumeric string based on the given seed (one-off convenience)



209
210
211
212
# File 'lib/pseudo_random.rb', line 209

def self.alphanumeric(seed:, length:)
  generator = new(seed)
  generator.alphanumeric(length)
end

.hex(seed:, length:) ⇒ String

Generates a single hexadecimal string based on the given seed (one-off convenience)



191
192
193
194
# File 'lib/pseudo_random.rb', line 191

def self.hex(seed:, length:)
  generator = new(seed)
  generator.hex(length)
end

.native_extension_loaded?Boolean

Returns true if native C++ extension is loaded and available



215
216
217
# File 'lib/pseudo_random.rb', line 215

def self.native_extension_loaded?
  NATIVE_EXTENSION_LOADED
end

.new(seed = nil) ⇒ Object

Creates a new generator with the given seed



168
169
170
# File 'lib/pseudo_random.rb', line 168

def self.new(seed = nil)
  Generator.new(seed)
end

.rand(positional_arg = nil, seed: nil) ⇒ Float

Generates a single pseudo-random number based on the given seed (one-off convenience)

Raises:

  • (ArgumentError)


175
176
177
178
179
180
181
182
183
184
185
# File 'lib/pseudo_random.rb', line 175

def self.rand(positional_arg = nil, seed: nil)
  if !positional_arg.nil? && seed.nil?
    raise ArgumentError,
          'PseudoRandom.rand(seed) is deprecated in v2.0.0. ' \
          "Use PseudoRandom.rand(seed: #{positional_arg.inspect}) instead."
  end
  raise ArgumentError, 'missing keyword: seed. Usage: PseudoRandom.rand(seed: your_seed)' if seed.nil?

  generator = new(seed)
  generator.rand
end