ITeye博客

Shell随机生成几个不重复的随机数

polyahu · 2013-02-04 23:48 · Shell · 编程语言 · Markdown

模拟体育彩票,36选7。 要求:随机,7个不重复,1到36这些整数。


#!/bin/bash

touch ./temp
>temp

while [ `sort temp | uniq | wc -l` != 7 ] 
do
  echo `expr $RANDOM % 36 + 1` >> temp
done

sort temp | uniq

rm temp

just for fun... 练习一下shell编程。

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。