At work we build almost all our sites in Ruby on Rails. As such, I’m writing JavaScript and Ruby day-to-day. Sometimes when we’re prototyping and messing around, I just need a random string of characters. I know there are things like the Faker gem and node package, but we don’t always have those dependencies available in our workflow, and sometimes I just want the one-liner.

Here are two StackOverflow answers that helped me out a ton this week.

Generate a random string of characters in JavaScript

Math.random().toString(36).substring(7);

source

Generate a random string of characters in Ruby

(0...8).map { (65 + rand(26)).chr }.join

source