Method: Range.random

Defined in:
lib/propr/random/range.rb

.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