Created
January 12, 2015 22:47
-
-
Save mklemme/72d162c420bc15dfec4d to your computer and use it in GitHub Desktop.
Generate a random string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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