Question: Randomly generate variables and numbers

Hello,

I want to randomly generate variables and numbers that look something along the lines of this:

(3x)(-2y2)
(-3x2y4) (4x2)
(-b2y4) (2b2)
(-3x2y4) (4x2y4)
(4x)(5x2)



Here's my code so far:

for k to 5 do

V := LinearAlgebra:-RandomVector(2, generator = rand(1 .. 9));
W := LinearAlgebra:-RandomVector(2, generator = (2*rand(0 .. 1)-1)*rand(1 .. 9));

if `not`(V[1] = V[2]) then

print(Question);
print(x^``(V[1])*x^``(V[2]));
print(Answer);
print(x^V[1]*x^V[2])


end if;
end do;

Output:

                                  Question

                                   (8)  (5)
                                  x    x  

                                   Answer

                                      13
                                     x 

                                  Question

                                   (4)  (2)
                                  x    x  

                                   Answer

                                      6
                                     x
etc

Please Wait...