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