Biblyon the Great

This zine is dedicated to articles about the fantasy role-playing game Gods & Monsters, and other random musings.

Gods & Monsters Fantasy Role-Playing

Beyond here lie dragons

Programming a Roman thumb

Jerry Stratton, March 8, 2011

Don’t worry, I’ve got some more cool stuff with the random table management script for later. But sometimes you don’t want to have to set up even a simple table. You just want to make a quick choice. “Death or mercy?” asks the gladiator, and the emperor responds with?

  • $ ./choose death mercy

As problems go, you can’t get much simpler than that. Here’s the code:

  • #!/usr/bin/python
  • import random, optparse
  • parser = optparse.OptionParser()
  • (options, args) = parser.parse_args()
  • print random.choice(args)

Save it as “choose”. Make it executable using “chmod u+x choose” just as in the previous installment. You now have a script that lets you make a quick choice between any arbitrary possibilities.

  • $ ./choose death mercy
  • mercy
  • $ ./choose mercury venus earth mars jupiter saturn uranus neptune pluto X
  • uranus

And a tip: the Unix command line uses spaces to separate arguments and options. If you want a single argument to include a space, surround the entire argument with quotes.

  • $ ./choose Greyhawk "Forgotten Realms"
  • Forgotten Realms

Ooh, that hurt.

  1. <- Random tables
  2. Is it random? ->