Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Creating random code strings with Array#inject

View inject.rb
1 2 3 4 5 6 7 8 9
# (to learn inject I am...)
# Using inject to create random strings
 
def code(size)
chars = ("a".."z").to_a+(0..9).to_a
Array.new(size).inject("") { |str, n| str += chars[rand(chars.size)].to_s }
end
50.times { |i| puts code(i) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.