DrngImpl implements Drng { @Override public boolean nextBit() { if (bitsLeft == 0) { drbg.nextBytes(randomBytes); bitsLeft = RANDOMBUFFER_SIZE * Byte.SIZE; } int index = RANDOMBUFFER_SIZE * Byte.SIZE - bitsLeft; byte currentByte = randomBytes[index / (Byte.SIZE)]; byte currentBit = (byte) (currentByte >> (index % (Byte.SIZE))); bitsLeft--; return currentBit == 0x00 ? false : true; } DrngImpl(Drbg drbg); @Override int nextInt(int limit); @Override long nextLong(long limit); @Override BigInteger nextBigInteger(BigInteger limit); @Override boolean nextBit();  }
@Test public void testNextBit() { int iterations = 1000; int trueCount = 0; int falseCount = 0; for (int i = 0; i < iterations; i++) { boolean currentRand = drng.nextBit(); if (currentRand) { trueCount++; } else { falseCount++; } } assertTrue(trueCount > iterations / 10); assertTrue(falseCount > iterations / 10); }