當前位置: 首頁>>代碼示例>>Java>>正文


Java RandomGenerator.nextFloat方法代碼示例

本文整理匯總了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;
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:26,代碼來源:Polygon.java

示例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--;
		}
	}
}
 
開發者ID:axbaretto,項目名稱:flink,代碼行數:64,代碼來源:RMatGraph.java


注:本文中的org.apache.commons.math3.random.RandomGenerator.nextFloat方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。