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.


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

CComboBoxEx problems with different DPI, height calculation

windows winapi mfc combobox dpi

I want to add a CComboBoxEx on my form, but I have to align it with other controls and make it the same height.

Two side-by-side elements, one unknown/variable width, the other filling up remainder of horizontal space?

html css localization chromium-embedded

I am working on a video game UI that is built in HTML/CSS/JS (Angular). This question has specifically to do with the chat component of the UI, which is a chat box with an input field and send but...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.