public static BigInteger primeRoot(BigInteger p) {
		if (!p.isProbablePrime(100))
			return null;

		ArrayList<BigInteger> tried = new ArrayList<BigInteger>();
		while (true) {
			boolean found = false;
			BigInteger g = null;
			while (!found) {
				g = new BigInteger(p.bitCount(), new java.util.Random());
				if (tried.size() == 0)
					tried.add(g);
				boolean notInList = true;
				for (int i = 0; i < tried.size(); i++)
					if (tried.get(i) == g)
						notInList = false;
				if (notInList)
					tried.add(g);
				found = tried.get(tried.size() - 1) == g;
			}

			int[] mods = new int[p.subtract(new BigInteger("" + 1)).intValue()];
			for (int i = 0; i < (p.subtract(new BigInteger("" + 1)).intValue()); i++)
				mods[i] = g.modPow(new BigInteger("" + i), p).intValue();
			if (allUnequal(mods))
				return g;
		}
	}