A version of fortune built with Zig, and thus runs on Windows. Fortune is a BSD program which prints witty messages to the console.
~/fortune> fortune 100
Computers can figure out all kinds of problems, except the things in
the world that just don't add up.
- Statically linked executable with small footprint
- Takes an input an integer to print a specific fortune. No in-built randomness. For a good source of randomness, you should use Powershell's in built Get-Random.
- Fast, under 20ms to print
You will need the Zig compiler, which you can download from their website.
To create, run
zig build
This will create an executable called fortune.exe
, or fortune
depending on your OS. This executable has the fortunes location built in, so you can move it around as you wish. However, the autogenerated fortunes/
folder cannot be moved around.
Simply replace fortune.txt
with your own file. The format of a fortune looks like this:
fortune1 CRLF
% CRLF
fortune2
The fortune.txt file is preprocessed to create a file called "fortunes-chunked.txt". This consists of fortunes which have been aligned on page boundaries. Then, we use the _lseek call to quickly load the page we want, find the fortune, and print it to the screen.