Sha256: 0bd0a76275aa7039f9d999e0e575ec49b038d55ddc95719ea4bb56a87471741d
Contents?: true
Size: 625 Bytes
Versions: 1
Compression:
Stored size: 625 Bytes
Contents
require 'rubyonacid/factory' module RubyOnAcid #Returns the minimum or the maximum at random (influenced by the given odds). class SkipFactory < Factory #The percentage odds that the factory will return 0 instead of 1. attr_accessor :odds #Takes a hash with all keys supported by Factory, plus these keys and defaults: # :odds => 0.1 def initialize(options = {}) super @odds = options[:odds] || 0.1 end #If a random number between 0 and 1 is less than the assigned odds value, will return 0 (a "skip"). #Otherwise returns 1. def get_unit(key) rand < @odds ? 0.0 : 1.0 end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rubyonacid-0.4.0 | lib/rubyonacid/factories/skip.rb |