Skip to content

Instantly share code, notes, and snippets.

@kawaguchi
Created August 9, 2009 01:33
Show Gist options
  • Save kawaguchi/164580 to your computer and use it in GitHub Desktop.
Save kawaguchi/164580 to your computer and use it in GitHub Desktop.
def String.random(size, option={})
option = {
:capital => false,
:exclude => []
}.merge(option)
alphanumerics = ('a'..'z').to_a + ('0'..'9').to_a
alphanumerics += ('A'..'Z').to_a if option[:capital]
alphanumerics -= option[:exclude].to_a
Array.new(size){ alphanumerics.choice }.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment