An amazingly simple random name generator and 3 ways to use it

Use this simple technique as a random name generator

I spend a lot of time testing websites for my customers. Part of that testing generally involves filling in a form of some sort for an eCommerce transaction, and I needed a random name generator to help.

Mr Test Test wasn’t cutting it anymore

Anyone who’s tested a website

So what did I really need?

I needed a way to generate a random name quickly, at a moments notice, using a consistent method and without having to rely on complicated browser plugins. And the last thing I wanted to do was have to copy and paste all the time.

I also wanted something that I could use in a browser as well as something I could use in an application and something that worked inside a remote session.

I needed the remote session access to be able to test inside a customer’s network or their custom internal application.

printed cards for random name generator

The random name generator implementation

To make this work I decided to use Keyboard Maestro. If you haven’t used it before keyboard maestro in app for the Mac that monitors what you type and when it finds something that you’ve configured it to ‘watch’ it replaces what you’ve type with the text you’ve configured.

Here’s a really simple example:

When I type “.name.” replace it with “Jay McCormack”

You might question why I would use something like .name. as the shortcut test? The reason for this is that you need to use text that you wouldn’t normally type in your day to day documents and email so that keyboard maestro has something unique to look for. It doesn’t have to start and end with periods (like you’ll see below), it just needs to be something unique.

To solve my random name generator problem I decided on the key phrase “ranff” for a random first name and “ranll” for a random last name (those are two L’s).

One more thing I chose to do was to add a little more information to the last name generation. Part of testing is being able to find the record that you just tested, and if the random name generator is creating random names then you really don’t have a way to know which random name was used unless you record each one that use when you use it. Too hard.

So instead I added the date to the end of the last name. Here’s an example:

When I type “ranll” replace it with “Wood2021821”

You can see in the above example that it adds the date with the year, then month, then day. This means that when I’m trying to find the data I used to test something I can at least look for the last name by date.

Adding it to Keyboard Maestro

This is a reasonable easy step if all you wanted to do was use the same text over and over again, however I wanted to also accommodate the random aspect to the name.

For this explanation, i’ll be focusing on the random name generator for the first name only.

Step 1 was to find some random name that I could work with. I think I ended up using mockaroo which is great website for generating random data sets for testing purposes.

Now that I had a set of names I needed to add a macro to keyboard maestro. When you create a macro you need to chose a trigger of some sort and in this case my trigger was this:

This means that when i type the text “ranff” that this macro will fire and at the same time is will remove the text “ranff” before doing anything else… which makes sense.

After this I needed to add some script to be able pick a name randomly and then type it for me. I chose to Apple Script for this as it’s relatively easy to read. I’m not overly familiar with it and sometimes find it a little foreign and overly verbose (like writing COBOL if anyone remembers what that is).

set myFirstNames to {"Ashley", "Ben", "Charlie", "Daniel", "Ethan", "George", "Harry", "Isaac", "Kai", "Lewis", "Matthew", "Noah", "Oliver", "Rhys", "Samuel", "Thomas", "William", "Annabelle", "Bethany", "Chloe", "Daisy", "Ebony", "Freya", "Grace", "Hannah", "Isla", "Jessica", "Katie", "Lara", "Martha", "Nell", "Olivia", "Polly", "Rosie", "Sophie", "Tilly", "Victoria", "Zarah"}
set listSize to count of myFirstNames
set randomNumber to (random number from 1 to listSize)
set temp to item randomNumber of myFirstNames
return temp

You could just copy and paste this to make it work. In Keyboard Maestro I added a new “Execute AppleScript” action and then added the script above into the box.

The script does the following:

  • It creates an variable called myFirstNames and sets the value of that variable to an array of names. Feel free to change the names to suit your requirements.
  • It then creates another variable called listSize and sets that to the number of items in the array, that is, the number of names in the list. We need this for the next step.
  • It then creates yet another variable called randomNumber which is a random number between 1 and the number of names. I do it this way so that if I add or remove names from the list then i don’t have change anything else in the script.
  • Finally it creates a variable called temp which is set to the name from the list based on the random number chosen. It then returns this temp variable so that the randomly selected name is typed out into whatever field I happen to be in.

Want to see it in action? Here’s a gif showing how it works (blink and you’ll miss it):

Over the years I’ve generated a range of macros in Keyboard Maestro and many of them are available for download.