Random r = new Random(); double randomValue = rangeMin + (rangeMax - rangeMin) * r.nextDouble();
double start = 400; double end = 402; double random = new Random().nextDouble(); double result = start + (random * (end - start)); System.out.println(result);
/** * To provide random values to populate a position. * */ protected Properties getProps() { Properties props = new Properties(); double qty = rng.nextInt(MAX_QTY) * 100.00; double mktValue = rng.nextDouble() * MAX_PRICE; props.setProperty("qty", String.valueOf(qty)); props.setProperty("mktValue", String.valueOf(mktValue)); return props; }
@Test public void testIllegalNumber() { Random rand = new Random(System.currentTimeMillis()); ArrayList<Double> doubleList = new ArrayList<>(); int count = 10; for (int i = 0; i < count; i++) { doubleList.add(rand.nextDouble()); } doubleList.add(0.0); doubleList.add(0.0); //test duplicate doubleList.add(-1.0); //test negative number doubleList.add(Double.MAX_VALUE); doubleList.add(-Double.MAX_VALUE); //System.out.println(Double.MIN_VALUE); System.out.println("test numbers:" + doubleList); ArrayList<String> strNumList = listToStringList(doubleList); strNumList.add("fjaeif"); //illegal type //System.out.println("test num strs list:"+strNumList); try { ArrayList<SelfDefineSortableKey> keyList = createKeyList(strNumList, (byte) SelfDefineSortableKey.TypeFlag.DOUBLE_FAMILY_TYPE.ordinal()); Collections.sort(keyList); fail("Need catch exception"); }catch(Exception e){ //correct } }
private List<Double> createDoubleValuesNoNull() { List<Double> values = new ArrayList<>(); for (int i = 0; i < ROWS; ++i) { values.add(Double.valueOf(random.nextDouble())); } return values; } }
protected double genDouble(List<Double> addTo) { double val = rand.nextDouble() * rand.nextInt(100); addTo.add(val); return val; }
public static Dataset getDataset() { int datapoints = 100; List<Double> labels = new ArrayList<>(); List<FeatureVector> features = new ArrayList<>(); Random rand = new Random(0); for (int i = 0; i < datapoints; i++) { double label = rand.nextDouble() < 0.5 ? 0 : 1; labels.add(label); features.add(new FeatureVector(0, label + rand.nextGaussian())); } return new Dataset(labels, features, ImmutableMap.of(0, "first", 1, "second")); } }
private void delay() { final Random random = ThreadLocalRandom.current(); double p = random.nextDouble(); int mod; if (p < 0.9) { System.out.println("OUCH"); final long baseDelayNs = MICROSECONDS.toNanos(delays[mod]); final int delayRangeNs = (int) (MICROSECONDS.toNanos(delays[mod + 1]) - baseDelayNs); final long delayNs = baseDelayNs + random.nextInt(delayRangeNs); final long deadline = System.nanoTime() + delayNs; do {
@Test public void nextInt() { Random random = mock(Random.class); NearbyRandom nearbyRandom = new ParabolicDistributionNearbyRandom(100); when(random.nextDouble()).thenReturn(0.0); assertEquals(0, nearbyRandom.nextInt(random, 500)); when(random.nextDouble()).thenReturn(1.0 - Math.pow(1 - 1.0 / 100.0, 3.0)); assertEquals(1, nearbyRandom.nextInt(random, 500)); when(random.nextDouble()).thenReturn(1.0 - Math.pow(1 - 2.0 / 100.0, 3.0)); assertEquals(2, nearbyRandom.nextInt(random, 500)); }
Random r = new Random(10); int numFeatures = 5; int featureLength = 30; for (int j = 0; j < numFeatures; j++) { if (r.nextBoolean()) { humanFeatureVectors[i].setSparseComponent(j, r.nextInt(featureLength), r.nextDouble()); } else { double[] dense = new double[featureLength]; for (int k = 0; k < dense.length; k++) { dense[k] = r.nextDouble(); for (int i = 0; i < numFeatures; i++) { double[] dense = new double[featureLength]; for (int j = 0; j < dense.length; j++) dense[j] = r.nextDouble(); weights.setDenseComponent(i, dense);
@Test public void getDouble() { double value = new Random().nextDouble(); verifySupportHeadAndOrTrailingWhitespaces(value, Configuration::getDouble); }
public A test() { Random random = new Random(); int a2 = random.nextInt(); int a3 = a2 + 3; return new A(this, a2, a3, 4, 5, random.nextDouble()) { @Override public void m() { System.out.println(1); } }; }
thisV[i] = generator.nextDouble(); thisX[i] = generator.nextDouble(); System.out.println("Condition Number of: " + maxSeen/minSeen); System.out.println("Is negative: " + isNeg); System.out.println("Is positive: " + isPos); System.out.println("Is semi: " + isSemi);
@Test public void testSimpleTypesObjects() { SimpleTypes a = new SimpleTypes(); SimpleTypes b = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes c = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes d = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes e = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes f = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); SimpleTypes g = new SimpleTypes(rnd.nextInt(), rnd.nextLong(), (byte) rnd.nextInt(), StringUtils.getRandomString(rnd, 10, 100), (short) rnd.nextInt(), rnd.nextDouble()); runTests(a, b, c, d, e, f, g); }
@Test public void testRandom() { Random rand = new Random(); int n = 1000; double[] nums = new double[n]; for (int i = 0; i < n; i++) { nums[i] = rand.nextDouble() * 1000000; } Arrays.parallelSort(nums); buf.clear(); dds.serialize(nums, buf); buf.flip(); double[] r = dds.deserialize(buf); assertArrayEquals(nums, r); System.out.println("doubles size of " + (n * 8) + " bytes serialized to " + buf.limit() + " bytes"); }
public void generateScanDots() { // Make sure stars don't jump around between updates. // final Random lRandom = new Random(ACearth.getStartTime()); final int lStarsMax = (int)(fImageWidth * fImageHeight * fStarFrequency); for(int i = 0; i < lStarsMax; i++) { // "-1" to leave space for big stars. int x = (int)(lRandom.nextDouble() * (fImageWidth - 1)); int y = (int)(lRandom.nextDouble() * fImageHeight); fDots.add(new ScanDot(ScanDot.DotTypeStar, x, y)); // A big star is just two pixels wide. if((fBigStars != 0) && (Math.random() * 100 < fBigStars)) { fDots.add(new ScanDot(ScanDot.DotTypeStar, x + 1, y)); } } } }
int index, count = 0; index = random.nextInt(siz); // initial center docs.add(documents_.get(index)); ++count; double potential = 0.0; double randval = random.nextDouble() * potential; docs.add(documents_.get(index)); ++count;
int numGroups = 50000; int itemCount = 30; Random random = new Random(); GroupedAccumulator groupedAccumulator = createGroupedAccumulator(aggregationFunction); String str = String.valueOf(i % 10); String item = IntStream.range(0, itemCount).mapToObj(x -> str).collect(Collectors.joining()); boolean distinctValue = random.nextDouble() < distinctFraction; if (distinctValue) { valueList.add(item); valueList.add(item);
public static void main(String[] args) { TrendLine t = new PolyTrendLine(2); Random rand = new Random(); double[] x = new double[1000*1000]; double[] err = new double[x.length]; double[] y = new double[x.length]; for (int i=0; i<x.length; i++) { x[i] = 1000*rand.nextDouble(); } for (int i=0; i<x.length; i++) { err[i] = 100*rand.nextGaussian(); } for (int i=0; i<x.length; i++) { y[i] = x[i]*x[i]+err[i]; } // quadratic model t.setValues(y,x); System.out.println(t.predict(12)); // when x=12, y should be... , eg 143.61380202745192 }
public static int getRandomCodePoint() { int codePoint; if (rnd.nextDouble() < 0.50) { codePoint = 32 + rnd.nextInt(90); } else { codePoint = getRandomSupplementaryChar(); } if (!Character.isValidCodePoint(codePoint)) { System.out.println(Integer.toHexString(codePoint) + " is not a valid code point"); } return codePoint; }