Check whether g generates Z_n*, Z_n or a subgroup of order q of Z_p*, with the order of g and the subgroup it generates.
Procedure
How it works
In a group of order $N$, the order of any element divides $N$ (Lagrange’s theorem). So $g$ is a generator exactly when its order is $N$ itself, and to show that one does not compute all $N$ powers. If the order were a proper divisor of $N$, it would divide $N/r$ for a prime $r \mid N$. Hence: $g$ generates the group exactly when $g^{N/r} \ne 1$ for every prime $r$ dividing $N$. This needs only a few modular powers, even for 2048-bit numbers, once $N$ is factored.
Modulo $7$, $N = 6 = 2 \cdot 3$: $3^3 \equiv 6$ and $3^2 \equiv 2$, neither is $1$, so $3$ is a generator. But $2^3 \equiv 1$, so $2$ has order $3$ and generates only $\{1, 2, 4\}$. In the additive group $\mathbb Z_n$ the test becomes $\gcd(g, n) = 1$, and a non-generator $g$ produces the multiples of $\gcd(g, n)$.
Checking a generator matters for real parameters: if the order of a Diffie-Hellman generator has small prime factors, the secret exponent can be found modulo each of them (the Pohlig-Hellman reduction). For a safe prime $p = 2q + 1$, as in the standard groups of RFC 3526, the test is just $g^2 \ne 1$ and $g^q \ne 1$. There $g = 2$ is a square, so it generates the subgroup of order $q$ rather than all of $\mathbb Z_p^*$, which is what one wants.
Everything is calculated in your browser. Nothing you type leaves your device.