module FFaker::RandomUtils
Methods for returning repeatably-random data using the internal Random
Number
Generator. You should not need to use this directly, it is automatically included when you ‘include ModuleUtils` in a FFaker
module.
Public Instance Methods
fetch_sample(list, options = {})
click to toggle source
Performs Array#sample on ‘list` using a the internal Random
Number
Generator so that the results are deterministic.
-
Returns one random item from ‘list`.
-
Pass ‘count: n` in options argument, where `n` is an integer, to
return n items from ‘list`
# File lib/ffaker/utils/random_utils.rb, line 20 def fetch_sample(list, options = {}) if (count = options.delete(:count)) list.sample(count, random: FFaker::Random) elsif list.is_a?(Range) FFaker::Random.rand(list) else list.sample(random: FFaker::Random) end end
rand(max = nil)
click to toggle source
shuffle(list)
click to toggle source