List of usage examples for java.util.concurrent ThreadLocalRandom current
public static ThreadLocalRandom current()
From source file:ru.portal.controllers.RestController.java
@RequestMapping(value = { "/random/{id}" }) @ResponseBody//w w w . j a v a 2s . com public DeferredResult<ResponseEntity<String>> random(@PathVariable Long id) { DeferredResult<ResponseEntity<String>> deferredResult = new DeferredResult<>(); String result = String.format("random : %s", ThreadLocalRandom.current().nextLong(id)); HttpHeaders headers = new HttpHeaders(); headers.add("Content-type", "application/json;charset=UTF-8"); ResponseEntity responseEntity = new ResponseEntity<>(result, headers, HttpStatus.OK); deferredResult.setResult(responseEntity); return deferredResult; }
From source file:com.github.jinahya.codec.BossVsEngineerTestCpuTimeDecode.java
@Test public void testDecode() { final double[] consumedLikeABoss = new double[ROUNDS]; final double[] consumedLikeAnEngineer = new double[ROUNDS]; for (int i = 0; i < ROUNDS; i++) { final byte[] encoded = Tests.encodedBytes(); if (ThreadLocalRandom.current().nextBoolean()) { consumedLikeABoss[i] = decodeLikeABoss(encoded); consumedLikeAnEngineer[i] = decodeLikeAnEngineer(encoded); } else {/*from w w w . j ava 2s . c o m*/ consumedLikeAnEngineer[i] = decodeLikeAnEngineer(encoded); consumedLikeABoss[i] = decodeLikeABoss(encoded); } } LOGGER.log(Level.INFO, "consumed.like.a.boss: {0} [{1}, {2}, {3}, ..., {4}, {5}, {6}]", new Object[] { StatUtils.mean(consumedLikeABoss), consumedLikeABoss[0], consumedLikeABoss[1], consumedLikeABoss[2], consumedLikeABoss[consumedLikeABoss.length - 3], consumedLikeABoss[consumedLikeABoss.length - 2], consumedLikeABoss[consumedLikeABoss.length - 1] }); LOGGER.log(Level.INFO, "consumed.like.an.engineer: {0}" + " [{1}, {2}, {3}, ..., {4}, {5}, {6}]", new Object[] { StatUtils.mean(consumedLikeAnEngineer), consumedLikeAnEngineer[0], consumedLikeAnEngineer[1], consumedLikeAnEngineer[2], consumedLikeAnEngineer[consumedLikeAnEngineer.length - 3], consumedLikeAnEngineer[consumedLikeAnEngineer.length - 2], consumedLikeAnEngineer[consumedLikeAnEngineer.length - 1] }); }
From source file:com.github.jinahya.codec.BossVsEngineerTestCpuTimeEncode.java
@Test public void testEncode() { final double[] consumedLikeABoss = new double[ROUNDS]; final double[] consumedLikeAnEngineer = new double[ROUNDS]; for (int i = 0; i < ROUNDS; i++) { final byte[] decoded = Tests.decodedBytes(); if (ThreadLocalRandom.current().nextBoolean()) { consumedLikeABoss[i] = encodeLikeABoss(decoded); consumedLikeAnEngineer[i] = encodeLikeAnEngineer(decoded); } else {//from www . ja v a 2 s . c om consumedLikeAnEngineer[i] = encodeLikeAnEngineer(decoded); consumedLikeABoss[i] = encodeLikeABoss(decoded); } } LOGGER.log(Level.INFO, "consumed.like.a.boss: {0} [{1}, {2}, {3}, ..., {4}, {5}, {6}]", new Object[] { StatUtils.mean(consumedLikeABoss), consumedLikeABoss[0], consumedLikeABoss[1], consumedLikeABoss[2], consumedLikeABoss[consumedLikeABoss.length - 3], consumedLikeABoss[consumedLikeABoss.length - 2], consumedLikeABoss[consumedLikeABoss.length - 1] }); LOGGER.log(Level.INFO, "consumed.like.an.engineer: {0}" + " [{1}, {2}, {3}, ..., {4}, {5}, {6}]", new Object[] { StatUtils.mean(consumedLikeAnEngineer), consumedLikeAnEngineer[0], consumedLikeAnEngineer[1], consumedLikeAnEngineer[2], consumedLikeAnEngineer[consumedLikeAnEngineer.length - 3], consumedLikeAnEngineer[consumedLikeAnEngineer.length - 2], consumedLikeAnEngineer[consumedLikeAnEngineer.length - 1] }); }
From source file:org.hawkular.datamining.forecast.utils.AutomaticPeriodIdentificationTest.java
@Test public void testAutomaticPeriodIdentificationVariableDataLength() throws IOException { ModelData rModel = ModelReader.read("sineTrendLowVar"); int lastIndex = rModel.getPeriods() * 2; while (lastIndex < rModel.getData().size()) { List<DataPoint> trainData = rModel.getData().subList(0, lastIndex); int periods = AutomaticPeriodIdentification.periods(trainData); Assert.assertEquals(rModel.getPeriods(), periods, 1); lastIndex += ThreadLocalRandom.current().nextInt(0, rModel.getPeriods() + 1); }// w w w .j av a 2s . c o m int[] startIndices = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 28, 47 }; for (int startIndex : startIndices) { List<DataPoint> trainData = rModel.getData().subList(startIndex, rModel.getData().size()); int periods = AutomaticPeriodIdentification.periods(trainData); Assert.assertEquals(rModel.getPeriods(), periods, 1); } }
From source file:com.navercorp.pinpoint.web.vo.stat.chart.agent.ResponseTimeChartGroupTest.java
private List<SampledResponseTime> createSampledResponseTimeList(TimeWindow timeWindow) { List<SampledResponseTime> sampledResponseTimeList = new ArrayList<>(); int maxConnectionSize = ThreadLocalRandom.current().nextInt(MIN_VALUE_OF_MAX_CONNECTION_SIZE) + MIN_VALUE_OF_MAX_CONNECTION_SIZE; long from = timeWindow.getWindowRange().getFrom(); long to = timeWindow.getWindowRange().getTo(); for (long i = from; i < to; i += timeWindow.getWindowSlotSize()) { sampledResponseTimeList.add(createSampledResponseTime(i, maxConnectionSize)); }//from w w w . ja v a2 s. c om return sampledResponseTimeList; }
From source file:org.evors.rs.unibot.sim.SimulatedUnibot.java
@Override public void step(double velocity, double angularVelocity) { super.step(velocity, angularVelocity); rangeFinderLine = getNewRangeFinder(); range = (float) (getWorld().traceRay(rangeFinderLine) + ThreadLocalRandom.current().nextGaussian() * RANGEFINDER_NOISE_STDEV); }
From source file:nz.co.testamation.testcommon.fixture.SomeFixture.java
public static Integer someIntBetween(int minInclusive, int maxExclusive) { return ThreadLocalRandom.current().nextInt(minInclusive, maxExclusive); }
From source file:org.neo4j.kernel.TokenCreationIT.java
public Label[] getLabels() { int randomLabelValue = ThreadLocalRandom.current().nextInt(2) + 1; Label[] labels = new Label[randomLabelValue]; for (int i = 0; i < labels.length; i++) { labels[i] = Label.label(RandomStringUtils.randomAscii(randomLabelValue)); }//from w ww. j a v a 2 s . com return labels; }
From source file:org.rhq.metrics.simulator.MeasurementCollector.java
private Set<MeasurementDataNumeric> generateData() { Set<MeasurementDataNumeric> data = new HashSet<MeasurementDataNumeric>(batchSize); long timestamp = dateTimeService.nowInMillis(); ThreadLocalRandom random = ThreadLocalRandom.current(); for (int i = 0; i < batchSize; ++i) { data.add(new MeasurementDataNumeric(timestamp, startingScheduleId + i, random.nextDouble())); }/*from w w w. java2 s . c o m*/ return data; }
From source file:com.github.jinahya.codec.PercentBinaryDecoderProxyTest.java
@Test(invocationCount = 128) public void testDecode() throws Exception { final BinaryDecoder decoder = (BinaryDecoder) PercentBinaryDecoderProxy.newInstance(); try {/*from w w w. ja va 2 s . c om*/ decoder.decode((Object) null); Assert.fail("passed: decode((Object) null)"); } catch (NullPointerException npe) { // ok } try { decoder.decode((byte[]) null); Assert.fail("passed: decode((byte[]) null)"); } catch (NullPointerException npe) { // ok } final Random random = ThreadLocalRandom.current(); final byte[] expected = new byte[random.nextInt(128)]; random.nextBytes(expected); System.out.println("original ----------------------------------------"); System.out.println(Base64.encodeBase64String(expected)); final byte[] encoded = PercentEncoder.encodeMultiple(expected); System.out.println("encoded -----------------------------------------"); System.out.println(new String(encoded, "US-ASCII")); final byte[] actual = decoder.decode(encoded); System.out.println("decoded -----------------------------------------"); System.out.println(Base64.encodeBase64String(actual)); Assert.assertEquals(actual, expected); }