shell、perl随机数
shell:
1 [huangzhiwei@localhost huangzhiwei]$ cat test.sh 2 #!/bin/sh 3 lines=`wc -l 4 num=$(($RANDOM % $lines)) 5 rnum=$(($num + 1)) 6 name=`sed -n "$rnum p" test.txt|cut -f1` 7 xuehao=`sed -n "$rnum p" test.txt|cut -f2` 8 echo "欢迎"$name"上台演讲,他的学号是:"$xuehao 9 --------------------------------------------------------------------
perl:
1 #!/usr/bin/perl -w 2 open (TEST, "< test.txt") or die"$!"; 3 @a=<TEST>; 4 $num=$#a; 5 $n=int (rand $num); 6 $stu=$a[$n]; 7 ($name,$xuehao)=(split /\t/,$stu)[0,1]; 8 print"欢迎$name 上台演讲,他的学号是:$xuehao";