博客主页:http://blog.csdn.net/minna_d
写测试代码的时候常常需要产生1堆随机数,比如排序时定义1个链表,手动输入1串随机数总是很麻烦。
如:
<span style="font-size:12px;">List<Integer> list = Lists.newArrayList(37,96,81,13,49,20,64,56,22,86,60,20,80,1,98,70,71,12,10,44,89,48,20,39,52,50,45,88,54,22);</span>
脚本文件:
[root@jjy /shell]# cat random.sh
#!/bin/bash
#coder: jianjun.yu
#date: 2014年 12月 04日 星期4 14:44:00 HKT
until [[ $count -gt 0 && $min -gt 0 && $max -gt $min ]];
do
read -p "please input willbe produce random counts:" count
read -p "please input willbe produce random min:" min
read -p "please input willbe produce random max:" max
done
for i in `seq 1 $count`; do
result=$(($RANDOM % $(($max -$min)) + min ))
echo $result;
done
运行结果:
[root@jjy /shell]# random.sh | tr '
' ','
please input willbe produce random counts:30
please input willbe produce random min:1
please input willbe produce random max:100
37,96,81,13,49,20,64,56,22,86,60,20,80,1,98,70,71,12,10,44,89,48,20,39,52,50,45,88,54,22,