List of usage examples for java.util.concurrent ThreadLocalRandom nextDouble
public double nextDouble()
From source file:com.test.zmisc.App.java
public static void main(String[] args) { double[] a = new double[32768]; double[] b = new double[32768]; ThreadLocalRandom rand = ThreadLocalRandom.current(); for (int i = 0; i < a.length; i++) { a[i] = rand.nextDouble(); b[i] = a[i];// w w w .ja v a 2 s . c om } long ts = System.currentTimeMillis(); PearsonsCorrelation corr = new PearsonsCorrelation(); corr.correlation(a, b); ts = System.currentTimeMillis() - ts; System.out.println("Time elapsed:" + ts + "ms"); // standard deviation is the sqrt(mean((X-avg)^2)) ts = System.currentTimeMillis(); double amean = average(a); double aStdDev = standardDeviation(a, amean); StandardDeviation sd = new StandardDeviation(); sd.setBiasCorrected(false); double bmean = average(b); double bStdDev = standardDeviation(b, bmean); double cor = (covariance(a, aStdDev, b, bmean)) / (aStdDev * bStdDev); ts = System.currentTimeMillis() - ts; System.out.println("Time elapsed:" + ts + "ms"); }
From source file:com.linkedin.pinot.integration.tests.UploadRefreshDeleteIntegrationTest.java
@Test(enabled = false) public void testUploadRefreshDelete() throws Exception { final int THREAD_COUNT = 1; final int SEGMENT_COUNT = 5; final int MIN_ROWS_PER_SEGMENT = 500; final int MAX_ROWS_PER_SEGMENT = 1000; final int OPERATIONS_PER_ITERATION = 10; final int ITERATION_COUNT = 5; final double UPLOAD_PROBABILITY = 0.8d; final String[] segmentNames = new String[SEGMENT_COUNT]; final int[] segmentRowCounts = new int[SEGMENT_COUNT]; for (int i = 0; i < SEGMENT_COUNT; i++) { segmentNames[i] = "segment_" + i; segmentRowCounts[i] = 0;/* w ww .j a v a2 s. c o m*/ } for (int i = 0; i < ITERATION_COUNT; i++) { // Create THREAD_COUNT threads ExecutorService executorService = Executors.newFixedThreadPool(THREAD_COUNT); // Submit OPERATIONS_PER_ITERATION uploads/deletes for (int j = 0; j < OPERATIONS_PER_ITERATION; j++) { executorService.submit(new Runnable() { @Override public void run() { try { ThreadLocalRandom random = ThreadLocalRandom.current(); // Pick a random segment int segmentIndex = random.nextInt(SEGMENT_COUNT); String segmentName = segmentNames[segmentIndex]; // Pick a random operation if (random.nextDouble() < UPLOAD_PROBABILITY) { // Upload this segment LOGGER.info("Will upload segment {}", segmentName); synchronized (segmentName) { // Create a segment with a random number of rows int segmentRowCount = random.nextInt(MIN_ROWS_PER_SEGMENT, MAX_ROWS_PER_SEGMENT); LOGGER.info("Generating and uploading segment {} with {} rows", segmentName, segmentRowCount); generateAndUploadRandomSegment(segmentName, segmentRowCount); // Store the number of rows LOGGER.info("Uploaded segment {} with {} rows", segmentName, segmentRowCount); segmentRowCounts[segmentIndex] = segmentRowCount; } } else { // Delete this segment LOGGER.info("Will delete segment {}", segmentName); synchronized (segmentName) { // Delete this segment LOGGER.info("Deleting segment {}", segmentName); String reply = sendDeleteRequest( ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL) .forSegmentDelete("myresource", segmentName)); LOGGER.info("Deletion returned {}", reply); // Set the number of rows to zero LOGGER.info("Deleted segment {}", segmentName); segmentRowCounts[segmentIndex] = 0; } } } catch (Exception e) { throw new RuntimeException(e); } } }); } // Await for all tasks to complete executorService.shutdown(); executorService.awaitTermination(5L, TimeUnit.MINUTES); // Count number of expected rows int expectedRowCount = 0; for (int segmentRowCount : segmentRowCounts) { expectedRowCount += segmentRowCount; } // Wait for up to one minute for the row count to match the expected row count LOGGER.info("Awaiting for the row count to match {}", expectedRowCount); int pinotRowCount = (int) getCurrentServingNumDocs(); long timeInOneMinute = System.currentTimeMillis() + 60 * 1000L; while (System.currentTimeMillis() < timeInOneMinute && pinotRowCount != expectedRowCount) { LOGGER.info("Row count is {}, expected {}, awaiting for row count to match", pinotRowCount, expectedRowCount); Thread.sleep(5000L); try { pinotRowCount = (int) getCurrentServingNumDocs(); } catch (Exception e) { LOGGER.warn("Caught exception while sending query to Pinot, retrying", e); } } // Compare row counts Assert.assertEquals(pinotRowCount, expectedRowCount, "Expected and actual row counts don't match after waiting one minute"); } }
From source file:ffx.algorithms.mc.RosenbluthChiAllMove.java
/** * Yields a random vector on the surface of the unit sphere. * Algorithm 42 from Frenkel/Smit./*from w w w. j av a2 s .c o m*/ */ private double[] vectorOnASphere() { ThreadLocalRandom rand = ThreadLocalRandom.current(); double ranA, ranB, ranC, ransq; do { ranA = 1 - 2 * rand.nextDouble(); ranB = 1 - 2 * rand.nextDouble(); ransq = ranA * ranA + ranB * ranB; } while (ransq >= 1); ranC = 2 * FastMath.sqrt(1 - ransq); double vec[] = new double[3]; vec[0] = ranA * ranC; // x vec[1] = ranB * ranC; // y vec[2] = 1 - 2 * ransq; // z return vec; }
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())); }/* w w w .ja v a2s . com*/ return data; }