本文整理汇总了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);
}
}
}
示例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);
}
示例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);
}
示例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);
}
示例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++;
}
}
示例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++;
}
}