Skip to content

Instantly share code, notes, and snippets.

@coreyward
Created December 10, 2010 03:14
Show Gist options
  • Save coreyward/735705 to your computer and use it in GitHub Desktop.
Save coreyward/735705 to your computer and use it in GitHub Desktop.
Easy random numbers (or letters) from a range
class Range
def pick
if min.is_a? Fixnum
rand(count) + min
else
self.to_a[rand(count)]
end
end
alias :random :pick
end
random_number = (1..500).pick
# or
random_character = ('a'..'z').pick
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment