From be5f03a64e7d0d27a88d6f341a8beff8ad788fc9 Mon Sep 17 00:00:00 2001 From: Bob Polis Date: Thu, 28 Nov 2024 17:43:25 +0100 Subject: [PATCH] Add README.md --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..ada9f15 --- /dev/null +++ b/README.md @@ -0,0 +1,35 @@ +# ranlin — Choose a random line from a text file + +Implemented using an elegant algorithm, originally stolen from the "Perl +Cookbook", which does not have more than a single text line in memory at any +time. + +The trivial way to pick a random line would of course be to read all lines into +an array, and then pick a random index for that array. + +The algorithm used here, however, will generate a random number between zero and +the number of lines read, every time a line is read. Then, if that number is +greater than one, the line will be taken as the resulting line, for that moment. + +Of course, when more lines are read after that, any line can be picked in that +fashion, _where the chance the line is picked is still equal for evey line_. + +Brilliant. + +## Build + +`make` + +## Install + +`sudo make install` + +or, on OpenBSD: + +`doas gmake install` + +## Run + +`ranlin ` + +Output will be some random line from the file.