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:
Output the Nth fortune, or
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.
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.