生成隨機(jī)數(shù)工具
來源:程序員人生 發(fā)布時(shí)間:2014-12-23 08:26:22 閱讀次數(shù):3695次
博客主頁:http://blog.csdn.net/minna_d
寫測(cè)試代碼的時(shí)候常常需要產(chǎn)生1堆隨機(jī)數(shù),比如排序時(shí)定義1個(gè)鏈表,手動(dòng)輸入1串隨機(jī)數(shù)總是很麻煩。
如:
<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
運(yùn)行結(jié)果:
[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,
生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對(duì)您的學(xué)習(xí)有所幫助,可以手機(jī)掃描二維碼進(jìn)行捐贈(zèng)