If you're on a Linux or BSD box that has fortune installed, you could always do something simple like system("fortune funny"); Use locate (or which) to determine if it it installed and what folder it is in. system() will print the contents, use exec if you want to capture them.
man fortune for more information, or check out http://linux.die.net/man/6/fortune. You may or may not have a database called "funny" installed.