本文整理匯總了Java中java.util.Random.nextLong方法的典型用法代碼示例。如果您正苦於以下問題:Java Random.nextLong方法的具體用法?Java Random.nextLong怎麽用?Java Random.nextLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.Random
的用法示例。
在下文中一共展示了Random.nextLong方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeRandomCacheEntry
import java.util.Random; //導入方法依賴的package包/類
/**
* Makes a random cache entry.
* @param data Data to use, or null to use random data
* @param isExpired Whether the TTLs should be set such that this entry is expired
* @param needsRefresh Whether the TTLs should be set such that this entry needs refresh
*/
public static Cache.Entry makeRandomCacheEntry(
byte[] data, boolean isExpired, boolean needsRefresh) {
Random random = new Random();
Cache.Entry entry = new Cache.Entry();
if (data != null) {
entry.data = data;
} else {
entry.data = new byte[random.nextInt(1024)];
}
entry.etag = String.valueOf(random.nextLong());
entry.lastModified = random.nextLong();
entry.ttl = isExpired ? 0 : Long.MAX_VALUE;
entry.softTtl = needsRefresh ? 0 : Long.MAX_VALUE;
return entry;
}
示例2: test5
import java.util.Random; //導入方法依賴的package包/類
@Test
public static void test5() {
ProcessHandle self = ProcessHandle.current();
Random r = new Random();
for (int i = 0; i < 30; i++) {
Instant end = Instant.now().plusMillis(500L);
while (end.isBefore(Instant.now())) {
// burn the cpu time checking the time
long x = r.nextLong();
}
if (self.info().totalCpuDuration().isPresent()) {
Duration totalCpu = self.info().totalCpuDuration().get();
long infoTotalCputime = totalCpu.toNanos();
long beanCputime = ProcessUtil.MXBeanCpuTime().toNanos();
System.out.printf(" infoTotal: %12d, beanCpu: %12d, diff: %12d%n",
infoTotalCputime, beanCputime, beanCputime - infoTotalCputime);
} else {
break; // nothing to compare; continue
}
}
}
示例3: run
import java.util.Random; //導入方法依賴的package包/類
public VoltTable run(long id)
{
// Get a deterministic date and a non-deterministic date and
// verify they're within ten seconds of each other as a basic
// sanity check
long nonDeterDate = new Date().getTime();
long deterDate = getTransactionTime().getTime();
long diffInMS = nonDeterDate - deterDate;
if (diffInMS > 10000) {
String msg = "VoltProcedure time is to far from real time: " + String.valueOf(diffInMS) + " ms";
throw new VoltAbortException(msg);
}
// Get a deterministically-generated random number
Random rand = getSeededRandomNumberGenerator();
long randNo = rand.nextLong();
// Return the deterministic values.
// Replication should check to make sure they're the same
// from all replicas.
VoltTable retval = new VoltTable(
new ColumnInfo("date", VoltType.BIGINT),
new ColumnInfo("rand", VoltType.BIGINT));
retval.addRow(deterDate, randNo);
return retval;
}
示例4: sortSorted
import java.util.Random; //導入方法依賴的package包/類
public void sortSorted(IndexedSorter sorter) throws Exception {
final int SAMPLE = 500;
int[] values = new int[SAMPLE];
Random r = new Random();
long seed = r.nextLong();
r.setSeed(seed);
System.out.println("testSorted seed: " + seed +
"(" + sorter.getClass().getName() + ")");
for (int i = 0; i < SAMPLE; ++i) {
values[i] = r.nextInt(100);
}
Arrays.sort(values);
SampleSortable s = new SampleSortable(values);
sorter.sort(s, 0, SAMPLE);
int[] check = s.getSorted();
assertTrue(Arrays.toString(values) + "\ndoesn't match\n" +
Arrays.toString(check), Arrays.equals(values, check));
}
示例5: JordanTurbulence
import java.util.Random; //導入方法依賴的package包/類
public JordanTurbulence(Random rand, double scale, int octaves, double lacunarity, double gain1, double gain, double warp0, double warp, double damp0, double damp, double damp_scale, int distortion_octaves, double distortion_scale, double distortion_magnitude, double distortion_gain) {
this.generator = new OpenSimplexNoise(rand.nextLong());
this.scale = scale;
this.octaves = octaves;
this.lacunarity = lacunarity;
this.gain1 = gain1;
this.gain = gain;
this.warp0 = warp0;
this.warp = warp;
this.damp0 = damp0;
this.damp = damp;
this.damp_scale = damp_scale;
this.distortion_octaves = distortion_octaves;
this.distortion_scale = distortion_scale;
this.distortion_magnitude = distortion_magnitude;
this.distortion_gain = distortion_gain;
this.distortion = new OctaveNoise(rand, this.scale / distortion_scale, distortion_octaves, lacunarity, distortion_gain);
}
示例6: testWritable
import java.util.Random; //導入方法依賴的package包/類
public void testWritable() throws Exception {
Random r = new Random();
Writable[] writs = {
new BooleanWritable(r.nextBoolean()),
new FloatWritable(r.nextFloat()),
new FloatWritable(r.nextFloat()),
new IntWritable(r.nextInt()),
new LongWritable(r.nextLong()),
new BytesWritable("dingo".getBytes()),
new LongWritable(r.nextLong()),
new IntWritable(r.nextInt()),
new BytesWritable("yak".getBytes()),
new IntWritable(r.nextInt())
};
TupleWritable sTuple = makeTuple(writs);
ByteArrayOutputStream out = new ByteArrayOutputStream();
sTuple.write(new DataOutputStream(out));
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
TupleWritable dTuple = new TupleWritable();
dTuple.readFields(new DataInputStream(in));
assertTrue("Failed to write/read tuple", sTuple.equals(dTuple));
}
示例7: generate
import java.util.Random; //導入方法依賴的package包/類
public boolean generate(World worldIn, Random rand, BlockPos position)
{
this.world = worldIn;
this.basePos = position;
this.rand = new Random(rand.nextLong());
if (this.heightLimit == 0)
{
this.heightLimit = 5 + this.rand.nextInt(this.heightLimitLimit);
}
if (!this.validTreeLocation())
{
return false;
}
else
{
this.generateLeafNodeList();
this.generateLeaves();
this.generateTrunk();
this.generateLeafNodeBases();
return true;
}
}
示例8: createLongArray
import java.util.Random; //導入方法依賴的package包/類
public static long[] createLongArray(int size) {
Random rand = new Random(0);
long[] array = new long[size];
for (int i = 0; i < size; ++i) {
array[i] = rand.nextLong();
}
return array;
}
示例9: createControlFile
import java.util.Random; //導入方法依賴的package包/類
public static void createControlFile(FileSystem fs,
long megaBytes, int numFiles,
long seed) throws Exception {
LOG.info("creating control file: "+megaBytes+" bytes, "+numFiles+" files");
Path controlFile = new Path(CONTROL_DIR, "files");
fs.delete(controlFile, true);
Random random = new Random(seed);
SequenceFile.Writer writer =
SequenceFile.createWriter(fs, conf, controlFile,
Text.class, LongWritable.class, CompressionType.NONE);
long totalSize = 0;
long maxSize = ((megaBytes / numFiles) * 2) + 1;
try {
while (totalSize < megaBytes) {
Text name = new Text(Long.toString(random.nextLong()));
long size = random.nextLong();
if (size < 0)
size = -size;
size = size % maxSize;
//LOG.info(" adding: name="+name+" size="+size);
writer.append(name, new LongWritable(size));
totalSize += size;
}
} finally {
writer.close();
}
LOG.info("created control file for: "+totalSize+" bytes");
}
示例10: func_175789_b
import java.util.Random; //導入方法依賴的package包/類
private void func_175789_b(World worldIn, Random p_175789_2_, int p_175789_3_, int p_175789_4_)
{
p_175789_2_.setSeed(worldIn.getSeed());
long i = p_175789_2_.nextLong();
long j = p_175789_2_.nextLong();
long k = (long)p_175789_3_ * i;
long l = (long)p_175789_4_ * j;
p_175789_2_.setSeed(k ^ l ^ worldIn.getSeed());
int i1 = p_175789_3_ * 16 + 8 - 29;
int j1 = p_175789_4_ * 16 + 8 - 29;
EnumFacing enumfacing = EnumFacing.Plane.HORIZONTAL.random(p_175789_2_);
this.components.add(new StructureOceanMonumentPieces.MonumentBuilding(p_175789_2_, i1, j1, enumfacing));
this.updateBoundingBox();
this.field_175790_d = true;
}
示例11: BiomeBlobs
import java.util.Random; //導入方法依賴的package包/類
public BiomeBlobs(long seed, int layers) {
this.seed = seed;
this.layers = layers;
this.layerseeds = new long[layers];
Random rand = new Random(seed);
for (int i=0; i<layers; i++) {
this.layerseeds[i] = rand.nextLong();
}
}
示例12: setup
import java.util.Random; //導入方法依賴的package包/類
@Setup
public void setup()
{
Random random = new Random();
for (int i = 0; i < SIZE; i++) {
values[i] = random.nextLong() % (Long.MAX_VALUE / 32L);
}
}
示例13: testKey
import java.util.Random; //導入方法依賴的package包/類
@Test
public void testKey() {
TTUtil.halfMoveCounter = 400;
short score = 30000;
int depth = 10;
int flag = TTUtil.FLAG_LOWER;
int move = MoveUtil.createMove(10, 20, 3);
System.out.println("move: " + move);
long value = TTUtil.createValue(score, move, flag, depth);
System.out.println("score: " + TTUtil.getScore(value, 0));
System.out.println("depth: " + TTUtil.getDepth(value));
System.out.println("flag: " + TTUtil.getFlag(value));
System.out.println("move: " + TTUtil.getMove(value));
System.out.println("counter: " + TTUtil.getHalfMoveCounter(value));
Random r = new Random();
long zk = r.nextLong();
TTUtil.addValue(zk, score, 1, depth, flag, move);
long ttValue = TTUtil.getTTValue(zk);
System.out.println("score: " + TTUtil.getScore(ttValue, 0));
System.out.println("depth: " + TTUtil.getDepth(ttValue));
System.out.println("flag: " + TTUtil.getFlag(ttValue));
System.out.println("move: " + TTUtil.getMove(ttValue));
System.out.println("counter: " + TTUtil.getHalfMoveCounter(value));
}
示例14: GzipConcatTest
import java.util.Random; //導入方法依賴的package包/類
void GzipConcatTest(Configuration conf,
Class<? extends Decompressor> decomClass) throws IOException {
Random r = new Random();
long seed = r.nextLong();
r.setSeed(seed);
LOG.info(decomClass + " seed: " + seed);
final int CONCAT = r.nextInt(4) + 3;
final int BUFLEN = 128 * 1024;
DataOutputBuffer dflbuf = new DataOutputBuffer();
DataOutputBuffer chkbuf = new DataOutputBuffer();
byte[] b = new byte[BUFLEN];
for (int i = 0; i < CONCAT; ++i) {
GZIPOutputStream gzout = new GZIPOutputStream(dflbuf);
r.nextBytes(b);
int len = r.nextInt(BUFLEN);
int off = r.nextInt(BUFLEN - len);
chkbuf.write(b, off, len);
gzout.write(b, off, len);
gzout.close();
}
final byte[] chk = Arrays.copyOf(chkbuf.getData(), chkbuf.getLength());
CompressionCodec codec = ReflectionUtils.newInstance(GzipCodec.class, conf);
Decompressor decom = codec.createDecompressor();
assertNotNull(decom);
assertEquals(decomClass, decom.getClass());
DataInputBuffer gzbuf = new DataInputBuffer();
gzbuf.reset(dflbuf.getData(), dflbuf.getLength());
InputStream gzin = codec.createInputStream(gzbuf, decom);
dflbuf.reset();
IOUtils.copyBytes(gzin, dflbuf, 4096);
final byte[] dflchk = Arrays.copyOf(dflbuf.getData(), dflbuf.getLength());
assertArrayEquals(chk, dflchk);
}
示例15: initialValue
import java.util.Random; //導入方法依賴的package包/類
protected Random initialValue() {
final Random r = new Random();
final long seed = r.nextLong();
LOG.info(Thread.currentThread() + ": seed=" + seed);
r.setSeed(seed);
return r;
}