Class: Range

Inherits:
Object show all
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(options = {}, m = Propr::Random)
  random =
    if block_given?
      yield
    else
      min = options[:min]
      max = options[:max]
      min or max or raise ArgumentError,
        "must provide min, max, or block"
      (min or max).class.random(options)
    end

  m.bind(random) do |a|
    m.bind(random) do |b|
      if options.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(options = {})
  # @todo: This won't work for some types, e.g. String.
  # @todo: Should this be skewed/scaled?
  min.class.random(options.merge(min: min, max: max))
end