Class: Faker::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/janrandom.rb

Class Method Summary collapse

Class Method Details

.bell_random_in_range(from, to) ⇒ Object



288
289
290
291
# File 'lib/janrandom.rb', line 288

def bell_random_in_range( from, to )
  from, to = to, from if to < from
  ( rand * (to - from ) + rand * (to - from ) ) / 2 + from
end

.fetch_with_weighting(key) ⇒ Object



272
273
274
275
276
277
278
279
280
281
# File 'lib/janrandom.rb', line 272

def fetch_with_weighting(key)
  fetched = translate("faker.#{key}")
  num = rand(fetched.length) + rand(fetched.length) - fetched.length
  fetched = fetched[num.abs] if fetched.respond_to?(:sample)
  if fetched.match(/^\//) and fetched.match(/\/$/) # A regex
    regexify(fetched)
  else
    fetched
  end
end

.random_in_range(from, to) ⇒ Object



283
284
285
286
# File 'lib/janrandom.rb', line 283

def random_in_range( from, to )
  from, to = to, from if to < from
  rand * (to - from ) + from
end