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:br.com.webbudget.application.component.Color.java

/**
 * @return uma cor randomica//from   w  w w.  j  a  v  a 2  s .  c  o  m
 */
public static Color randomize() {

    int rgb[] = new int[3];

    for (int i = 0; i < 3; i++) {
        rgb[i] = ThreadLocalRandom.current().nextInt(1, 255 + 1);
    }
    return new Color(rgb[0], rgb[1], rgb[2]);
}

From source file:com.github.tomakehurst.wiremock.http.LogNormal.java

@Override
public long sampleMillis() {
    return Math.round(Math.exp(ThreadLocalRandom.current().nextGaussian() * sigma) * median);
}

From source file:ru.jts_dev.common.config.UtilsConfig.java

/**
 * Random bean should be loaded lazily, and only in points, that it's really needed,
 * because random is instance of {@link ThreadLocalRandom}
 * and if all random beans will be initialized in single thread - no performance impact will be provided.
 * <p>//w  ww.j a  v  a  2  s. c  o  m
 * <pre class="code">
 * &#064;Autowired ApplicationContent context;
 * ...
 * Random random = context.getBean(Random.class);
 * ...
 * </pre>
 *
 * @return ThreadLocalRandom for caller thread
 */
@Bean
@Scope(SCOPE_PROTOTYPE)
public Random random() {
    return ThreadLocalRandom.current();
}

From source file:pl.project13.maven.git.GitIntegrationTest.java

@Before
public void setUp() throws Exception {
    // generate unique sandbox for this test
    File sandbox;/* w ww . j  av  a2 s .com*/
    do {
        currSandbox = SANDBOX_DIR + "sandbox"
                + Integer.toString(ThreadLocalRandom.current().nextInt(Integer.MAX_VALUE));
        sandbox = new File(currSandbox);
    } while (sandbox.exists());

    mavenSandbox = new FileSystemMavenSandbox(currSandbox);
    mojo = new GitCommitIdMojo();
    initializeMojoWithDefaults(mojo);
}

From source file:org.jspare.server.transaction.TidGeneratorImpl.java

@Override
public String generate() {

    StringBuilder tid = new StringBuilder();
    tid.append(LocalDateTime.now().format(dtf));
    tid.append(StringUtils.leftPad(String.valueOf(ThreadLocalRandom.current().nextLong(MIN, MAX)), 6, "0"));
    tid.append(calculateVerifyDigit(tid.toString()));
    return tid.toString();
}

From source file:org.apache.druid.query.aggregation.datasketches.tuple.GenerateTestData.java

private static void generateBucketTestData() throws Exception {
    double meanTest = 10;
    double meanControl = 10.2;
    Path path = FileSystems.getDefault().getPath("bucket_test_data.tsv");
    try (BufferedWriter out = Files.newBufferedWriter(path, StandardCharsets.UTF_8)) {
        Random rand = ThreadLocalRandom.current();
        for (int i = 0; i < 1000; i++) {
            writeBucketTestRecord(out, "test", i, rand.nextGaussian() + meanTest);
            writeBucketTestRecord(out, "control", i, rand.nextGaussian() + meanControl);
        }// w  w  w .j  a  v a  2 s . co  m
    }
}

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();
    }//  w ww.  ja va 2s. 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:com.github.jinahya.persistence.ShadowTest.java

public static byte[] newPassword() {

    final byte[] password = new byte[ThreadLocalRandom.current().nextInt(1, 32)];

    ThreadLocalRandom.current().nextBytes(password);

    return password;
}

From source file:dk.dma.navnet.client.AbstractClientConnectionTest.java

@Before
public void before() {
    clientPort = ThreadLocalRandom.current().nextInt(40000, 50000);
    ws = new TestWebSocketServer(clientPort);
    ws.start();/*w ww.ja  v a2 s  .c o  m*/
    t = ws.addEndpoint(new TestClientEndpoint());
    conf = MaritimeCloudClientConfiguration.create(ID1);
    conf.setHost("localhost:" + clientPort);
    conf.setKeepAlive(1, TimeUnit.HOURS);
}

From source file:com.autsia.socialboot.SocialBootApplicationTests.java

@Test
public void performanceTest() throws Exception {
    final IQueue<Object> queue = hazelcastInstance.getQueue(SocialBootApplication.class.getSimpleName());

    ExecutorService threadPool = Executors.newFixedThreadPool(1);
    threadPool.submit((Runnable) () -> {
        while (true) {
            String id = String.valueOf(ThreadLocalRandom.current().nextLong());
            twitterService.consumeTweetFromExternalSystem(id, text);
        }/*from   w w w .j a v a 2s  . c  o m*/
    });
    while (queue.isEmpty()) {
        Thread.sleep(1000);
    }
    int countBefore = queue.size();
    Thread.sleep(MEASUREMENT_DELAY);
    int countAfter = queue.size();
    LOGGER.info("Tweets processed: {}", countAfter - countBefore);
}