---
name: "random"
section: "6"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/random"
---

# random(6)

random lines from a file or random numbers

## NAME

**random** – random lines from a file or random numbers

## SYNOPSIS

**random** \[**-elrUuw**\] \[**-f** *filename*\] \[*denominator*\]

## DESCRIPTION

**Random** has two distinct modes of operations. The default is to read lines from standard input and write them to standard output with a probability of 1.0 / *denominator*. (*denominator* is a real number greater than or equal to 1.0.) The default *denominator* for this mode of operation is 2.0, giving each line a 50% chance of being displayed.

The second mode of operation, selected with the **-f** *filename* option, reads the specified file and outputs the randomized contents to standard output. The contents can be randomized in units of lines (split on newline characters) or in units of words (split on space characters as determined by [isspace(3)](/isspace/3.md).) The default *denominator* for this mode of operation is 1.0, which displays every line.

The options are as follows:

- **-e**

  If the **-e** option is specified, **random** does not read or write anything, and simply exits with a random exit value of 0 to *denominator* - 1, inclusive. In this mode, *denominator* must be less than or equal to 256.

- **-f** *filename*

  The **-f** option is used to specify the *filename* to read from. Standard input is used if *filename* is ‘-’.

- **-l**

  Randomize the input via newlines (the default).

- **-r**

  Do not buffer output.

- **-U**

  Reuse any given line or word when creating a randomized output.

- **-u**

  Do not select the same line or word from a file more than once (the default). This does not guarantee uniqueness if there are two of the same tokens in the input.

- **-w**

  Randomize words separated by [isspace(3)](/isspace/3.md) instead of newlines.

## SEE ALSO

[fortune(6)](/fortune/6.md)

## HISTORY

The functionality to randomizing lines and words was added in 2003 by Sean Chittenden ⟨*seanc@FreeBSD.org*⟩.

## BUGS

This tool is a remnant of the "games" collection formerly part of FreeBSD base. It probably should have been removed to ports with the rest of that collection. It does not have a coherent purpose and the motivation for it to be a core base utility is nonobvious.

No index is used when printing out tokens from the list which makes it rather slow for large files (10MB+).
