[EDIT, 2010-11-10:] After being kindly corrected by Chris Jones, I recommend instead using a readily available utility that is more feature rich to boot: pwgen.[/EDIT]
I have been using this script I wrote about a few years back to generate random passwords. It works, but it’s limited. I’ve written a new one that doesn’t have requirements other than Python 2.5 or higher, is more flexible and a bit easier to follow: randpass.py.
This script is very easy to use. Download it somewhere you keep handy scripts and make an alias like this: