本文整理汇总了Java中org.apache.commons.math3.random.RandomGenerator.nextFloat方法的典型用法代码示例。如果您正苦于以下问题:Java RandomGenerator.nextFloat方法的具体用法?Java RandomGenerator.nextFloat怎么用?Java RandomGenerator.nextFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.math3.random.RandomGenerator
的用法示例。
在下文中一共展示了RandomGenerator.nextFloat方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: randomPolygon
import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
/**
* Creates a new random Polygon of the given length.
*/
public static Polygon randomPolygon(int length) {
final int polygonSize = 4 + 2 * length;
final RandomGenerator random = GeneticAlgorithm.getRandomGenerator();
Polygon p = new Polygon();
p.data = new float[polygonSize];
p.data[0] = random.nextFloat(); // r
p.data[1] = random.nextFloat(); // g
p.data[2] = random.nextFloat(); // b
p.data[3] = FastMath.max(0.2f, random.nextFloat() * random.nextFloat()); // a
float px = random.nextFloat();
float py = random.nextFloat();
for (int k = 0; k < length; k++) {
p.data[4 + 2*k] = px + (random.nextFloat() - 0.5f);
p.data[5 + 2*k] = py + (random.nextFloat() - 0.5f);
}
return p;
}
示例2: flatMap
import org.apache.commons.math3.random.RandomGenerator; //导入方法依赖的package包/类
@Override
public void flatMap(BlockInfo<T> blockInfo, Collector<Edge<LongValue, NullValue>> out)
throws Exception {
RandomGenerator rng = blockInfo.getRandomGenerable().generator();
long edgesToGenerate = blockInfo.getElementCount();
while (edgesToGenerate > 0) {
long x = 0;
long y = 0;
// matrix constants are reset for each edge
float a = this.a;
float b = this.b;
float c = this.c;
float d = this.d;
for (int bit = 0; bit < scale; bit++) {
// generated next bit for source and target
x <<= 1;
y <<= 1;
float random = rng.nextFloat();
if (random <= a) {
} else if (random <= a + b) {
y += 1;
} else if (random <= a + b + c) {
x += 1;
} else {
x += 1;
y += 1;
}
if (noiseEnabled) {
// noise is bounded such that all parameters remain non-negative
a *= 1.0 - noise / 2 + rng.nextFloat() * noise;
b *= 1.0 - noise / 2 + rng.nextFloat() * noise;
c *= 1.0 - noise / 2 + rng.nextFloat() * noise;
d *= 1.0 - noise / 2 + rng.nextFloat() * noise;
// normalize back to a + b + c + d = 1.0
float norm = 1.0f / (a + b + c + d);
a *= norm;
b *= norm;
c *= norm;
// could multiply by norm, but subtract to minimize rounding error
d = 1.0f - a - b - c;
}
}
// if vertexCount is not a power-of-2 then discard edges outside the vertex range
if (x < vertexCount && y < vertexCount) {
source.setValue(x);
target.setValue(y);
out.collect(sourceToTarget);
edgesToGenerate--;
}
}
}