Replace all string matches in file with unique random number

Hello
Take this file...

Test01
Ref test
Version 01

Test02
Ref test
Version 02

Test66
Ref test
Version 66

Test99
Ref test
Version 99

I want to substitute every occurrence of Test[0-9]{2} with a unique random number, so for example, if I was using sed , substitution would be something like the below but obviously the below does reevaluate the random number for each occurrence of Test[0-9]{2}

num=$((1+RANDOM 20 % 60))
sed -ri "s/Test[0-9]{2}/Test${num}/" test_file

So on the execution of substitution, the file would read something like

Test59
Ref test
Version 01

Test57
Ref test
Version 02

Test48
Ref test
Version 66

Test51
Ref test
Version 99

Untested.

#!/bin/bash
rndm=($(shuf -e {00..99}))
while read line
do
   if [[ "$line" =~ ^Test ]]
   then
      printf "%s%s\n" Test ${rndm[10#${line#Test}]}
   else
      printf "%s\n" "$line"
   fi
done < infile > outfile

Creates a pseudo-random list of numbers 00-99 and uses the value of the current number in the test line to index the new number.

The 10# is required to stop bash from evaluating 08 and 09 as invalid octal numbers and instead evaluate them as valid decimals.

Andrew