当前位置: 首页>>代码示例>>Java>>正文


Java Random.nextLong方法代码示例

本文整理汇总了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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:CacheTestUtils.java

示例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
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:InfoTest.java

示例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;
}
 
开发者ID:s-store,项目名称:s-store,代码行数:27,代码来源:EvilDeterminism.java

示例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));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestIndexedSort.java

示例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);
}
 
开发者ID:stuebz88,项目名称:modName,代码行数:21,代码来源:JordanTurbulence.java

示例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));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:23,代码来源:TestTupleWritable.java

示例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;
    }
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:25,代码来源:WorldGenBigTree.java

示例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;
}
 
开发者ID:richardstartin,项目名称:simdbenchmarks,代码行数:9,代码来源:DataUtil.java

示例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");
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:TestFileSystem.java

示例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;
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:16,代码来源:StructureOceanMonument.java

示例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();
    }
}
 
开发者ID:stuebz88,项目名称:modName,代码行数:12,代码来源:BiomeBlobs.java

示例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);
    }
}
 
开发者ID:pnowojski,项目名称:simd-blog,代码行数:9,代码来源:BenchmarkSIMDLongBlog.java

示例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));
}
 
开发者ID:sandermvdb,项目名称:chess22k,代码行数:30,代码来源:TTTest.java

示例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);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:37,代码来源:TestCodec.java

示例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;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:FiTestUtil.java


注:本文中的java.util.Random.nextLong方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。