List of usage examples for java.util Random nextLong
public long nextLong()
From source file:edu.indiana.lib.osid.component.id.Id.java
protected Id() throws org.osid.shared.SharedException { long base;/* w w w. jav a 2s. c o m*/ Random random; base = getIdBase(); random = new Random(base); idString = String.valueOf(base) + "-" + String.valueOf(random.nextLong()); random = null; }
From source file:processing.app.UpdateCheck.java
public void run() { //System.out.println("checking for updates..."); // generate a random id in case none exists yet Random r = new Random(); long id = r.nextLong(); String idString = PreferencesData.get("update.id"); if (idString != null) { id = Long.parseLong(idString); } else {// w w w. ja v a2s.c o m PreferencesData.set("update.id", String.valueOf(id)); } try { String info; info = URLEncoder.encode( id + "\t" + PApplet.nf(BaseNoGui.REVISION, 4) + "\t" + System.getProperty("java.version") + "\t" + System.getProperty("java.vendor") + "\t" + System.getProperty("os.name") + "\t" + System.getProperty("os.version") + "\t" + System.getProperty("os.arch"), "UTF-8"); int latest = readInt(downloadURL + "?" + info); String lastString = PreferencesData.get("update.last"); long now = System.currentTimeMillis(); if (lastString != null) { long when = Long.parseLong(lastString); if (now - when < ONE_DAY) { // don't annoy the shit outta people return; } } PreferencesData.set("update.last", String.valueOf(now)); String prompt = tr("A new version of Arduino is available,\n" + "would you like to visit the Arduino download page?"); if (base.activeEditor != null) { if (latest > BaseNoGui.REVISION) { Object[] options = { tr("Yes"), tr("No") }; int result = JOptionPane.showOptionDialog(base.activeEditor, prompt, tr("Update"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]); if (result == JOptionPane.YES_OPTION) { Base.openURL(tr("http://www.arduino.cc/en/Main/Software")); } } } } catch (Exception e) { //e.printStackTrace(); //System.err.println("Error while trying to check for an update."); } }
From source file:terrastore.util.collect.MergeSetTest.java
@Test public void testPerf() { Set<String> first = new TreeSet<String>(); Random r1 = new Random(System.nanoTime()); for (int i = 0; i < 100000; i++) { first.add("" + r1.nextLong()); }/*from ww w.j a va2 s. co m*/ Set<String> second = new TreeSet<String>(); Random r2 = new Random(System.nanoTime()); for (int i = 0; i < 100000; i++) { second.add("" + r2.nextLong()); } StopWatch sw = new StopWatch(); sw.start(); Sets.merge(first, second); sw.stop(); System.out.println("Elapsed time in millis: " + sw.getTime()); }
From source file:net.sourceforge.subsonic.controller.NetworkSettingsController.java
protected void doSubmitAction(Object cmd) throws Exception { NetworkSettingsCommand command = (NetworkSettingsCommand) cmd; settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled()); settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled()); settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); if (!settingsService.isLicenseValid() && settingsService.getUrlRedirectTrialExpires() == null) { Date expiryDate = new Date(System.currentTimeMillis() + TRIAL_DAYS * 24L * 3600L * 1000L); settingsService.setUrlRedirectTrialExpires(expiryDate); }//w ww. j ava 2s .c o m if (settingsService.getServerId() == null) { Random rand = new Random(System.currentTimeMillis()); settingsService.setServerId(String.valueOf(Math.abs(rand.nextLong()))); } settingsService.setSubsonicUrl(StringUtils.lowerCase(command.getSubsonicUrl())); settingsService.save(); networkService.initPortForwarding(); networkService.initUrlRedirection(true); }
From source file:org.madsonic.controller.NetworkSettingsController.java
protected void doSubmitAction(Object cmd) throws Exception { NetworkSettingsCommand command = (NetworkSettingsCommand) cmd; command.setToast(true);/*from w w w .j av a 2 s . co m*/ settingsService.setPortForwardingEnabled(command.isPortForwardingEnabled()); settingsService.setUrlRedirectionEnabled(command.isUrlRedirectionEnabled()); settingsService.setUrlRedirectFrom(StringUtils.lowerCase(command.getUrlRedirectFrom())); // if (settingsService.isUsePremiumServices()) { // if (!settingsService.isLicenseValid() && settingsService.getTrialExpires() == null) { // Date expiryDate = new Date(System.currentTimeMillis() + TRIAL_DAYS * 24L * 3600L * 1000L); // settingsService.setTrialExpires(expiryDate); // } // } if (settingsService.getServerId() == null) { Random rand = new Random(System.currentTimeMillis()); settingsService.setServerId(String.valueOf(Math.abs(rand.nextLong()))); } settingsService.setMadsonicUrl(StringUtils.lowerCase(command.getMadsonicUrl())); settingsService.save(); networkService.initPortForwarding(0); networkService.initUrlRedirection(true); }
From source file:org.gaixie.jibu.security.service.impl.LoginServiceImpl.java
public Token generateToken(String username) { Connection conn = null;//from w w w .j a v a 2 s. co m Token token = null; try { conn = ConnectionUtils.getConnection(); User user = userDAO.get(conn, username); if (user == null) return null; Random randomGenerator = new Random(); long randomLong = randomGenerator.nextLong(); // Date date = new Date(); Calendar calendar = Calendar.getInstance(); //calendar.setTime(date); calendar.add(calendar.DAY_OF_MONTH, +1); long time = calendar.getTimeInMillis(); Timestamp ts = new Timestamp(time); String key = MD5.encodeString(Long.toString(randomLong) + time, null); token = new Token(key, "password", ts, user.getId()); tokenDAO.save(conn, token); DbUtils.commitAndClose(conn); } catch (SQLException e) { DbUtils.rollbackAndCloseQuietly(conn); logger.error(e.getMessage()); return null; } finally { DbUtils.closeQuietly(conn); } return token; }
From source file:org.apache.directory.server.core.partition.impl.btree.jdbm.BTreeRedirectMarshallerTest.java
@Test public void testRoundTripTests() throws IOException { byte[] bites = createBites(); Random random = new Random(); for (int ii = 0; ii < 100; ii++) { long orig = random.nextLong(); bites = marshaller.serialize(new BTreeRedirect(orig)); assertEquals(orig, marshaller.deserialize(bites).getRecId()); }/*from w w w . j av a 2s. c o m*/ }
From source file:org.diorite.commons.math.DioriteRandomUtils.java
public static long getRandomLong(Random random, long min, long max) throws IllegalArgumentException { if (min == max) { return max; }/* www. j a v a 2 s . c o m*/ Validate.isTrue(max > min, "Max can't be smaller than min!"); return (Math.abs(random.nextLong()) % ((max - min) + 1)) + min; }
From source file:org.apache.blur.trace.hdfs.HdfsTraceStorage.java
private String getRequestIdPathName(String requestId, Random random) { return requestId + "_" + random.nextLong(); }
From source file:org.apache.hadoop.mapred.TestCombineSequenceFileInputFormat.java
@Test(timeout = 10000) public void testFormat() throws Exception { JobConf job = new JobConf(conf); Reporter reporter = Reporter.NULL;/*from w ww . ja v a 2 s .com*/ Random random = new Random(); long seed = random.nextLong(); LOG.info("seed = " + seed); random.setSeed(seed); localFs.delete(workDir, true); FileInputFormat.setInputPaths(job, workDir); final int length = 10000; final int numFiles = 10; // create a file with various lengths createFiles(length, numFiles, random); // create a combine split for the files InputFormat<IntWritable, BytesWritable> format = new CombineSequenceFileInputFormat<IntWritable, BytesWritable>(); IntWritable key = new IntWritable(); BytesWritable value = new BytesWritable(); for (int i = 0; i < 3; i++) { int numSplits = random.nextInt(length / (SequenceFile.SYNC_INTERVAL / 20)) + 1; LOG.info("splitting: requesting = " + numSplits); InputSplit[] splits = format.getSplits(job, numSplits); LOG.info("splitting: got = " + splits.length); // 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.length); InputSplit split = splits[0]; assertEquals("It should be CombineFileSplit", CombineFileSplit.class, split.getClass()); // check each split BitSet bits = new BitSet(length); RecordReader<IntWritable, BytesWritable> reader = format.getRecordReader(split, job, reporter); try { while (reader.next(key, value)) { assertFalse("Key in multiple partitions.", bits.get(key.get())); bits.set(key.get()); } } finally { reader.close(); } assertEquals("Some keys in no partition.", length, bits.cardinality()); } }