Arthur de Jong

Open Source / Free Software developer

rl is a command-line tool that reads lines from an input file or stdin, randomizes the lines and outputs a specified number of lines. It does this with only a single pass over the input while trying to use as little memory as possible.

I wrote rl in my spare time mainly to be able to select a random audio file to play when my toast is done (script in combination with find and sleep). Another reason was to familiarize myself with autoconf and friends.

The most recent version of this page can be found at https://arthurdejong.org/rl/.

Warning: rl is software in development. The command line options and default behavior may change between releases.

Another Warning: I have mostly lost interest in this project and am not planning on doing much development on it any more. I will however still accept patches and fix important bugs (this more or less contradicts the previous warning).

Note: Users are recommended to use shuf from GNU coreutils instead which has been included since coreutils 6.0.

Download

At the moment rl is source-only. You can also get rl from Debian by doing:

% apt-get install randomize-lines

Or you can download one of the files below and follow the installation instructions below.

Copyright notice

Copyright © 2001-2008 Arthur de Jong

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU General Public License for more details.

A copy of the GNU General Public License is available in the download and can be found on the World Wide Web at http://www.gnu.org/copyleft/gpl.html. You can also obtain it by writing to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.

Installation instructions

rl should compile fine on most Unix-like operating systems. It is written to be as portable as possible.

rl is developed on Debian GNU/Linux 3.1 (sarge) and unstable (sid) and has been tested on Solaris 8 (once in a while), OpenBSD 2.7 (hardly ever) and HP-UX 10 (a long time ago).

rl uses a configure script to guess build parameters for your system. Configuration, compilation and installation would be as simple as one, two, three:

% ./configure
% make
% make install

For more details read the included README and INSTALL files.

Subversion repository

The randomize lines development repository is available through svn (read-only) with https://arthurdejong.org/svn/rl/
The repository is also browsable through viewcvs at https://arthurdejong.org/viewvc/rl/

Please note that the development version should work in general (although an ocasional bug shows up once in a whil) but the released versions are more thoroughly tested.

Also note that the address of the repository could change in the future.

Plans / TODO

rl is still in development and there are more features to implement. The development is currently based on the "it works for me" principle. Things to do:

  • The memory management can probably be improved a bit here and there avoiding a lot of calls to malloc() and free(), especially when multiple input files are read.
  • I would like to experiment with using temporary files instead of allocating memory which might improve performance with very large input data.
  • The currently used random generator is rand() which is seeded with the process id and the current time in microseconds. This method does not in any way provide cryptographicly strong random values. It might be a good idea to look in to cryptographicly strong random number generators for picking a line (low priority though).
  • Maybe there need to be more options added for some things like verbosity of error messages.
  • Another method for picking out a line in a file is to do a random fseek() in a file and find the matching line. Using this longer lines have a higher probability of being picked, but it is lot faster for picking a low number of lines.
  • Find out for which file sizes the random numbers produce accurate results. This really needs some work since some systems (HP-UX and Solaris) have a very low RAND_MAX.

If you want any features added to rl or you have comments or questions you can email me at arthur@arthurdejong.org. Patches for bug fixes and feature extensions are appreciated.

Fun and useful things to do with rl

  • sleep 240 ; play `find /sounds -name '*.au' -print | rl --count=1`
    Play a random sound after 4 minutes (perfect for toast).
  • renice +5 -u `who | cut '-d ' -f 1 | sort -u | rl --count=1`
    Renice all the processes of a random logged-in user.
  • Dangerous usage:
    kill -9 `ps -A | cut '-d ' -f 2 | rl --count=1`
    Kill a random process on your computer. Do this as root and see how long your system keeps working. Increase the --count for extra effect. (you might need to change the ps parameters depending on your system)

Links

You might want to have a look at the rl Freshmeat page:
http://freshmeat.net/projects/rl/

Similar programs:

Other similar programs? Other links? Any comment? Email me at: arthur@arthurdejong.org