Forked from KamilLelonek/random_string_generator.rb
Created
September 2, 2019 20:09
-
-
Save lym/1d55a0af5ff9d70f16efae117f0215b5 to your computer and use it in GitHub Desktop.
Revisions
-
KamilLelonek revised this gist
Mar 19, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ def with_numbers(length) private def random_string(length, charset) Array.new(length) { charset.sample }.join end def alphabet -
KamilLelonek revised this gist
Mar 19, 2015 . 2 changed files with 22 additions and 4 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +0,0 @@ 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,22 @@ class RandomStringGenerator def without_numbers(length) random_string(length, alphabet) end def with_numbers(length) random_string(length, alphabet + numbers) end private def random_string(length, charset) Array.new(length) { charset.sample }.flatten.join end def alphabet @alphabet ||= Array('A'..'Z') + Array('a'..'z') end def numbers @numbers ||= Array(0 .. 9) end end -
KamilLelonek created this gist
Mar 19, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ def random_string(number) charset = Array('A'..'Z') + Array('a'..'z') Array.new(number) { charset.sample }.join end