Class: Contracts::Builtin::Int

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

Direct Known Subclasses

BigInt, SmallInt, TinyInt

Class Method Summary collapse

Class Method Details

.generate(min: -2e31,, max: 2e31 - 1, neg_ratio: 0.5) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/contracts/builtin_ext.rb', line 18

def self.generate(min: -2e31, max: 2e31 - 1, neg_ratio: 0.5)
  min_pos = min < 0 ? 0 : min
  max_neg = max > -1 ? -1 : max

  if Bool.generate(true_ratio: neg_ratio)
    Num.generate(min: min, max: max_neg).to_i
  else
    Num.generate(min: min_pos, max: max).to_i
  end
end