shell生成指定范围随即整数
#!/bin/bash function rand(){ min=$1 max=$(($2-$min+1)) num=$(cat /dev/urandom | head -n 10 | cksum | awk -F ' ' '{print $1}') echo $(($num%$max+$min)) } rnd=$(rand 2 100) echo $rnd exit 0
#!/bin/bash
function rand(){ min=$1 max=$(($2-$min+1)) num=$(cat /dev/urandom | head -n 10 | cksum | awk -F ' ' '{print $1}') echo $(($num%$max+$min))}
rnd=$(rand 2 100)echo $rnd
exit 0