@private Implementation corresponding to the actual Random class of Ruby The actual random generator (mersenne twister) is in MT19937. Ruby specific conversions are handled in bits_and_bytes. The high level stuff (argument checking) is done here.
# File lib/rspec/core/backport_random.rb, line 275 def ==(other) other.is_a?(Random) && seed == other.seed && left == other.send(:left) && state == other.send(:state) end
# File lib/rspec/core/backport_random.rb, line 269 def bytes(nb) nb = Backports.coerce_to_int(nb) raise ArgumentError, "negative size" if nb < 0 @mt.random_bytes(nb) end
# File lib/rspec/core/backport_random.rb, line 282 def marshal_dump @mt.marshal_dump << @seed end
# File lib/rspec/core/backport_random.rb, line 286 def marshal_load(ary) @seed = ary.pop @mt = MT19937.allocate @mt.marshal_load(ary) end
# File lib/rspec/core/backport_random.rb, line 255 def rand(limit = Backports::Undefined) case limit when Backports::Undefined @mt.random_float when Float limit * @mt.random_float unless limit <= 0 when Range _rand_range(limit) else limit = Backports.coerce_to_int(limit) @mt.random_integer(limit) unless limit <= 0 end || raise(ArgumentError, "invalid argument #{limit}") end
Generated with the Darkfish Rdoc Generator 2.