diff options
author | seanc <seanc@FreeBSD.org> | 2003-02-11 19:32:18 +0000 |
---|---|---|
committer | seanc <seanc@FreeBSD.org> | 2003-02-11 19:32:18 +0000 |
commit | 0f9b087524425d34260b48dfe452fe59123a8921 (patch) | |
tree | 097b8974b8e346530a10af46d5f0dba419e30286 /games/random/random.6 | |
parent | 978695f103a5c784ac63a0337e502e29660341f3 (diff) | |
download | FreeBSD-src-0f9b087524425d34260b48dfe452fe59123a8921.zip FreeBSD-src-0f9b087524425d34260b48dfe452fe59123a8921.tar.gz |
Update random(6) to have the ability to randomize a file/stdin based
off of lines or words. See the man page for details.
Reviewed by: markm
MFC after: 3 days
Diffstat (limited to 'games/random/random.6')
-rw-r--r-- | games/random/random.6 | 67 |
1 files changed, 60 insertions, 7 deletions
diff --git a/games/random/random.6 b/games/random/random.6 index 16a6e22..9706d74 100644 --- a/games/random/random.6 +++ b/games/random/random.6 @@ -10,7 +10,7 @@ .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: +.\" must display the following acknowledgment: .\" This product includes software developed by the University of .\" California, Berkeley and its contributors. .\" 4. Neither the name of the University nor the names of its contributors @@ -32,7 +32,7 @@ .\" @(#)random.6 8.2 (Berkeley) 3/31/94 .\" $FreeBSD$ .\" -.Dd March 31, 1994 +.Dd February 8, 2003 .Dt RANDOM 6 .Os .Sh NAME @@ -41,14 +41,31 @@ .Sh SYNOPSIS .Nm .Op Fl er +.Op Fl f Ar filename .Op Ar denominator .Sh DESCRIPTION .Nm Random -reads lines from the standard input and copies them to the standard -output with a probability of 1/denominator. -The default value for +has two distinct modes of operations. The default is to read in lines +from stdin and randomly write them out to stdout with a probability of +1 / +.Ar denominator . +The default .Ar denominator -is 2. +for this mode of operation is 2, giving each line a 50/50 chance of +being displayed. +.Pp +The second mode of operation is to read in a file from +.Ar filename +and randomize the contents of the file and send it back out to stdout. +The contents can be randomized based off of newlines or based off of +space characters as determined by +.Xr isspace 3 . +The default +.Ar denominator +for this mode of operation is 1, which gives each line a chance to be +displayed, but in a +.Xr random 3 +order. .Pp The options are as follows: .Bl -tag -width Ds @@ -61,10 +78,46 @@ does not read or write anything, and simply exits with a random exit value of 0 to .Ar denominator \&- 1, inclusive. +.It Fl f Ar filename +The +.Fl f +option is used to specify the +.Ar filename +to read from. stdin is used if the filename is set to "-". +.It Fl l +Randomize the input via newlines (the default). .It Fl r The .Fl r option guarantees that the output is unbuffered. +.It Fl u +Tells +.Xr random 6 +not to 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 from the input, but it does prevent selecting the same +token more than once. +.It Fl U +Tells +.Xr random 6 +that it is okay for it to reuse any given line or word when creating a +randomized output. +.It Fl w +Randomize words separated by +.Xr isspace 3 +instead of newlines. .El .Sh SEE ALSO -.Xr fortune 6 +.Xr fortune 6 , +.Xr random 3 +.Sh BUGS +There is no index used when printing out tokens from the list which +makes rather slow for large files (10MB+). If this were used in +performance sensitive areas, I'd do something about it. For smaller +files, however, it should still be quite fast and efficient. +.Sh HISTORY +Original +.Xr random 6 +game was brought in from BSD 4.4 Lite by jkh in 1994. The +functionality to randomizing lines and words was added in 2003 by +seanc. |