Skip to content

Instantly share code, notes, and snippets.

@mklemme
Created January 12, 2015 22:47
Show Gist options
  • Save mklemme/72d162c420bc15dfec4d to your computer and use it in GitHub Desktop.
Save mklemme/72d162c420bc15dfec4d to your computer and use it in GitHub Desktop.
Generate a random string
## Random string generator
This solution generates a string of easily readable characters for activation codes; I didn't want people confusing 8 with B, 1 with I, 0 with O, L with 1, etc.
# Generates a random string from a set of easily readable characters
def generate_activation_code(size = 6)
charset = %w{ 2 3 4 6 7 9 A C D E F G H J K M N P Q R T V W X Y Z}
(0...size).map{ charset.to_a[rand(charset.size)] }.join
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment