QA Graphic

Going Random with TextExpander

As a tester, I sometimes have a need for a random word. For example, I may need a unique word for creating a new account in my system. Using the Shell Script feature in TextExpander now makes it easy to add a random word whenever I need to.

Here are the simple steps to create a TextExpander Snippet so that you can instantly insert a random word whenever you need it:

random word
  1. Open up TextExpander and create a new Snippet.
  2. Change the script Content type to 'Shell Script'
  3. Enter in the following code:
    #!/bin/bash
    WORDFILE=/usr/share/dict/words
    RANDOM=$$;
    lines=$(cat $WORDFILE | wc -l);
    rnum=$((RANDOM*RANDOM%$lines+1));
    sed -n "$rnum p" $WORDFILE | perl -pe 'chomp'
  4. Click on the 'eye' to get a preview to make sure that it works.
  5. Enter in 'Random Word' as the Label.
  6. Enter 'rrandom' as the Abbreviation. (Makes it easy to remember!)

The root dictionary, /usr/share/dict/words as my random source library is good choice since their are 235,886 words available.

There are many ways to get a random word, I selected using the above method since it seems to be the quickest way. If you know of a better option, let me know!

 

Comments

Add Comments

Name:
Comment: