jeudi 29 août 2019

$RANDOM Probleem in Bash

i write'd an script with bash in while loop code:

number=0
while [ 1500 -gt $number ]
do
var="abcdefghijklmnopqrstuvxyz"
letter1="${var:$(( RANDOM % ${#var} )):1}"
letter2="${var:$(( RANDOM % ${#var} )):1}"
a=$RANDOM
b=$RANDOM
c=$(( $a * $b))
echo "$letter1$letter2 $c" >> a.txt
number=$(( 1 + $number ))
done

but now i see duplicate numbers in Result:

Result:
ab 15474
at 15474
yh 15474
gd 15474
re 18696
jg 18696

the numbers are duplicate i guess the $RANDOM changes after a invariant time and my script starts agian the the While loop faster than the $RANDOM changes can you help me an other randomization way?

please help




Aucun commentaire:

Enregistrer un commentaire