There is nothing stopping you from doing both. In fact I would go a step further and stick with integer arithmetic as far as possible. For example:
$a1 = non_zero_random(-2000,2000,1);
$b1 = non_zero_random(-2000,2000,1);
$c1 = non_zero_random(-2000,2000,1);
$mag1 = sqrt($a1**2+$b1**2+$c1**2);
@dir = ($a1/$mag1,$b1/$mag1,$c1/$mag1);
$a = $a1/100;
$b = $b1/100;
$c = $c1/100;
$mag = $mag1/100;
On an unrelated note, you can save a lot of effort in this problem by using the MathObject Vector class:
DOCUMENT();
loadMacros(
"PGstandard.pl",
"MathObjects.pl",
"PGML.pl",
"PGcourse.pl",
);
Context("Vector");
$showPartialCorrectAnswers = 1;
$v = Vector([random(-2000,2000,1),random(-2000,2000,1),random(-2000,2000,1)]);
$v1 = $v/100;
$u = $v/norm($v);
TEXT(beginproblem());
BEGIN_PGML
What is the unit vector for the vector [`[$v1]`]?
Answer: [_]*{$u}
END_PGML
ENDDOCUMENT();