Class: Integer

Inherits:
Object show all
Defined in:
lib/ext_core.rb

Overview

Some extentions to the core Integer class

Class Method Summary collapse

Class Method Details

.generate(min: nil, max: nil, bit_length: nil) ⇒ Integer

Randomly generate an Integer

Returns:



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ext_core.rb', line 53

def self.generate(min: nil, max: nil, bit_length: nil)
  i = Random.rand(10e10).to_i
  if !min.nil? or !max.nil? or !bit_length.nil?
    while i > max or i < min or i.bit_length > bit_length
      i = Random.rand(10e10).to_i
    end
  end

  if Random.rand < 0.5
    i
  else
    i * -1
  end
end