当前位置: 首页>>代码示例>>Java>>正文


Java SplittableRandom.nextDouble方法代码示例

本文整理汇总了Java中java.util.SplittableRandom.nextDouble方法的典型用法代码示例。如果您正苦于以下问题:Java SplittableRandom.nextDouble方法的具体用法?Java SplittableRandom.nextDouble怎么用?Java SplittableRandom.nextDouble使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.SplittableRandom的用法示例。


在下文中一共展示了SplittableRandom.nextDouble方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testNextDoubleBounded2

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextDouble(least, bound) returns least <= value < bound;
 * repeated calls produce at least two distinct results
 */
public void testNextDoubleBounded2() {
    SplittableRandom sr = new SplittableRandom();
    for (double least = 0.0001; least < 1.0e20; least *= 8) {
        for (double bound = least * 1.001; bound < 1.0e20; bound *= 16) {
            double f = sr.nextDouble(least, bound);
            assertTrue(least <= f && f < bound);
            int i = 0;
            double j;
            while (i < NCALLS &&
                   (j = sr.nextDouble(least, bound)) == f) {
                assertTrue(least <= j && j < bound);
                ++i;
            }
            assertTrue(i < NCALLS);
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:SplittableRandomTest.java

示例2: testNextDouble

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * Repeated calls to nextDouble produce at least two distinct results
 */
public void testNextDouble() {
    SplittableRandom sr = new SplittableRandom();
    double f = sr.nextDouble();
    int i = 0;
    while (i < NCALLS && sr.nextDouble() == f)
        ++i;
    assertTrue(i < NCALLS);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:12,代码来源:SplittableRandomTest.java

示例3: testNextDoubleBoundNonPositive

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextDouble(non-positive) throws IllegalArgumentException
 */
public void testNextDoubleBoundNonPositive() {
    SplittableRandom sr = new SplittableRandom();
    Runnable[] throwingActions = {
        () -> sr.nextDouble(-17.0d),
        () -> sr.nextDouble(0.0d),
        () -> sr.nextDouble(-Double.MIN_VALUE),
        () -> sr.nextDouble(Double.NEGATIVE_INFINITY),
        () -> sr.nextDouble(Double.NaN),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:SplittableRandomTest.java

示例4: testNextDoubleBadBounds

import java.util.SplittableRandom; //导入方法依赖的package包/类
/**
 * nextDouble(! (least < bound)) throws IllegalArgumentException
 */
public void testNextDoubleBadBounds() {
    SplittableRandom sr = new SplittableRandom();
    Runnable[] throwingActions = {
        () -> sr.nextDouble(17.0d, 2.0d),
        () -> sr.nextDouble(-42.0d, -42.0d),
        () -> sr.nextDouble(Double.MAX_VALUE, Double.MIN_VALUE),
        () -> sr.nextDouble(Double.NaN, 0.0d),
        () -> sr.nextDouble(0.0d, Double.NaN),
    };
    assertThrows(IllegalArgumentException.class, throwingActions);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:SplittableRandomTest.java

示例5: spawnParticle

import java.util.SplittableRandom; //导入方法依赖的package包/类
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
		double offsetY, double offsetZ, double extra, T data) {
	int id = 0;

	id = PokkitParticle.toNukkit(particle);

	SplittableRandom random = new SplittableRandom();

	int index = 0;
	while (count > index) {
		double realOffsetX = 0;
		double realOffsetY = 0;
		double realOffsetZ = 0;
		if (offsetX != 0) {
			realOffsetX = offsetX / 2;
			x = x + random.nextDouble(-realOffsetX, realOffsetX);
		}
		if (offsetX != 0) {
			realOffsetY = offsetY / 2;
			y = y + random.nextDouble(-realOffsetY, realOffsetY);
		}
		if (offsetX != 0) {
			realOffsetZ = offsetZ / 2;
			z = z + random.nextDouble(-realOffsetZ, realOffsetZ);
		}

		GenericParticle nukkitParticle = new GenericParticle(new Vector3(x, y, z), id);

		nukkit.addParticle(nukkitParticle);
		index++;
	}
}
 
开发者ID:rutgerkok,项目名称:Pokkit,代码行数:34,代码来源:PokkitWorld.java

示例6: spawnParticle

import java.util.SplittableRandom; //导入方法依赖的package包/类
@Override
public <T> void spawnParticle(Particle particle, double x, double y, double z, int count, double offsetX,
		double offsetY, double offsetZ, double extra, T data) {
	int id = 0;

	id = PokkitParticle.toNukkit(particle);

	SplittableRandom random = new SplittableRandom();

	int index = 0;
	while (count > index) {
		double realOffsetX = 0;
		double realOffsetY = 0;
		double realOffsetZ = 0;
		if (offsetX != 0) {
			realOffsetX = offsetX / 2;
			x = x + random.nextDouble(-realOffsetX, realOffsetX);
		}
		if (offsetX != 0) {
			realOffsetY = offsetY / 2;
			y = y + random.nextDouble(-realOffsetY, realOffsetY);
		}
		if (offsetX != 0) {
			realOffsetZ = offsetZ / 2;
			z = z + random.nextDouble(-realOffsetZ, realOffsetZ);
		}

		GenericParticle nukkitParticle = new GenericParticle(new Vector3(x, y, z), id);

		nukkit.getLevel().addParticle(nukkitParticle, nukkit);
		index++;
	}
}
 
开发者ID:rutgerkok,项目名称:Pokkit,代码行数:34,代码来源:PokkitPlayer.java


注:本文中的java.util.SplittableRandom.nextDouble方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。