Created
November 1, 2011 01:58
-
-
Save jaysonrowe/1329634 to your computer and use it in GitHub Desktop.
Random String Generator
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
| SPCHAR = %w['~`!@#$%^&*()_-+={[}]|\:;"<,>.?/'].shuffle[0..2] | |
| UPCHAR = ('A'..'Z').to_a.shuffle[0..4] | |
| CHAR = ('a'..'z').to_a.shuffle[0..4] | |
| NUMCHAR = ('0'..'9').to_a.shuffle[0..4] | |
| def random_string(length=15) | |
| s = SPCHAR | |
| c = CHAR | |
| u = UPCHAR | |
| n = NUMCHAR | |
| @password = s + c + n + u | |
| @password.sort_by { rand }.join[0..length] | |
| end | |
| puts random_string.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment