shuf 随机排序
待扩展->Linux下的随机数生成和排序方法,包含各类shell和sort
讯享网
1.安装
yum install coreutils
或
brew install coreutils
或
apt install coreutils
进行安装。
2.详情
它能够接受标准输入,即管道。
讯享网man页给出的使用方法如下: NAME shuf - generate random permutations SYNOPSIS shuf [OPTION]... [FILE] shuf -e [OPTION]... [ARG]... shuf -i LO-HI [OPTION]... DESCRIPTION Write a random permutation of the input lines to standard output. With no FILE, or when FILE is -, read standard input. Mandatory arguments to long options are mandatory for short options too. -e, --echo treat each ARG as an input line -i, --input-range=LO-HI treat each number LO through HI as an input line -n, --head-count=COUNT output at most COUNT lines -o, --output=FILE write result to FILE instead of standard output --random-source=FILE get random bytes from FILE -r, --repeat output lines can be repeated -z, --zero-terminated line delimiter is NUL, not newline --help display this help and exit --version output version information and exit
其中常用参数:
-i 写入范围 -n 最多显示多少行 -o 将随机排序后的输出写到一个文件中
3.例子
假设需要生成3个范围为0-200的随机数到文件rand.txt中,只需要如下操作即可,效率:
shuf -i 0-200 -n 3 -o rand.txt
当然这个也是有不足之处的,比如,它并不是严格意义上的随机数。但是可以满足一些非专业和严格要求的需要。【具体细节待补充】
参考来源:
- shuf 命令:随机排序文件:https://blog.csdn.net/reyleon/article/details/

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/122825.html