+ 7

How to generate a random alphanumeric string in Ruby ?

Title says all.

8th Jun 2017, 1:18 PM
Ekansh
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
8th Jun 2017, 1:42 PM
Dev
Dev - avatar
+ 6
@Dayve Code Playground is Showing No Output
8th Jun 2017, 2:42 PM
Ekansh
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).
3rd Mar 2021, 7:46 AM
#0009e7 [get]
#0009e7 [get] - avatar