OsSecureRandom extends Random implements Closeable, Configurable { @Override synchronized public void close() { if (stream != null) { IOUtils.cleanup(LOG, stream); stream = null; } } OsSecureRandom(); @Override synchronized void setConf(Configuration conf); @Override synchronized Configuration getConf(); @Override synchronized void nextBytes(byte[] bytes); @Override synchronized void close(); static final Log LOG; }
@Test(timeout=120000) public void testRandomBytes() throws Exception { OsSecureRandom random = getOsSecureRandom(); checkRandomBytes(random, 16); checkRandomBytes(random, 32); checkRandomBytes(random, 128); checkRandomBytes(random, 256); random.close(); }
@Test(timeout=120000) public void testRandomInt() throws Exception { OsSecureRandom random = getOsSecureRandom(); int rand1 = random.nextInt(); int rand2 = random.nextInt(); while (rand1 == rand2) { rand2 = random.nextInt(); } random.close(); }
@Test(timeout=120000) public void testRandomLong() throws Exception { OsSecureRandom random = getOsSecureRandom(); long rand1 = random.nextLong(); long rand2 = random.nextLong(); while (rand1 == rand2) { rand2 = random.nextLong(); } random.close(); }
@Test(timeout=120000) public void testRandomFloat() throws Exception { OsSecureRandom random = getOsSecureRandom(); float rand1 = random.nextFloat(); float rand2 = random.nextFloat(); while (rand1 == rand2) { rand2 = random.nextFloat(); } random.close(); }
@Test(timeout=120000) public void testRandomDouble() throws Exception { OsSecureRandom random = getOsSecureRandom(); double rand1 = random.nextDouble(); double rand2 = random.nextDouble(); while (rand1 == rand2) { rand2 = random.nextDouble(); } random.close(); }
@Test(timeout=120000) public void testRefillReservoir() throws Exception { OsSecureRandom random = getOsSecureRandom(); for (int i = 0; i < 8196; i++) { random.nextLong(); } random.close(); }