Simplify fractions for use in feedback

Sometimes in the feedback you have a fraction, but due to the randomised numbers you have it might end up not being in it's simplest form. For example consider you random numbers $a & $b and want to have $a/$b in LaTeX
\( \frac{$a}{$b} \)
. To ensure that it is in it's simplest form I use this MapleTA code:
MapleTA:
$a = rint(1, 20);
$b = rint(1, 20);
$gcd = gcd($a, $b);
$numerator = $a/$gcd;
$denominator = $b/$gcd;
LaTeX:
\( \frac{$numerator}{\denominator} \)