module FFaker::Random
Random
Number
Generator (RNG) used with ModuleUtils#fetch, shuffle, rand in order to provide deterministic repeatability.
Public Class Methods
Source
# File lib/ffaker.rb, line 126 def self.new_rng ::Random.new(seed) end
Returns a new Random
object instantiated with seed.
Source
# File lib/ffaker.rb, line 114 def self.rand(max = nil) return rng.rand(max) if max rng.rand end
Returns a random number using an RNG with a known seed.
Source
# File lib/ffaker.rb, line 109 def self.reset! @rng = new_rng end
Reset the RNG back to its initial state.
Source
# File lib/ffaker.rb, line 121 def self.rng @rng ||= new_rng end
Returns the current Random
object.
Source
# File lib/ffaker.rb, line 97 def self.seed @seed ||= ::Random.new_seed end
Returns the current RNG seed.
Source
# File lib/ffaker.rb, line 102 def self.seed=(new_seed) @seed = new_seed reset! new_seed end
Sets the RNG seed and creates a new internal RNG.