Z implements Identifiable, FiniteField<Z> { @Override public FiniteField.Element<Z> getRandomElement() { int n = q.bitLength() + 1; BigInteger randomElement; do { randomElement = new BigInteger(n, random); } while(randomElement.compareTo(q) >= 0); return element(randomElement); } Z(int q);  Z(int q, Random random);  Z(BigInteger q);  Z(BigInteger q, Random random); @Override String getIdentity(); @Override FiniteField.Element<Z> getZero(); FiniteField.Element<Z> element(BigInteger element); FiniteField.Element<Z> element(Integer element); @Override FiniteField.Element<Z> getOne(); @Override FiniteField.Element<Z> getRandomElement();  }
@Test public void shouldBeAbleToReturnARandomElementTheFiniteField() { FiniteField.Element<Z> element = field.getRandomElement(); assertEquals(field, element.getFiniteField()); }