Example usage for java.util Random nextLong

List of usage examples for java.util Random nextLong

Introduction

In this page you can find the example usage for java.util Random nextLong.

Prototype

public long nextLong() 

Source Link

Document

Returns the next pseudorandom, uniformly distributed long value from this random number generator's sequence.

Usage

From source file:com.navjagpal.fileshare.WebServer.java

private String createCookie() {
    Random r = new Random();
    String value = Long.toString(Math.abs(r.nextLong()), 36);
    ContentValues values = new ContentValues();
    values.put("name", "id");
    values.put("value", value);
    values.put("expiry", (int) System.currentTimeMillis() / 1000 + COOKIE_EXPIRY_SECONDS);
    mCookiesDatabase.insert("cookies", "name", values);
    return value;
}

From source file:com.oneguy.recognize.engine.GoogleStreamingEngine.java

private String generateRequestPairKey() {
    Random random = new Random(System.currentTimeMillis());
    long value = random.nextLong();
    return Long.toHexString(value);
}

From source file:org.apache.camel.component.gora.hbase.example.GoraSpringSupportTest.java

/**
 * Test multiple puts like 1K for example
 *
 * @throws Exception//from   w  ww .  j  a  v a 2  s  .  co m
 */
@Test
public void testingMultiplePuts() throws Exception {

    final int numberOfPuts = 1000;
    final Random idGenerator = new Random();

    for (int i = 0; i < numberOfPuts; i++) {
        mock.expectedMessageCount(1);

        final Map<String, Object> headers = new HashMap();
        final long id = idGenerator.nextLong();

        headers.put("goraOperation", "pUt");
        headers.put(GoraAttribute.GORA_KEY.value, id);

        template.sendBodyAndHeaders("direct:putCode", ExchangePattern.InOnly, getSamplePageview(), headers);

        assertMockEndpointsSatisfied();
        mock.reset();
    }
}

From source file:org.apache.hadoop.io.compress.TestCodec.java

public void testGzipCompatibility() throws IOException {
    Random r = new Random();
    long seed = r.nextLong();
    r.setSeed(seed);//ww  w .ja  v  a2 s  .c  o  m
    LOG.info("seed: " + seed);

    DataOutputBuffer dflbuf = new DataOutputBuffer();
    GZIPOutputStream gzout = new GZIPOutputStream(dflbuf);
    byte[] b = new byte[r.nextInt(128 * 1024 + 1)];
    r.nextBytes(b);
    gzout.write(b);
    gzout.close();

    DataInputBuffer gzbuf = new DataInputBuffer();
    gzbuf.reset(dflbuf.getData(), dflbuf.getLength());

    Configuration conf = new Configuration();
    conf.setBoolean("hadoop.native.lib", false);
    CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf);
    Decompressor decom = codec.createDecompressor();
    assertNotNull(decom);
    assertEquals(BuiltInGzipDecompressor.class, decom.getClass());
    InputStream gzin = codec.createInputStream(gzbuf, decom);

    dflbuf.reset();
    IOUtils.copyBytes(gzin, dflbuf, 4096);
    final byte[] dflchk = Arrays.copyOf(dflbuf.getData(), dflbuf.getLength());
    assertTrue(java.util.Arrays.equals(b, dflchk));
}

From source file:org.apache.hadoop.io.compress.TestCodec.java

void GzipConcatTest(Configuration conf, Class<? extends Decompressor> decomClass) throws IOException {
    Random r = new Random();
    long seed = r.nextLong();
    r.setSeed(seed);/*  w ww.  j a  v a2  s.  co  m*/
    LOG.info(decomClass + " seed: " + seed);

    final int CONCAT = r.nextInt(4) + 3;
    final int BUFLEN = 128 * 1024;
    DataOutputBuffer dflbuf = new DataOutputBuffer();
    DataOutputBuffer chkbuf = new DataOutputBuffer();
    byte[] b = new byte[BUFLEN];
    for (int i = 0; i < CONCAT; ++i) {
        GZIPOutputStream gzout = new GZIPOutputStream(dflbuf);
        r.nextBytes(b);
        int len = r.nextInt(BUFLEN);
        int off = r.nextInt(BUFLEN - len);
        chkbuf.write(b, off, len);
        gzout.write(b, off, len);
        gzout.close();
    }
    final byte[] chk = Arrays.copyOf(chkbuf.getData(), chkbuf.getLength());

    CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf);
    Decompressor decom = codec.createDecompressor();
    assertNotNull(decom);
    assertEquals(decomClass, decom.getClass());
    DataInputBuffer gzbuf = new DataInputBuffer();
    gzbuf.reset(dflbuf.getData(), dflbuf.getLength());
    InputStream gzin = codec.createInputStream(gzbuf, decom);

    dflbuf.reset();
    IOUtils.copyBytes(gzin, dflbuf, 4096);
    final byte[] dflchk = Arrays.copyOf(dflbuf.getData(), dflbuf.getLength());
    assertTrue(java.util.Arrays.equals(chk, dflchk));
}

From source file:org.jbpm.workbench.pr.client.editors.instance.list.variables.dash.DataSetProcessInstanceWithVariablesListPresenterTest.java

@Test
public void abortProcessInstancesTest() {
    final Random random = new Random();
    final List<String> containers = new ArrayList<String>();
    containers.add("container");

    final List<Long> pIds = new ArrayList<Long>();
    pIds.add(random.nextLong());
    pIds.add(random.nextLong());//from  w w  w .  j  av  a 2  s.  com
    pIds.add(random.nextLong());

    presenter.abortProcessInstance(containers, pIds);

    verify(processService).abortProcessInstances(anyString(), eq(containers), eq(pIds));
}

From source file:test.integ.be.fedict.performance.TestPKIPerformanceTest.java

private List<X509Certificate> getCertificateChain(KeyPair testKeyPair, List<CAConfiguration> leaves,
        Random random, DateTime notBefore, DateTime notAfter) throws Exception {

    int leafIndex = random.nextInt(leaves.size());
    CAConfiguration ca = leaves.get(leafIndex);
    boolean revoked = random.nextInt(100) < revokedPercentage;
    long t = Math.abs(random.nextLong()) % (0 != ca.getCrlRecords() ? ca.getCrlRecords() : 2);
    if (0 == t) {
        t = 1;/*from   ww  w .j  a v  a2 s  .c  om*/
    }
    BigInteger serialNumber;
    if (revoked) {
        serialNumber = new BigInteger(Long.toString(t));
        expectedRevokedCount++;
    } else {
        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() + " revoked=" + revoked + " 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.apache.hadoop.mapreduce.TestMapCollection.java

@Test
public void testRandom() throws Exception {
    Configuration conf = new Configuration();
    conf.setInt(Job.COMPLETION_POLL_INTERVAL_KEY, 100);
    Job job = Job.getInstance(conf);// w ww. j  a va2s  . c  o  m
    conf = job.getConfiguration();
    conf.setInt(MRJobConfig.IO_SORT_MB, 1);
    conf.setClass("test.mapcollection.class", RandomFactory.class, RecordFactory.class);
    final Random r = new Random();
    final long seed = r.nextLong();
    LOG.info("SEED: " + seed);
    r.setSeed(seed);
    conf.set(MRJobConfig.MAP_SORT_SPILL_PERCENT, Float.toString(Math.max(0.1f, r.nextFloat())));
    RandomFactory.setLengths(conf, r, 1 << 14);
    conf.setInt("test.spillmap.records", r.nextInt(500));
    conf.setLong("test.randomfactory.seed", r.nextLong());
    runTest("random", job);
}

From source file:org.apache.hadoop.mapreduce.TestMapCollection.java

@Test
public void testRandomCompress() throws Exception {
    Configuration conf = new Configuration();
    conf.setInt(Job.COMPLETION_POLL_INTERVAL_KEY, 100);
    Job job = Job.getInstance(conf);//from ww w . jav  a2  s. co  m
    conf = job.getConfiguration();
    conf.setInt(MRJobConfig.IO_SORT_MB, 1);
    conf.setBoolean(MRJobConfig.MAP_OUTPUT_COMPRESS, true);
    conf.setClass("test.mapcollection.class", RandomFactory.class, RecordFactory.class);
    final Random r = new Random();
    final long seed = r.nextLong();
    LOG.info("SEED: " + seed);
    r.setSeed(seed);
    conf.set(MRJobConfig.MAP_SORT_SPILL_PERCENT, Float.toString(Math.max(0.1f, r.nextFloat())));
    RandomFactory.setLengths(conf, r, 1 << 14);
    conf.setInt("test.spillmap.records", r.nextInt(500));
    conf.setLong("test.randomfactory.seed", r.nextLong());
    runTest("randomCompress", job);
}

From source file:io.selendroid.server.model.AndroidNativeElement.java

public AndroidNativeElement(View view, ServerInstrumentation instrumentation, KeySender keys,
        KnownElements ke) {//from  ww  w. j  a v  a 2 s .  c  om
    Preconditions.checkNotNull(view);
    this.viewRef = new WeakReference<View>(view);
    hashCode = view.hashCode() + 31;
    this.instrumentation = instrumentation;
    this.keys = keys;
    this.nativeElementSearchScope = new NativeElementSearchScope(instrumentation, keys, ke);
    this.ke = ke;

    Random random = new Random();
    this.id = new UUID(random.nextLong(), random.nextLong()).toString();
}