# randline(1)

## NAME

randline - deliver random line(s)
## SYNOPSIS

**randline**
[
-s
]
[
-#
]
[
files
]
## DESCRIPTION

*randline* selects a random line or lines from its input,
either standard input or the named *files*.
The algorithm used is the classic one-pass one described in Knuth,
with a couple of extensions.

There are a few options:

**-kh**
- (``keep header'')
Always pass through the first line of the input
(which is assumed to be a header of some sort);
perform random selection from among the remaining lines.
**-n** *n*
- (or just
**-***n*)
Select *n* lines.
**-s**
- (``stable'')
When selecting more than one line,
print them out in the same order they were in in the input,
rather than
shuffling them
randomly.
**-seed** *s*
- Use initial random seed
*s*.
**-seedfile** *f*
- Save random seed state in file
*f*
for repeatable behavior between runs.
**-version**
- Print program's version number.
**-w**
- Use weighted probabilities when selecting lines.
The first
(or last, whichever looks numeric)
column on each input
line gives its ``weight''.
Lines with higher weights are selected
with higher probability:
specifically,
if two lines a and b have weights in the ratio m:n,
line a will be selected m/n times as often as line b.
(The weights
of the selected lines
are
*not* printed on output.)
- Another way of thinking about this is that
if an input line has weight
*w*,
the behavior is the same as if that line appeared
in the input
*w* times.
- (This feature is still somewhat experimental.)
**-?**, **-help**
- Print a brief help message.

## BUGS

There is a fixed limit
(currently 1000)
on the longest input line that can be read.

There is no provision for
fractional or floating-point weights
under the **-w** option;
all weights must be integral.

## SEE ALSO

*shuffle*
## HISTORY

The program is based on the algorithm in Knuth, section xxx.

This documentation corresponds to version 3.01 of the program.

See
`http://www.eskimo.com/~scs/src/#randline`
for possible updates.

## AUTHOR

Steve Summit,
`scs@eskimo.com`