Class: Integer
Overview
Some extentions to the core Integer class
Class Method Summary collapse
-
.generate(min: nil, max: nil, bit_length: nil) ⇒ Integer
Randomly generate an Integer.
Class Method Details
.generate(min: nil, max: nil, bit_length: nil) ⇒ Integer
Randomly generate an Integer
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 |