List of usage examples for java.util Random nextLong
public long nextLong()
From source file:com.adaptris.core.fs.ItemCacheCase.java
protected ProcessedItemList createCacheEntries(int count) { ProcessedItemList result = new ProcessedItemList(); Random r = new Random(); for (int i = 0; i < count; i++) { result.addProcessedItem(new ProcessedItem(CACHE_PREFIX + i, r.nextLong(), r.nextLong())); }// w w w .jav a 2 s . c o m return result; }
From source file:io.selendroid.server.model.SelendroidStandaloneDriverTest.java
@Test public void shouldCreateNewTestSession() throws Exception { // Setting up driver with test app and device stub SelendroidStandaloneDriver driver = getSelendroidStandaloneDriver(); SelendroidConfiguration conf = new SelendroidConfiguration(); conf.addSupportedApp(new File(APK_FILE).getAbsolutePath()); driver.initApplicationsUnderTest(conf); DeviceStore store = new DeviceStore(false, EMULATOR_PORT, anDeviceManager()); DeviceForTest emulator = new DeviceForTest(DeviceTargetPlatform.ANDROID16); Random random = new Random(); final UUID definedSessionId = new UUID(random.nextLong(), random.nextLong()); emulator.testSessionListener = new TestSessionListener(definedSessionId.toString(), "test") { @Override/*from w w w. j a v a 2 s . c o m*/ public SelendroidResponse executeSelendroidRequest(Properties params) { return null; } }; store.addDeviceToStore(emulator); driver.setDeviceStore(store); // testing new session creation SelendroidCapabilities capa = new SelendroidCapabilities(); capa.setAut(TEST_APP_ID); capa.setAndroidTarget(DeviceTargetPlatform.ANDROID16.name()); try { String sessionId = driver.createNewTestSession(new JSONObject(capa.asMap()), 0); Assert.assertNotNull(UUID.fromString(sessionId)); } finally { // this will also stop the http server emulator.stop(); } }
From source file:gov.nih.nci.cabig.caaers.web.filters.CsrfPreventionFilter.java
private String generateCsrfToken() { long seed = System.currentTimeMillis(); Random r = new Random(); r.setSeed(seed);/*w w w . jav a2 s . c om*/ return Long.toString(seed) + Long.toString(Math.abs(r.nextLong())); }
From source file:com.almarsoft.GroundhogReader.lib.MessagePosterLib.java
private String generateMsgId() { String host = mPrefs.getString("host", "noknownhost.com").trim(); Random rand = new Random(); String randstr = Long.toString(Math.abs(rand.nextLong()), 72); return "<" + "almarsoft." + randstr + "@" + host + ">"; }
From source file:test.integ.be.fedict.performance.TestPKILoadCRLsTest.java
private List<X509Certificate> getCertificateChain(KeyPair testKeyPair, CAConfiguration ca, Random random, DateTime notBefore, DateTime notAfter) throws Exception { long t = Math.abs(random.nextLong()) % (0 != ca.getCrlRecords() ? ca.getCrlRecords() : 2); if (0 == t) { t = 1;/*from w w w. j a v a 2 s.c om*/ } BigInteger serialNumber = new BigInteger(Long.toString(t + ca.getCrlRecords())); String crlPath = new URI( testPkiPath + "/" + CrlServlet.PATH + "?" + CrlServlet.CA_QUERY_PARAM + "=" + ca.getName(), false) .toString(); String ocspPath = new URI( testPkiPath + "/" + OcspServlet.PATH + "?" + OcspServlet.CA_QUERY_PARAM + "=" + ca.getName(), false) .toString(); LOG.debug("generate for CA=" + ca.getName() + " sn=" + serialNumber); X509Certificate certificate = TestUtils.generateCertificate(testKeyPair.getPublic(), "CN=Test", ca.getKeyPair().getPrivate(), ca.getCertificate(), notBefore, notAfter, "SHA512WithRSAEncryption", true, false, false, ocspPath, crlPath, null, serialNumber); List<X509Certificate> certificateChain = new LinkedList<X509Certificate>(); certificateChain.add(certificate); certificateChain.add(ca.getCertificate()); if (null != ca.getRoot()) { CAConfiguration parent = ca.getRoot(); while (null != parent.getRoot()) { certificateChain.add(parent.getCertificate()); parent = parent.getRoot(); } certificateChain.add(parent.getCertificate()); } return certificateChain; }
From source file:org.satsang.security.BlowfishEasy.java
/** * Encrypts a string (in Unicode).//w ww . j a va 2 s .c o m * * @param plaintext * string to encrypt * @param rndgen * random generator (usually a java.security.SecureRandom * instance) * @return encrypted string in binhex format */ public String encryptString(String plaintext, Random rndgen) { return encStr(plaintext, rndgen.nextLong()); }
From source file:org.apache.hadoop.mapreduce.lib.input.TestCombineSequenceFileInputFormat.java
@Test(timeout = 10000) public void testFormat() throws IOException, InterruptedException { Job job = Job.getInstance(conf);/* w w w.j ava 2 s . c o m*/ Random random = new Random(); long seed = random.nextLong(); random.setSeed(seed); localFs.delete(workDir, true); FileInputFormat.setInputPaths(job, workDir); final int length = 10000; final int numFiles = 10; // create files with a variety of lengths createFiles(length, numFiles, random, job); TaskAttemptContext context = MapReduceTestUtil.createDummyMapTaskAttemptContext(job.getConfiguration()); // create a combine split for the files InputFormat<IntWritable, BytesWritable> format = new CombineSequenceFileInputFormat<IntWritable, BytesWritable>(); for (int i = 0; i < 3; i++) { int numSplits = random.nextInt(length / (SequenceFile.SYNC_INTERVAL / 20)) + 1; LOG.info("splitting: requesting = " + numSplits); List<InputSplit> splits = format.getSplits(job); LOG.info("splitting: got = " + splits.size()); // we should have a single split as the length is comfortably smaller than // the block size assertEquals("We got more than one splits!", 1, splits.size()); InputSplit split = splits.get(0); assertEquals("It should be CombineFileSplit", CombineFileSplit.class, split.getClass()); // check the split BitSet bits = new BitSet(length); RecordReader<IntWritable, BytesWritable> reader = format.createRecordReader(split, context); MapContext<IntWritable, BytesWritable, IntWritable, BytesWritable> mcontext = new MapContextImpl<IntWritable, BytesWritable, IntWritable, BytesWritable>( job.getConfiguration(), context.getTaskAttemptID(), reader, null, null, MapReduceTestUtil.createDummyReporter(), split); reader.initialize(split, mcontext); assertEquals("reader class is CombineFileRecordReader.", CombineFileRecordReader.class, reader.getClass()); try { while (reader.nextKeyValue()) { IntWritable key = reader.getCurrentKey(); BytesWritable value = reader.getCurrentValue(); assertNotNull("Value should not be null.", value); final int k = key.get(); LOG.debug("read " + k); assertFalse("Key in multiple partitions.", bits.get(k)); bits.set(k); } } finally { reader.close(); } assertEquals("Some keys in no partition.", length, bits.cardinality()); } }
From source file:org.motechproject.mobile.imp.serivce.oxd.PasswordEncoderImpl.java
public String generateSalt() { Random random = new Random(); StringBuffer buf = new StringBuffer(); buf.append(Long.toString(System.currentTimeMillis())); buf.append(Long.toString(random.nextLong())); return rawToHex(sha1Encode(buf.toString())); }
From source file:org.apache.hadoop.fs.TestLocalFileSystem.java
void testFileCrcInternal(boolean inlineChecksum) throws IOException { ((Log4JLogger) HftpFileSystem.LOG).getLogger().setLevel(Level.ALL); Random random = new Random(1); final long seed = random.nextLong(); random.setSeed(seed);/* ww w . ja v a2 s . c o m*/ FileSystem fs = FileSystem.getLocal(new Configuration()); // generate random data final byte[] data = new byte[1024 * 1024 + 512 * 7 + 66]; random.nextBytes(data); // write data to a file Path foo = new Path(TEST_ROOT_DIR, "foo_" + inlineChecksum); { final FSDataOutputStream out = fs.create(foo, false, 512, (short) 2, 512); out.write(data); out.close(); } // compute data CRC DataChecksum checksum = DataChecksum.newDataChecksum(DataChecksum.CHECKSUM_CRC32, 1); checksum.update(data, 0, data.length); // compute checksum final int crc = fs.getFileCrc(foo); System.out.println("crc=" + crc); TestCase.assertEquals((int) checksum.getValue(), crc); }
From source file:org.apache.edgent.samples.utils.sensor.PeriodicRandomSensor.java
/** * Create a periodic sensor stream with readings from {@link Random#nextLong()}. * @param t the topology to add the sensor stream to * @param periodMsec how frequently to generate a reading * @return the sensor value stream//from w ww .j a va2 s. com */ public TStream<Pair<Long, Long>> newLong(Topology t, long periodMsec) { Random r = newRandom(); return t.poll(() -> new Pair<Long, Long>(System.currentTimeMillis(), r.nextLong()), periodMsec, TimeUnit.MILLISECONDS); }