+ 7
How to generate a random alphanumeric string in Ruby ?
Title says all.
3 ответов
+ 22
alpha_string = Array.new(12){rand(36).to_s(36)}.join
=begin
You can use any length in Array.new()
If you're wondering why only 36?
The answer is :
total English alphabets = 26.
total 1 - 10 numbers = 10.
10+26 = 36.
=end
+ 6
@Dayve Code Playground is Showing No Output
0
Ekansh, the code provided by Dev only assigns that string to "alpha_string" variable. You have to print or do something else with that variable/string by yourself (for example, to print: `print alpha_string`, `puts alpha_string` or `p alpha_string` (prints like it is in code, like debugging) with or without (as I provided) parentheses).