Example usage for java.util.concurrent ThreadLocalRandom current

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

Introduction

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

Prototype

public static ThreadLocalRandom current() 

Source Link

Document

Returns the current thread's ThreadLocalRandom .

Usage

From source file:Main.java

static final void localInit() {
    // This will kick an init. In ConcurrentHashMap, it is only called after having check if the probe is there, so
    // there shouldn't be any drawback to do it that way
    ThreadLocalRandom.current();
}

From source file:com.github.jinahya.codec.Tests.java

static Random random() {

    return ThreadLocalRandom.current();
}

From source file:com.github.jinahya.codec.PercentCodecTestHelper.java

private static Random random() {

    return ThreadLocalRandom.current();
}

From source file:com.github.jinahya.io.bit.BitIoTests.java

static ThreadLocalRandom random() {

    return ThreadLocalRandom.current();
}

From source file:Main.java

/**
 * Selects pseudo-random elements from a collection
 *
 * @param c      Collection to select from
 * @param n      Number of elements to select
 * @param unique Whether the selection should be unique
 * @return Random element(s) from collection
 *///from  www .  ja  va 2s . c  o m
public static <E> Collection<E> randomElement(Collection<E> c, int n, boolean unique) {
    List<E> out = new ArrayList<>();
    List<E> l = new ArrayList<>(c);

    while (out.size() < n) {
        E e = l.get(ThreadLocalRandom.current().nextInt(0, l.size()));
        out.add(e);
        if (unique)
            l.remove(e);
    }
    return out;
}

From source file:nz.co.testamation.testcommon.fixture.SomeFixture.java

public static int someInt() {
    return ThreadLocalRandom.current().nextInt();
}

From source file:Main.java

/**
 * Gets the {@link ThreadLocalRandom} for the current {@link Thread}.
 *
 * @return the current Thread's ThreadLocalRandom
 *//*from   w  w w  .  j a va2 s.  com*/
public static ThreadLocalRandom concurrentRandom() {
    return ThreadLocalRandom.current();
}

From source file:com.joyent.manta.http.ShufflingDnsResolver.java

/**
 * Shuffles an array of addresses that were returned from a DNS query.
 * Shuffle algorithm inspired by <a href="http://stackoverflow.com/a/1520212/33611">this stackoverflow post.</a>
 * @param addresses addresses to shuffle
 *///from  ww  w . j  a v  a2 s.c  om
private static void shuffle(final InetAddress[] addresses) {
    // Only shuffle if we have 2 or more addresses
    if (addresses.length < 2) {
        return;
    }

    Random random = ThreadLocalRandom.current();

    for (int i = addresses.length - 1; i > 0; i--) {
        int index = random.nextInt(i + 1);
        // Simple swap
        InetAddress a = addresses[index];
        addresses[index] = addresses[i];
        addresses[i] = a;
    }
}

From source file:nz.co.testamation.testcommon.fixture.SomeFixture.java

public static long someLong() {
    return ThreadLocalRandom.current().nextLong();
}

From source file:com.salesforce.jprotoc.ProtoTypeUtilsTest.java

@Test
public void classWithEnclosingClassAndJavaPackage() {
    final String className = randomAlphabetic(ThreadLocalRandom.current().nextInt(5, 10));
    final String enclosingClassName = randomAlphabetic(ThreadLocalRandom.current().nextInt(5, 10));
    final String javaPackage = randomAlphabetic(ThreadLocalRandom.current().nextInt(5, 10));

    assertThat(ProtoTypeMap.toJavaTypeName(className, enclosingClassName, javaPackage))
            .isEqualTo(javaPackage + "." + enclosingClassName + "." + className);
}