Module: FFaker::Random
- Defined in:
- lib/ffaker.rb
Overview
Random Number Generator (RNG) used with ModuleUtils#fetch, #shuffle, #rand in order to provide deterministic repeatability.
Class Method Summary collapse
-
.new_rng ⇒ Object
Returns a new Random object instantiated with #seed.
-
.rand(max = nil) ⇒ Object
Returns a random number using an RNG with a known seed.
-
.reset! ⇒ Object
Reset the RNG back to its initial state.
-
.rng ⇒ Object
Returns the current Random object.
-
.seed ⇒ Object
Returns the current RNG seed.
-
.seed=(new_seed) ⇒ Object
Sets the RNG seed and creates a new internal RNG.
Class Method Details
.new_rng ⇒ Object
Returns a new Random object instantiated with #seed.
253 254 255 |
# File 'lib/ffaker.rb', line 253 def self.new_rng ::Random.new(seed) end |
.rand(max = nil) ⇒ Object
Returns a random number using an RNG with a known seed.
241 242 243 244 245 |
# File 'lib/ffaker.rb', line 241 def self.rand(max = nil) return rng.rand(max) if max rng.rand end |
.reset! ⇒ Object
Reset the RNG back to its initial state.
236 237 238 |
# File 'lib/ffaker.rb', line 236 def self.reset! @rng = new_rng end |
.rng ⇒ Object
Returns the current Random object.
248 249 250 |
# File 'lib/ffaker.rb', line 248 def self.rng @rng ||= new_rng end |
.seed ⇒ Object
Returns the current RNG seed.
224 225 226 |
# File 'lib/ffaker.rb', line 224 def self.seed @seed ||= ::Random.new_seed end |
.seed=(new_seed) ⇒ Object
Sets the RNG seed and creates a new internal RNG.
229 230 231 232 233 |
# File 'lib/ffaker.rb', line 229 def self.seed=(new_seed) @seed = new_seed reset! new_seed end |