java.util.Random.doubles()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(6.0k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中java.util.Random.doubles()方法的一些代码示例,展示了Random.doubles()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Random.doubles()方法的具体详情如下:
包路径:java.util.Random
类名称:Random
方法名:doubles

Random.doubles介绍

暂无

代码示例

代码示例来源:origin: neo4j/neo4j

public DoubleStream doubles( int dimension, double minValue, double maxValue )
{
  return random.doubles( dimension, minValue, maxValue );
}

代码示例来源:origin: stackoverflow.com

double[] array = new Random().doubles()
              .distinct()
              .limit(500) // How many you want.
              .toArray();

代码示例来源:origin: HubSpot/Singularity

Iterator<Double> cpuIterator = r.doubles(1, 5).iterator();
Iterator<Double> memoryIterator = r.doubles(15, 20000).iterator();
Iterator<Double> diskIterator = r.doubles(30, 50000).iterator();

代码示例来源:origin: geotools/geotools

new ReferencedEnvelope(-20, 20, -30, 30, DefaultGeographicCRS.WGS84);
PrimitiveIterator.OfDouble rand =
    new Random().doubles(bounds.getMinX(), bounds.getMaxX()).iterator();
SimpleFeatureBuilder fb = new SimpleFeatureBuilder(type);
for (int i = 0; i < featureNumber; i++) {

代码示例来源:origin: jenetics/jenetics

public static SubsetSum of(final int n, final int k, final Random random) {
  return new SubsetSum(
    random.doubles()
      .limit(n)
      .mapToObj(d -> (int)((d - 0.5)*n))
      .collect(ISeq.toISeq()),
    k
  );
}

代码示例来源:origin: jenetics/jenetics

@Test
public void comparator() {
  final double[] d1 = new Random().doubles(10).toArray();
  final double[] d2 = new Random().doubles(10).toArray();
  final Vec<double[]> v1 = Vec.of(d1);
  final Vec<double[]> v2 = Vec.of(d2);
  for (int i = 0; i < d1.length; ++i) {
    Assert.assertEquals(Double.compare(d1[i], d2[i]), v1.compare(v2, i));
  }
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Vec<double[]>> circle(final int count, final Random random) {
  return random.doubles(count)
    .mapToObj(r -> {
      final double a = random.nextDouble()*2*PI;
      return Vec.of(r*sin(a), r*cos(a));
    })
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

@Test(dataProvider = "sorters")
public void sortAscSortedValues(final IndexSorter sorter, final Integer size) {
  final double[] values = new Random().doubles(size).toArray();
  Arrays.sort(values);
  final double[] actual = indexSort(sorter, values);
  final double[] expected = arraySort(values);
  Assert.assertEquals(actual, expected);
}

代码示例来源:origin: jenetics/jenetics

@Test(dataProvider = "sorters")
public void sortRandomValues(final IndexSorter sorter, final Integer size) {
  final double[] values = new Random().doubles(size).toArray();
  final double[] actual = indexSort(sorter, values);
  final double[] expected = arraySort(values);
  Assert.assertEquals(actual, expected);
}

代码示例来源:origin: jenetics/jenetics

@Test
public void distance() {
  final double[] d1 = new Random().doubles(10).toArray();
  final double[] d2 = new Random().doubles(10).toArray();
  final Vec<double[]> v1 = Vec.of(d1);
  final Vec<double[]> v2 = Vec.of(d2);
  for (int i = 0; i < d1.length; ++i) {
    Assert.assertEquals(d1[i] - d2[i], v1.distance(v2, i));
  }
}

代码示例来源:origin: jenetics/jenetics

@Test
public void dominance() {
  final double[] d1 = new Random().doubles(10).toArray();
  final double[] d2 = new Random().doubles(10).toArray();
  final Vec<double[]> v1 = Vec.of(d1);
  final Vec<double[]> v2 = Vec.of(d2);
  Assert.assertEquals(v1.dominance(v2), Pareto.dominance(d1, d2));
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Point2> front(final int count, final Random random) {
  return random.doubles(count)
    .mapToObj(x -> Point2.of(x, sqrt(1 - x*x)))
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

@Test(dataProvider = "sorters")
public void sortDescSortedValues(final IndexSorter sorter, final Integer size) {
  final double[] values = new Random().doubles(size).toArray();
  Arrays.sort(values);
  revert(values);
  final double[] actual = indexSort(sorter, values);
  final double[] expected = arraySort(values);
  Assert.assertEquals(actual, expected);
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Vec<double[]>> frontMax(
  final double r,
  final int count,
  final Random random
) {
  return random.doubles(count)
    .map(a -> a*PI*0.5)
    .mapToObj(a -> Vec.of(r*sin(a), r*cos(a)))
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Vec<double[]>> frontMin(
  final double r,
  final int count,
  final Random random
) {
  return random.doubles(count)
    .map(a -> a*PI*0.5 + PI)
    .mapToObj(a -> Vec.of(r*sin(a), r*cos(a)))
    .collect(ISeq.toISeq());
}

代码示例来源:origin: jenetics/jenetics

@Test
public void acceptReverseMinMax() {
  final Random random = RandomRegistry.getRandom();
  final double[] numbers = random.doubles().limit(1000).toArray();
  final MinMax<Double> minMax = MinMax.of((a, b) -> b.compareTo(a));
  Arrays.stream(numbers)
    .mapToObj(Double::valueOf)
    .forEach(minMax);
  Assert.assertEquals(minMax.getMin(), StatUtils.max(numbers));
  Assert.assertEquals(minMax.getMax(), StatUtils.min(numbers));
}

代码示例来源:origin: jenetics/jenetics

@Test
public void toMinMaxReverse() {
  final Random random = RandomRegistry.getRandom();
  final double[] numbers = random.doubles().limit(1000).toArray();
  final MinMax<Double> minMax = Arrays.stream(numbers)
    .mapToObj(Double::valueOf)
    .collect(MinMax.toMinMax((a, b) -> b.compareTo(a)));
  Assert.assertEquals(minMax.getMin(), StatUtils.max(numbers));
  Assert.assertEquals(minMax.getMax(), StatUtils.min(numbers));
}

代码示例来源:origin: jenetics/jenetics

static ISeq<Point2> circle(final int count, final Random random) {
    return random.doubles()
      .mapToObj(x -> Point2.of(x, random.nextDouble()))
      .filter(p -> p.x()*p.x() + p.y()*p.y() < 0.9)
      .limit(count)
      .collect(ISeq.toISeq());
  }
}

代码示例来源:origin: jenetics/jenetics

@Test
public void acceptNormalMinMax() {
  final Random random = RandomRegistry.getRandom();
  final double[] numbers = random.doubles().limit(1000).toArray();
  final MinMax<Double> minMax = MinMax.of();
  Arrays.stream(numbers)
    .mapToObj(Double::valueOf)
    .forEach(minMax);
  Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers));
  Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers));
}

代码示例来源:origin: jenetics/jenetics

@Test
public void toMinMaxNormal() {
  final Random random = RandomRegistry.getRandom();
  final double[] numbers = random.doubles().limit(1000).toArray();
  final MinMax<Double> minMax = Arrays.stream(numbers)
    .mapToObj(Double::valueOf)
    .collect(MinMax.toMinMax());
  Assert.assertEquals(minMax.getMin(), StatUtils.min(numbers));
  Assert.assertEquals(minMax.getMax(), StatUtils.max(numbers));
}

相关文章