Skip to content

Instantly share code, notes, and snippets.

@isuke
Created August 26, 2015 05:13
Show Gist options
  • Save isuke/970cd87cab5bc9747aad to your computer and use it in GitHub Desktop.
Save isuke/970cd87cab5bc9747aad to your computer and use it in GitHub Desktop.
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