How many generators Z_n*, Z_n or a prime order subgroup of Z_p* has, which they are, and the smallest one with the standard test.
Procedure
How it works
A generator $g$ of a cyclic group of order $N$ is an element whose powers $g, g^2, \dots, g^N = 1$ run through the whole group. Once one is known, all others follow: $g^k$ has order $N / \gcd(k, N)$, so the generators are the $g^k$ with $\gcd(k, N) = 1$, and there are $\varphi(N)$ of them. For $\mathbb Z_7^*$ ($N = 6$) that gives $\varphi(6) = 2$ generators, $3$ and $5$; a cyclic $\mathbb Z_n^*$ has $\varphi(\varphi(n))$, and the additive group $\mathbb Z_n$ has $\varphi(n)$, the numbers coprime to $n$.
To find one, factor $N$ and try $g = 2, 3, \dots$: $g$ is a generator exactly when $g^{N/r} \ne 1$ for every prime $r$ dividing $N$, because a smaller order would divide one of these $N/r$. Generators are common, so the search is short; factoring $N$ is the hard part.
Diffie-Hellman, DSA and Schnorr signatures usually work in a subgroup of prime order $q$ of $\mathbb Z_p^*$ (a Schnorr group), where $q$ divides $p - 1$. Its elements are the powers $h^{(p-1)/q}$, and since $q$ is prime every element except $1$ generates it. With a safe prime $p = 2q + 1$ this subgroup is the set of squares modulo $p$.
Everything is calculated in your browser. Nothing you type leaves your device.