diff options
author | Assaf Gordon <assafgordon@gmail.com> | 2013-07-04 13:26:45 -0600 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2013-07-11 01:17:31 +0100 |
commit | 3a84293987bd21a92071a3d1c605ec9a2b3af1b4 (patch) | |
tree | 66aedec3a3800ba35045921fadb63fea557077e6 /doc | |
parent | f3fa3b2990c13623b80439039a92f72e08bb42be (diff) | |
download | coreutils-3a84293987bd21a92071a3d1c605ec9a2b3af1b4.tar.xz |
shuf: add --repetition to support repetition in output
main(): Process new option. Replace input_numbers_option_used()
with a local variable. Re-organize argument processing.
usage(): Describe the new option.
(write_random_numbers): A new function to generate a
permutation of the specified input range with repetition.
(write_random_lines): Likewise for stdin and --echo.
(write_permuted_numbers): New function refactored from
write_permuted_output().
(write_permuted_lines): Likewise.
* tests/misc/shuf.sh: Add tests for --repetitions option.
* doc/coreutils.texi: Mention --repetitions, add examples.
* TODO: Mention an optimization to avoid needing to
read all of the input into memory with --repetitions.
* NEWS: Mention new shuf option.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/coreutils.texi | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/coreutils.texi b/doc/coreutils.texi index b3233f602..ca10a16ff 100644 --- a/doc/coreutils.texi +++ b/doc/coreutils.texi @@ -4945,6 +4945,16 @@ commands like @code{shuf -o F <F} and @code{cat F | shuf -o F}. Use @var{file} as a source of random data used to determine which permutation to generate. @xref{Random sources}. +@item -r +@itemx --repetitions +@opindex -r +@opindex --repetitions +@cindex allowing repetitions in output values +Changes the default behaviour of @command{shuf}, allowing repetition in +output values (in which case, @option{--head-count} can be larger +than the number of input values). If @option{--head-count} is not +specified, output a single random value. + @zeroTerminatedOption @end table @@ -5004,6 +5014,33 @@ general, if there are @var{n} input lines, there are @var{n}! (i.e., @var{n} factorial, or @var{n} * (@var{n} - 1) * @dots{} * 1) possible output permutations. +@noindent +To output 50 random numbers between 0 and 9, use: + +@example +shuf --repetitions --input-range 0-9 --head-count 50 +@end example + +@noindent +or (using short options): + +@example +shuf -r -i0-9 -n50 +@end example + +@noindent +To simulate 100 coin flips, use: + +@example +shuf -r -n100 -e Head Tail +@end example + +@noindent +or +@example +printf '%s\n' Head Tail | shuf -r -n100 +@end example + @exitstatus |