Example usage for java.util.concurrent ThreadLocalRandom nextLong

List of usage examples for java.util.concurrent ThreadLocalRandom nextLong

Introduction

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

Prototype

public long nextLong() 

Source Link

Document

Returns a pseudorandom long value.

Usage

From source file:fi.luontola.cqrshotel.JsonSerializationTest.java

private static Object randomValue(Class<?> type) {
    ThreadLocalRandom random = ThreadLocalRandom.current();
    if (type == UUID.class) {
        return UUID.randomUUID();
    }/*from  w  w w . ja  v a  2  s .  c om*/
    if (type == LocalDate.class) {
        return LocalDate.of(random.nextInt(2000, 2100),
                random.nextInt(Month.JANUARY.getValue(), Month.DECEMBER.getValue() + 1),
                random.nextInt(1, Month.FEBRUARY.minLength() + 1));
    }
    if (type == Money.class) {
        return Money.of(random.nextDouble(0, 1000), pickRandom(Monetary.getCurrencies()));
    }
    if (type == Instant.class) {
        return Instant.ofEpochMilli(random.nextLong());
    }
    if (type == String.class) {
        return RandomStringUtils.randomAlphanumeric(random.nextInt(10));
    }
    if (type == int.class) {
        return random.nextInt();
    }
    throw new IllegalArgumentException("Unsupported type: " + type);
}

From source file:org.neo4j.io.pagecache.PageCacheTest.java

@Test
public void mustSupportUnalignedWordAccesses() throws Exception {
    // 8 MB pages, 10 of them for 80 MB.
    // This way we are sure to write across OS page boundaries. The default
    // size of Huge Pages on Linux is 2 MB, but it can be configured to be
    // as large as 1 GB - at least I have not heard of anyone trying to
    // configure it to be more than that.
    int pageSize = 1024 * 1024 * 8;
    getPageCache(fs, 10, pageSize, PageCacheTracer.NULL);

    ThreadLocalRandom rng = ThreadLocalRandom.current();

    try (PagedFile pagedFile = pageCache.map(file("a"), filePageSize);
            PageCursor cursor = pagedFile.io(0, PF_SHARED_WRITE_LOCK)) {
        assertTrue(cursor.next());//from   w w w  . j a va  2 s. c o m

        for (int i = 0; i < pageSize - 8; i++) {
            cursor.setOffset(i);
            long x = rng.nextLong();
            cursor.putLong(x);
            cursor.setOffset(i);
            String reason = "Failed to read back the value that was written at " + "offset " + toHexString(i);
            assertThat(reason, toHexString(cursor.getLong()), is(toHexString(x)));
        }
    }
}