Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

A script to generate random text via jot UNIX
There's already one hint on this site about the many wonders of the Unix utility jot. However, I was bored and decided to come up with some fun jot applications. So after hours of tweaking and coding, I came up with a script that lets you pick between three different types of output:
  1. Monkey typing random words.
  2. Geeky-looking code spam.
  3. Random English words from the dictionary.
Choose one, and your terminal window will then fill with all the randomness you could ever want; type Control-C to stop the program. Possible applications include looking busy at work, lorem ipsum for filler text, and generally feeling geeky.

My favorite is the code spam option. My best friend's fiancee took one look at my screen and said in an awed voice, "What is that?," in the same tone that one might say, "You built a nuclear reactor in your back yard!?" So I suppose all that time coding was worth it :). Read on for the script and a bit of detail on how it works.

Here's the script:
#!/bin/bash

#Ben Holt's fun jot script!
#http://theholtsite.com
#ben @ theholtsite.com

#Help from http://unixjunkie.blogspot.com/2007/10/generating-random-words.html

line=150
n=`cat /usr/share/dict/words | wc -l`

clear; echo; echo "I'm a code monkey! I can type all day! To stop me, press Control-C."; echo
echo "What should I type?"; echo

echo "1) Shakespeare/Lorem Ipsum"
echo "2) Spew Code!"
echo "3) Random English Words"
echo
echo ""

read arg

clear

case $arg in
    1)
    #Word spam
    while [ 1 ]; do
        nice jot -r -n -c $line a z | rs -g | sed -e "s/..\{`jot -r 1 3 6`\}/ &/g" | sed -e "s/..\{`jot -r 1 3 6`\}/ &/g" | sed -e "s/[ ]\{2,\}/ /g" | tr -d "[:cntrl:]"
        sleep .2
    done
;;
    2)    
    #Code spam
    while [ 1 ]; do
        nice jot -r -s "" -c `jot -r 1 1 $line` | sed -e "s/.\{`jot -r 1 4 6`\}/ &/g" | sed -e "s/.\{`jot -r 1 4 6`\}/ &/g" | tr -d "[:cntrl:]" | sed -e "s/.\{`jot -r 1 1 $line`\}//g" | tr "[:upper:]" "[:lower:]"
        sleep .2
    done
;;
    3)
    while [ 1 ]; do
    #Random English
        #perl -nle '$word = $_ if rand($.) < 1; END { print $word }' /usr/share/dict/words | tr "[:cntrl:]" " "
        cat /usr/share/dict/words | head -`jot -r 1 1 $n` | tail -1 | tr '\012' " "
        sleep .1
    done
;;
*)
    echo "Not a valid command."
    exit
esac
    
done
The line that makes it tick is this one:
nice jot -r -s "" -c `jot -r 1 1 $line` | sed -e "s/.\{`jot -r 1 4 6`\}/ &/g" | sed -e "s/.\{`jot -r 1 4 6`\}/ &/g" | tr -d "[:cntrl:]" | sed -e "s/.\{`jot -r 1 1 $line`\}//g" | tr "[:upper:]" "[:lower:]"
The script makes extensive use of jot, sed, and tr. There may be a better way to do this (there usually is). There's also many different ways to tweak it, such as changing the $line variable and the jot values of 4 and 6 (which affect spacing). Note that all control characters are removed so that nothing will ever be executed (this is a good thing).

[robg adds: This script works as described -- just remember to make it executable (chmod a+x script_name), and soon, your Terminal window can be filled with a bizarre assortment of words, gibberish, or geeky-looking code. Why one might want to run this script regularly is left as an exercise for the reader :).]
    •    
  • Currently 1.67 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (6 votes cast)
 
[10,065 views]  

A script to generate random text via jot | 9 comments | Create New Account
Click here to return to the 'A script to generate random text via jot' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Spew code doesn't really look like code.
Authored by: yarnmitch on Jun 11, '08 08:14:01AM

Being a code monkey, "Spew Code" doesn't look like code to me. How about using real code for this? There are plenty of scripts on the system that are ripe for grepping - check out all the scripts in /usr/bin.



[ Reply to This | # ]
A script to generate random text via jot
Authored by: sweyhrich on Jun 11, '08 09:28:21AM

Sorry to be so dense, but where and under what name do I save the script? It is invoked through that long line of code? Is there a way to save that long line as an executable script?



---
Steven Weyhrich
http://apple2history.org



[ Reply to This | # ]
A script to generate random text via jot
Authored by: flip on Jun 11, '08 09:49:40AM

You can name the script as you want and save it where you want. I named it monkeyTextGenerator. Once this is done you must make it executable (chmod +x nameOfYourScript). Then you can call it with ./nameOfYourScript. Then type your choice (1, 2 or 3) and Return. Ctrl-C stops it.

The line "that makes it tick" is the command in that script that generates the text.



[ Reply to This | # ]
A script to generate random text via jot
Authored by: sweyhrich on Jun 11, '08 10:18:55AM

That did it! Thanks so much for the extra assistance.

---
Steven Weyhrich
http://apple2history.org



[ Reply to This | # ]
A script to generate random text via jot
Authored by: asmeurer on Jun 11, '08 11:06:08AM

Well, I definitely need to update my vocabulary. I only recognize about 1/10 of the English words. What the heck are corcir, isothujone, halver (not even Dictionary recognizes these words, are these even real?)?



[ Reply to This | # ]
A script to generate random text via jot
Authored by: sebastianlewis on Jun 11, '08 01:46:36PM

Lexicographers are not traffic cops, they compile dictionaries, they don't create them. But no those words are not real, they can be real if you want them to be though, heh.

Sebastian



[ Reply to This | # ]
A script to generate random text via jot
Authored by: Daij on Jun 11, '08 03:02:08PM

I hate to be pedantic - OK, no, I love to be pedantic - corcir=Any of the colors, imparted by the dye archil varying from moderate red to dark purplish red; isothojune= one of the bio-active elements of wormwood; halver=would you believe, a machine or person that cuts things in half? That unix dictionary is pretty good!



[ Reply to This | # ]
no substitute for...
Authored by: chrischram on Jun 11, '08 03:05:19PM

I must say this script has literally minutes of entertainment value. That said, it's no substitute for a good Hipcrime-generated short story.



[ Reply to This | # ]
A script to generate random text via jot
Authored by: bdan44 on Jun 23, '08 06:26:43PM

Still very confused. This is going to sound bad but how do I say the script (what extension??).



[ Reply to This | # ]