Created
August 26, 2015 05:13
-
-
Save isuke/970cd87cab5bc9747aad to your computer and use it in GitHub Desktop.
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 make_string(length, type = :alphabet, random: false) | |
char_set = nil | |
case type | |
when :alphabet | |
char_set = ('a'..'z').to_a | |
when :zenkaku | |
char_set = ('あ'..'ん').to_a | |
when :hankaku | |
char_set = ('ア'..'ン').to_a | |
end | |
char_set_len = char_set.length | |
(0..Float::INFINITY).lazy.map do |num| | |
nn = random ? rand(char_set_len) : num % char_set_len | |
char_set.to_a[nn] | |
end.take(length).to_a.join('') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment