Example usage for java.util.concurrent ThreadLocalRandom nextDouble

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

Introduction

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

Prototype

public double nextDouble(double origin, double bound) 

Source Link

Document

Returns a pseudorandom double value between the specified origin (inclusive) and bound (exclusive).

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();
    }/* w ww .j ava2  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);
}