Last active
January 7, 2023 23:03
-
-
Save umutakturk/3835467 to your computer and use it in GitHub Desktop.
Generate random string in Ruby.
This file contains 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
def random_string(length = 6) | |
rand(36**length).to_s(36) | |
end |
This file contains 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
def random_string | |
rand(2**1024).to_s(36).upcase[0..9] | |
end |
This file contains 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
def random_string(length) | |
chars = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a | |
(1..length).map { | |
chars[rand(chars.length)] | |
}.join | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment