Joined June 2019
·

macx

Posted to Random number generator in bash over 1 year ago

Im sharing my very simplistic script that always displays 5 digit random number. It will add Zero if the generated random numbers is less than 5 characters.

function Random5digit {
unset R1
unset R2
unset R3
R1=${RANDOM}
R2=${#R1}
N4=0
N3=00
N2=000
N1=0000
case $R2 in
5)
echo $R1
;;
4)
# Concatenate Zero to make a 5 digit Random number with trailing 0
R3+=$N4$R1
echo $R3
;;
3)
R3+=$N3$R1
echo $R3
;;
2)
R3+=$N2$R1
echo $R3
;;
1)
R3+=$N1$R1
echo $R3
;;
esac
}

Achievements
1 Karma
0 Total ProTip Views