Generating output from fortune deterministically

My outputs from fortune are too random - in order for my fortunes to have any kind of scientific significance, I need to follow the principles of Astrology such that the fortune that is selected depends partly on, e.g., the phase of the moon. I've sorted out the Astrology side of things to get an astrologically deterministic number, which I can use as a random seed.

From here, I either want to be able to:

  1. Output the Nth fortune, or

  2. Set the random seed that fortune uses.

I can imagine doing 1. by getting a list of fortune files fortune -f and picking a random line from one of those files. But it would be nice if there was a more elegant solution.

I don't know how to do 2., all I know is that the RNG is not $RANDOM, so I can't set the seed in bash with RANDOM=seed.

Answers


There are many versions and re-implementations of fortune. I have had a look to Linux' fortune source code, the one you are probably using (here: fortune source). Unforutnately (!) it uses /dev/urandomto get the seed, and if this fails time(0) is used instead. That's why $RANDOM doesn't work. I can imagine only these solutions (in addition to the one you have already found):

1) Modify the source to add an option to force the random seed. It's quite trivial.

2) Run the program into a restricted environment via chroot. The restricted environment must contain the necessary binaries and a fake /dev/urandom (plain file) containing the seed you want to apply:

echo -en "$myseed" > restrictedroot/dev/urandom
chroot restrictedroot fortune

Note that the fake urandom containd binary data, so $myseed must be expanded as a 4-bytes binary sequence (i.e. with four exadecimal sequences "\xHH"). Not at all handy.


Need Your Help

ASP.NET Changing Session-State Modes

php asp.net .net iis-7.5 session-state

I'm attempting to share Session information between PHP and .NET on the same server. The sessions will always be created by the .NET site. From my research I've come to believe that the Session-State

'Stringing together' a pymongo query based on a set of conditions

python mongodb pymongo

I have a set of conditions that I need to use to retrieve some data from a mongodb database (using pymongo). Some of these conditions are optional, and others may have more than one possible value...