Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

An inclusive rand() for ruby 1.9

View rand_incl.rb
1 2 3 4 5 6 7 8 9 10 11 12 13 14
class << Random
def rand_incl max=1.0
raise ArgumentError "maximum not greater than 0" if max <= 0.0
if @incl_lim.nil?
@incl_lim = (1 / Float::EPSILON).to_i
@incl_lim1 = @incl_lim + 1
end
if Float === max
max*rand(@incl_lim1) / @incl_lim
else
rand(max+1)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.