List of usage examples for java.util.concurrent ThreadLocalRandom current
public static ThreadLocalRandom current()
From source file:com.github.tomakehurst.wiremock.http.UniformDistribution.java
@Override public long sampleMillis() { return ThreadLocalRandom.current().nextLong(lower, upper + 1); }
From source file:com.salesforce.jprotoc.ProtoTypeUtilsTest.java
@Test public void classWithJavaPackage() { final String className = randomAlphabetic(ThreadLocalRandom.current().nextInt(5, 10)); final String javaPackage = randomAlphabetic(ThreadLocalRandom.current().nextInt(5, 10)); assertThat(ProtoTypeMap.toJavaTypeName(className, null, javaPackage)) .isEqualTo(javaPackage + "." + className); }
From source file:org.red5.server.session.SessionManager.java
public static String getSessionId() { //random int from 1 - 100000 int part1 = rnd.nextInt(99999) + 1; //thread-safe "long" part long part2 = ThreadLocalRandom.current().nextLong(); //current time in millis long part3 = System.currentTimeMillis(); //generate uuid-type id String sessionId = createHash(part1 + "-" + part2 + "-" + part3); log.debug("Session id created: {}", sessionId); return sessionId; }
From source file:org.apache.kylin.rest.util.QueryIdGenerator.java
/** * @param project name of the project/* w ww .j av a 2s . co m*/ * @return the next query id. We try to generate unique id as much as possible, but don't guarantee it. */ @Nonnull public String nextId(final String project) { char[] postfix = new char[6]; for (int i = 0; i < postfix.length; i++) { postfix[i] = base26[ThreadLocalRandom.current().nextInt(base26.length)]; } return new String(postfix); //return String.format("%s_%s_%s", dateFormat.format(System.currentTimeMillis()), project, new String(postfix)); //disabled testcase: org.apache.kylin.rest.util.QueryIdGeneratorTest.testIdFormat() }
From source file:com.github.jinahya.persistence.ShadowTest.java
public static String newUsername(final EntityManager manager) { String username;//from www . jav a 2s . c o m do { final int count = ThreadLocalRandom.current().nextInt(Shadow.USERNAME_SIZE_MIN, Shadow.USERNAME_SIZE_MAX + 1); Assert.assertTrue(count >= Shadow.USERNAME_SIZE_MIN && count <= Shadow.USERNAME_SIZE_MAX); username = RandomStringUtils.randomAlphanumeric(32); } while (FIND_BY_USERNAME(manager, username) != null); return username; }
From source file:nz.co.testamation.testcommon.fixture.SomeFixture.java
public static Boolean someBoolean() { return ThreadLocalRandom.current().nextBoolean(); }
From source file:com.github.horrorho.inflatabledonkey.cloudkitty.CloudKitty.java
public static CloudKitty backupd(CKInit ckInit, String cloudKitToken) { String container = "com.apple.backup.ios"; String bundle = "com.apple.backupd"; String cloudKitUserId = ckInit.cloudKitUserId(); String baseUrl = ckInit.production().url(); String deviceID = UUID.randomUUID().toString(); String deviceHardwareID = new BigInteger(256, ThreadLocalRandom.current()).toString(16) .toUpperCase(Locale.US); RequestOperationFactory factory = new RequestOperationFactory(cloudKitUserId, container, bundle, deviceHardwareID, deviceID); InputStreamResponseHandler<List<CloudKit.ResponseOperation>> responseHandler = new InputStreamResponseHandler<>( new RawProtoDecoderLogger(null)); return new CloudKitty(factory, container, bundle, cloudKitUserId, cloudKitToken, baseUrl, responseHandler); }
From source file:org.apache.htrace.core.ProbabilitySampler.java
@Override public boolean next() { return ThreadLocalRandom.current().nextDouble() < threshold; }
From source file:com.microsoft.sqlserver.testframework.sqlType.SqlTime.java
public Object createdata() { Time temp = new Time( ThreadLocalRandom.current().nextLong(((Time) minvalue).getTime(), ((Time) maxvalue).getTime())); String timeNano = temp.toString() + "." + RandomStringUtils.randomNumeric(this.precision); // can pass String rather than converting to loacTime, but leaving it // unchanged for now to handle prepared statements return LocalTime.parse(timeNano, formatter); }
From source file:com.microsoft.sqlserver.testframework.sqlType.SqlDateTime2.java
public Object createdata() { Timestamp temp = new Timestamp(ThreadLocalRandom.current().nextLong(((Timestamp) minvalue).getTime(), ((Timestamp) maxvalue).getTime())); temp.setNanos(0);// w w w. ja v a 2s . c om String timeNano = temp.toString().substring(0, temp.toString().length() - 1) + RandomStringUtils.randomNumeric(this.precision); // can pass string rather than converting to LocalDateTime, but leaving // it unchanged for now to handle prepared statements return LocalDateTime.parse(timeNano, formatter); }