Skip to content

Instantly share code, notes, and snippets.

@judofyr
Created March 12, 2011 23:17
Show Gist options
  • Save judofyr/867673 to your computer and use it in GitHub Desktop.
Save judofyr/867673 to your computer and use it in GitHub Desktop.
class Range
def sample
b, e = self.begin, self.end
a = exclude_end? ? 1 : 0
case b
when Integer
rand(1 + e - b - a) + b
when Float
rand * (e - b) + b
else
to_a.sample
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment