2-parameter Pythagorean triple formulas

Derivation:

Reorganize x^2+y^2=z^2 to get x^2 equal to a product of two factors.
x^2 = z^2 - y^2
x^2 = (z-y)*(z+y)

Assign the factors on the right to two new variables.
u = (z-y)
v = (z+y)

Then we have
x = sqrt(u*v)
y = (v-u)/2
z = (v+u)/2

To make selecting the parameters u and v easier, replace them with expressions that are divisible by 2 and such that u*v is a perfect square, since we want x, y, and z to be integers.
u -> 2*s^2
v -> 2*t^2

Then we finally have
x = 2*s*t
y = t^2 - s^2
z = t^2 + s^2,
choosing t larger than s so that y will come out positive.

As for making primitive Pythagorean triples, observe that if s and t have a common divisor different from 1, then x, y, and z will be divisible by this factor. So we must choose s and t to be coprime. Also, if s and t are both odd, then x, y, and z will all be even which means they're divisible by 2, so s and t must not have the same parity.