xref: /freebsd/usr.bin/random/random.6 (revision bdcbfde31e8e9b343f113a1956384bdf30d1ed62)
16ae1554aSColin Percival.\" Copyright (c) 1994
26ae1554aSColin Percival.\"	The Regents of the University of California.  All rights reserved.
36ae1554aSColin Percival.\"
46ae1554aSColin Percival.\" Redistribution and use in source and binary forms, with or without
56ae1554aSColin Percival.\" modification, are permitted provided that the following conditions
66ae1554aSColin Percival.\" are met:
76ae1554aSColin Percival.\" 1. Redistributions of source code must retain the above copyright
86ae1554aSColin Percival.\"    notice, this list of conditions and the following disclaimer.
96ae1554aSColin Percival.\" 2. Redistributions in binary form must reproduce the above copyright
106ae1554aSColin Percival.\"    notice, this list of conditions and the following disclaimer in the
116ae1554aSColin Percival.\"    documentation and/or other materials provided with the distribution.
126ae1554aSColin Percival.\" 3. Neither the name of the University nor the names of its contributors
136ae1554aSColin Percival.\"    may be used to endorse or promote products derived from this software
146ae1554aSColin Percival.\"    without specific prior written permission.
156ae1554aSColin Percival.\"
166ae1554aSColin Percival.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
176ae1554aSColin Percival.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
186ae1554aSColin Percival.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
196ae1554aSColin Percival.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
206ae1554aSColin Percival.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
216ae1554aSColin Percival.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
226ae1554aSColin Percival.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
236ae1554aSColin Percival.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
246ae1554aSColin Percival.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
256ae1554aSColin Percival.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
266ae1554aSColin Percival.\" SUCH DAMAGE.
276ae1554aSColin Percival.\"
28*06257a71SConrad Meyer.Dd February 15, 2020
296ae1554aSColin Percival.Dt RANDOM 6
306ae1554aSColin Percival.Os
316ae1554aSColin Percival.Sh NAME
326ae1554aSColin Percival.Nm random
336ae1554aSColin Percival.Nd random lines from a file or random numbers
346ae1554aSColin Percival.Sh SYNOPSIS
356ae1554aSColin Percival.Nm
366ae1554aSColin Percival.Op Fl elrUuw
376ae1554aSColin Percival.Op Fl f Ar filename
386ae1554aSColin Percival.Op Ar denominator
396ae1554aSColin Percival.Sh DESCRIPTION
406ae1554aSColin Percival.Nm Random
416ae1554aSColin Percivalhas two distinct modes of operations.
42*06257a71SConrad MeyerThe default is to read lines from standard input and write them to standard
43*06257a71SConrad Meyeroutput with a probability of 1.0 /
446ae1554aSColin Percival.Ar denominator .
45*06257a71SConrad Meyer.Ar ( denominator
46*06257a71SConrad Meyeris a real number greater than or equal to 1.0.)
476ae1554aSColin PercivalThe default
486ae1554aSColin Percival.Ar denominator
49*06257a71SConrad Meyerfor this mode of operation is 2.0, giving each line a 50% chance of
506ae1554aSColin Percivalbeing displayed.
516ae1554aSColin Percival.Pp
52*06257a71SConrad MeyerThe second mode of operation, selected with the
53*06257a71SConrad Meyer.Fl f Ar filename
54*06257a71SConrad Meyeroption, reads the specified file and outputs the randomized contents to
556ae1554aSColin Percivalstandard output.
56*06257a71SConrad MeyerThe contents can be randomized in units of lines (split on newline characters)
57*06257a71SConrad Meyeror in units of words (split on space characters as determined by
58*06257a71SConrad Meyer.Xr isspace 3 . )
596ae1554aSColin PercivalThe default
606ae1554aSColin Percival.Ar denominator
61*06257a71SConrad Meyerfor this mode of operation is 1.0, which displays every line.
626ae1554aSColin Percival.Pp
636ae1554aSColin PercivalThe options are as follows:
646ae1554aSColin Percival.Bl -tag -width Ds
656ae1554aSColin Percival.It Fl e
666ae1554aSColin PercivalIf the
676ae1554aSColin Percival.Fl e
686ae1554aSColin Percivaloption is specified,
696ae1554aSColin Percival.Nm
706ae1554aSColin Percivaldoes not read or write anything, and simply exits with a random
716ae1554aSColin Percivalexit value of 0 to
726ae1554aSColin Percival.Ar denominator
736ae1554aSColin Percival\&- 1, inclusive.
74*06257a71SConrad MeyerIn this mode,
75*06257a71SConrad Meyer.Ar denominator
76*06257a71SConrad Meyermust be less than or equal to 256.
776ae1554aSColin Percival.It Fl f Ar filename
786ae1554aSColin PercivalThe
796ae1554aSColin Percival.Fl f
806ae1554aSColin Percivaloption is used to specify the
816ae1554aSColin Percival.Ar filename
826ae1554aSColin Percivalto read from.
836ae1554aSColin PercivalStandard input is used if
846ae1554aSColin Percival.Ar filename
85*06257a71SConrad Meyeris
86*06257a71SConrad Meyer.Sq - .
876ae1554aSColin Percival.It Fl l
886ae1554aSColin PercivalRandomize the input via newlines (the default).
896ae1554aSColin Percival.It Fl r
90*06257a71SConrad MeyerDo not buffer output.
916ae1554aSColin Percival.It Fl U
92*06257a71SConrad MeyerReuse any given line or word when creating a randomized output.
936ae1554aSColin Percival.It Fl u
94*06257a71SConrad MeyerDo not select the same line or word from a file more than once (the default).
956ae1554aSColin PercivalThis does not guarantee uniqueness if there are two of the
96*06257a71SConrad Meyersame tokens in the input.
976ae1554aSColin Percival.It Fl w
986ae1554aSColin PercivalRandomize words separated by
996ae1554aSColin Percival.Xr isspace 3
1006ae1554aSColin Percivalinstead of newlines.
1016ae1554aSColin Percival.El
1026ae1554aSColin Percival.Sh SEE ALSO
1036ae1554aSColin Percival.Xr fortune 6
1046ae1554aSColin Percival.Sh HISTORY
1056ae1554aSColin PercivalThe
1066ae1554aSColin Percivalfunctionality to randomizing lines and words was added in 2003 by
1076ae1554aSColin Percival.An Sean Chittenden Aq Mt seanc@FreeBSD.org .
1086ae1554aSColin Percival.Sh BUGS
109*06257a71SConrad MeyerThis tool is a remnant of the "games" collection formerly part of
110*06257a71SConrad Meyer.Fx
111*06257a71SConrad Meyerbase.
112*06257a71SConrad MeyerIt probably should have been removed to ports with the rest of that collection.
113*06257a71SConrad MeyerIt does not have a coherent purpose and the motivation for it to be a core base
114*06257a71SConrad Meyerutility is nonobvious.
115*06257a71SConrad Meyer.Pp
1166ae1554aSColin PercivalNo index is used when printing out tokens from the list which
1176ae1554aSColin Percivalmakes it rather slow for large files (10MB+).
118