Class: Range
- Defined in:
- lib/propr/random/range.rb,
lib/propr/shrink/range.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.random(options = {}, m = Propr::Random) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/propr/random/range.rb', line 10 def random( = {}, m = Propr::Random) random = if block_given? yield else min = [:min] max = [:max] min or max or raise ArgumentError, "must provide min, max, or block" (min or max).class.random() end m.bind(random) do |a| m.bind(random) do |b| if .fetch(:inclusive?, rand > 0.5) m.unit(a..b) else m.unit(a...b) end end end end |
Instance Method Details
#random(options = {}) ⇒ Object
2 3 4 5 6 |
# File 'lib/propr/random/range.rb', line 2 def random( = {}) # @todo: This won't work for some types, e.g. String. # @todo: Should this be skewed/scaled? min.class.random(.merge(min: min, max: max)) end |