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


Java RandomGenerator.nextLong方法代碼示例

本文整理匯總了Java中org.apache.commons.math3.random.RandomGenerator.nextLong方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomGenerator.nextLong方法的具體用法?Java RandomGenerator.nextLong怎麽用?Java RandomGenerator.nextLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.math3.random.RandomGenerator的用法示例。


在下文中一共展示了RandomGenerator.nextLong方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: random

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
/**
 * Create a random bit string of given {@code length}.
 *
 * @param length the length of the bit string
 * @param rng    the random number generator to use
 * @return a new bit string of given length.
 */
public static BitString random(final int length, final RandomGenerator rng) {
    checkNotNull(rng);
    checkArgument(length >= 0);

    if (length == 0) {
        return emptyBitSequence();
    }

    long[] longs = new long[(length + 63) / 64];
    for (int i = 0; i < longs.length; i++) {
        longs[i] = rng.nextLong();
    }
    longs[longs.length - 1] &= (~0L >>> (longs.length * 64 - length));
    return new BitSetString(BitSet.valueOf(longs), length);
}
 
開發者ID:asoem,項目名稱:greyfish,代碼行數:23,代碼來源:BitString.java

示例2: testFloorDivModLong

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
@Test
public void testFloorDivModLong() {
    RandomGenerator generator = new Well1024a(0xb87b9bc14c96ccd5l);
    for (int i = 0; i < 10000; ++i) {
        long a = generator.nextLong();
        long b = generator.nextLong();
        if (b == 0) {
            try {
                FastMath.floorDiv(a, b);
                Assert.fail("an exception should have been thrown");
            } catch (MathArithmeticException mae) {
                // expected
            }
        } else {
            long d = FastMath.floorDiv(a, b);
            long m = FastMath.floorMod(a, b);
            Assert.assertEquals(poorManFloorDiv(a, b), d);
            Assert.assertEquals(poorManFloorMod(a, b), m);
            Assert.assertEquals(a, d * b + m);
            if (b < 0) {
                Assert.assertTrue(m <= 0);
                Assert.assertTrue(-m < -b);
            } else {
                Assert.assertTrue(m >= 0);
                Assert.assertTrue(m < b);
            }
        }
    }
}
 
開發者ID:Quanticol,項目名稱:CARMA,代碼行數:30,代碼來源:FastMathTest.java

示例3: main

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
public static void main(final String[] arg) throws JSAPException {

		final SimpleJSAP jsap = new SimpleJSAP(SelectSpeedTest.class.getName(), "Tests the speed of rank/select implementations.",
				new Parameter[] {
					new UnflaggedOption("numBits", JSAP.LONGSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The number of bits."),
					new UnflaggedOption("density", JSAP.DOUBLE_PARSER, ".5", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The density."),
					new FlaggedOption("numPos", JSAP.INTSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, 'p', "positions", "The number of positions to test"),
					//new FlaggedOption("encoding", ForNameStringParser.getParser(Charset.class), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding."),
					//new Switch("zipped", 'z', "zipped", "The term list is compressed in gzip format."),
					//new FlaggedOption("termFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "offline", "Read terms from this file (without loading them into core memory) instead of standard input."),
					//new UnflaggedOption("trie", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised hollow trie.")
		});

		final JSAPResult jsapResult = jsap.parse(arg);
		if (jsap.messagePrinted()) return;

		final long numBits = jsapResult.getLong("numBits");
		final double density = jsapResult.getDouble("density");
		final int numPos = jsapResult.getInt("numPos");

		final RandomGenerator random = new XoRoShiRo128PlusRandomGenerator(42);
		final LongArrayBitVector bitVector = LongArrayBitVector.getInstance().length(numBits);
		long c = 0;
		for(long i = numBits; i-- != 0;)
			if (random.nextDouble() < density) {
				bitVector.set(i);
				c++;
			}

		final long[] rankPosition = new long[numPos];
		final long[] selectPosition = new long[numPos];

		for(int i = numPos; i-- != 0;) {
			rankPosition[i] = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % numBits;
			selectPosition[i] = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % c;
		}

		long time;
		final SimpleSelect simpleSelect = new SimpleSelect(bitVector);
		for(int k = 1000; k-- != 0;) {

			System.out.println("=== Simple ===");
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) simpleSelect.select(selectPosition[i]);
			time += System.currentTimeMillis();
			System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/select");

/*			System.out.println("=== Sparse ===");
			SparseSelect sparseSelect = new SparseSelect(bitVector);
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) sparseSelect.select(selectPosition[i]);
			time += System.currentTimeMillis();
	 		System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/select");*/
		}
	}
 
開發者ID:vigna,項目名稱:Sux4J,代碼行數:56,代碼來源:SelectSpeedTest.java

示例4: main

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
public static void main(final String[] arg) throws JSAPException {

		final SimpleJSAP jsap = new SimpleJSAP(RankSpeedTest.class.getName(), "Tests the speed of rank/select implementations.",
				new Parameter[] {
					new UnflaggedOption("numBits", JSAP.LONGSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The number of bits."),
					new UnflaggedOption("density", JSAP.DOUBLE_PARSER, ".5", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The density."),
					new FlaggedOption("numPos", JSAP.INTSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, 'p', "positions", "The number of positions to test"),
					//new FlaggedOption("encoding", ForNameStringParser.getParser(Charset.class), "UTF-8", JSAP.NOT_REQUIRED, 'e', "encoding", "The term file encoding."),
					//new Switch("zipped", 'z', "zipped", "The term list is compressed in gzip format."),
					//new FlaggedOption("termFile", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.NOT_REQUIRED, 'o', "offline", "Read terms from this file (without loading them into core memory) instead of standard input."),
					//new UnflaggedOption("trie", JSAP.STRING_PARSER, JSAP.NO_DEFAULT, JSAP.REQUIRED, JSAP.NOT_GREEDY, "The filename for the serialised hollow trie.")
		});

		final JSAPResult jsapResult = jsap.parse(arg);
		if (jsap.messagePrinted()) return;

		final long numBits = jsapResult.getLong("numBits");
		final double density = jsapResult.getDouble("density");
		final int numPos = jsapResult.getInt("numPos");

		final RandomGenerator random = new XoRoShiRo128PlusRandomGenerator(42);
		final LongArrayBitVector bitVector = LongArrayBitVector.getInstance().length(numBits);
		for(long i = numBits; i-- != 0;) if (random.nextDouble() < density) bitVector.set(i);

		final long[] rankPosition = new long[numPos];

		for(int i = numPos; i-- != 0;) rankPosition[i] = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % numBits;

		long time;
		for(int k = 10; k-- != 0;) {
			System.out.println("=== Rank 9 ===");
			final Rank9 rank9 = new Rank9(bitVector);
			time = - System.nanoTime();
			for(int i = 0; i < numPos; i++) rank9.rank(rankPosition[i]);
			time += System.nanoTime();
			System.err.println(time / 1E9 + "s, " + time / (double)numPos + " ns/rank (" + 100.0 * rank9.numBits() / numBits + "%)");

			System.out.println("=== Rank 9b ===");
			final Rank9GogPetri rank9b = new Rank9GogPetri(bitVector);
			time = - System.nanoTime();
			for(int i = 0; i < numPos; i++) rank9b.rank(rankPosition[i]);
			time += System.nanoTime();
			System.err.println(time / 1E9 + "s, " + time / (double)numPos + " ns/rank (" + 100.0 * rank9b.numBits() / numBits + "%)");

			System.out.println("=== Rank 16 ===");
			final Rank16 rank16 = new Rank16(bitVector);
			time = - System.nanoTime();
			for(int i = 0; i < numPos; i++) rank16.rank(rankPosition[i]);
			time += System.nanoTime();
			System.err.println(time / 1E9 + "s, " + time / (double)numPos + " ns/rank (" + 100.0 * rank16.numBits() / numBits + "%)");

			System.out.println("=== Rank 11 ===");
			final Rank11Original rank11 = new Rank11Original(bitVector);
			time = - System.nanoTime();
			for(int i = 0; i < numPos; i++) rank11.rank(rankPosition[i]);
			time += System.nanoTime();
			System.err.println(time / 1E9 + "s, " + time / (double)numPos + " ns/rank (" + 100.0 * rank11.numBits() / numBits + "%)");

			System.out.println("=== Rank 11b ===");
			final Rank11 rank11b = new Rank11(bitVector);
			time = - System.nanoTime();
			for(int i = 0; i < numPos; i++) rank11b.rank(rankPosition[i]);
			time += System.nanoTime();
			System.err.println(time / 1E9 + "s, " + time / (double)numPos + " ns/rank (" + 100.0 * rank11b.numBits() / numBits + "%)");

			System.out.println("=== Rank 12 ===");
			final Rank12 rank12 = new Rank12(bitVector);
			time = - System.nanoTime();
			for(int i = 0; i < numPos; i++) rank12.rank(rankPosition[i]);
			time += System.nanoTime();
			System.err.println(time / 1E9 + "s, " + time / (double)numPos + " ns/rank (" + 100.0 * rank12.numBits() / numBits + "%)");
		}
	}
 
開發者ID:vigna,項目名稱:Sux4J,代碼行數:74,代碼來源:RankSpeedTest.java

示例5: main

import org.apache.commons.math3.random.RandomGenerator; //導入方法依賴的package包/類
public static void main(final String[] arg) throws JSAPException {

		final SimpleJSAP jsap = new SimpleJSAP(RankSelectSpeedTest.class.getName(), "Tests the speed of rank/select implementations.",
				new Parameter[] {
					new UnflaggedOption("numBits", JSAP.LONGSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The number of bits."),
					new UnflaggedOption("density", JSAP.DOUBLE_PARSER, ".5", JSAP.NOT_REQUIRED, JSAP.NOT_GREEDY, "The density."),
					new FlaggedOption("numPos", JSAP.INTSIZE_PARSER, "1Mi", JSAP.NOT_REQUIRED, 'p', "positions", "The number of positions to test"),
		});

		final JSAPResult jsapResult = jsap.parse(arg);
		if (jsap.messagePrinted()) return;

		final long numBits = jsapResult.getLong("numBits");
		final double density = jsapResult.getDouble("density");
		final int numPos = jsapResult.getInt("numPos");

		final RandomGenerator random = new XoRoShiRo128PlusRandomGenerator(42);
		final LongArrayBitVector bitVector = LongArrayBitVector.getInstance().length(numBits);
		long c = 0;
		for(long i = numBits; i-- != 0;)
			if (random.nextDouble() < density) {
				bitVector.set(i);
				c++;
			}

		final long[] rankPosition = new long[numPos];
		final long[] selectPosition = new long[numPos];

		for(int i = numPos; i-- != 0;) {
			rankPosition[i] = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % numBits;
			selectPosition[i] = (random.nextLong() & 0x7FFFFFFFFFFFFFFFL) % c;
		}

		long time;
		for(int k = 10; k-- != 0;) {
			System.out.println("=== Rank 9 ===");
			final Rank9 rank9 = new Rank9(bitVector);
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) rank9.rank(rankPosition[i]);
			time += System.currentTimeMillis();
			System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/rank");

			System.out.println("=== Rank 16 ===");
			final Rank16 rank16 = new Rank16(bitVector);
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) rank16.rank(rankPosition[i]);
			time += System.currentTimeMillis();
			System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/rank");

			System.out.println("=== Hinted bsearch ===");
			final HintedBsearchSelect hintedBsearchSelect = new HintedBsearchSelect(rank9);
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) hintedBsearchSelect.select(selectPosition[i]);
			time += System.currentTimeMillis();
			System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/select");

			System.out.println("=== Select9 ===");
			final Select9 select9 = new Select9(rank9);
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) select9.select(selectPosition[i]);
			time += System.currentTimeMillis();
			System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/select");

			System.out.println("=== Simple ===");
			final SimpleSelect simpleSelect = new SimpleSelect(bitVector);
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) simpleSelect.select(selectPosition[i]);
			time += System.currentTimeMillis();
			System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/select");

			System.out.println("=== Sparse ===");
			final SparseSelect sparseSelect = new SparseSelect(bitVector);
			time = - System.currentTimeMillis();
			for(int i = 0; i < numPos; i++) sparseSelect.select(selectPosition[i]);
			time += System.currentTimeMillis();
			System.err.println(time / 1000.0 + "s, " + (time * 1E6) / numPos + " ns/select");
		}
	}
 
開發者ID:vigna,項目名稱:Sux4J,代碼行數:79,代碼來源:RankSelectSpeedTest.java


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