java.util.Random.setSeed()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(144)

本文整理了Java中java.util.Random.setSeed()方法的一些代码示例,展示了Random.setSeed()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Random.setSeed()方法的具体详情如下:
包路径:java.util.Random
类名称:Random
方法名:setSeed

Random.setSeed介绍

[英]Modifies the seed using a linear congruential formula presented in The Art of Computer Programming, Volume 2, Section 3.2.1.
[中]使用计算机编程技术第2卷第3.2.1节中提出的线性同余公式修改种子。

代码示例

代码示例来源:origin: alibaba/jstorm

@Override
public void prepare(Map stormConf, TopologyContext context) {
  rand = new Random();
  rand.setSeed(System.currentTimeMillis());
}

代码示例来源:origin: stackoverflow.com

public class Numbers {
  Random randnum;

  public Numbers() {
    randnum = new Random();
    randnum.setSeed(123456789);
  }

  public int random(int i){
    return randnum.nextInt(i);
  }
}

代码示例来源:origin: GlowstoneMC/Glowstone

private List<LeveledEnchant> calculateCurrentEnchants(ItemStack item, int level, int cost) {
  random.setSeed(xpSeed + level);
  int modifier = calculateRandomizedModifier(random, item, cost);
  if (modifier <= 0) {
    return null;
  }
  List<LeveledEnchant> possibleEnchants = getAllPossibleEnchants(item, modifier, cost);
  if (possibleEnchants == null || possibleEnchants.isEmpty()) {
    return null;
  }
  LeveledEnchant chosen = WeightedRandom.getRandom(random, possibleEnchants);
  if (chosen == null) {
    return null;
  }
  List<LeveledEnchant> enchants = new ArrayList<>();
  enchants.add(chosen);
  while (random.nextInt(50) <= modifier) {
    removeConflicting(enchants, possibleEnchants);
    if (!possibleEnchants.isEmpty()) {
      enchants.add(WeightedRandom.getRandom(random, possibleEnchants));
    }
    modifier /= 2;
  }
  if (item.getType() == Material.BOOK && enchants.size() > 1) {
    enchants.remove(random.nextInt(enchants.size()));
  }
  return enchants;
}

代码示例来源:origin: JZ-Darkal/AndroidHttpCapture

public static long initRandomSerial() {
  final Random rnd = new Random();
  rnd.setSeed(System.currentTimeMillis());
  // prevent browser certificate caches, cause of doubled serial numbers
  // using 48bit random number
  long sl = ((long) rnd.nextInt()) << 32 | (rnd.nextInt() & 0xFFFFFFFFL);
  // let reserve of 16 bit for increasing, serials have to be positive
  sl = sl & 0x0000FFFFFFFFFFFFL;
  return sl;
}

代码示例来源:origin: apache/hive

private static void writeJunk(DataOutput out, Random r, long seed, int iter)
  throws IOException  {
 r.setSeed(seed);
 for (int i = 0; i < iter; ++i) {
  switch (r.nextInt(numCases)) {
   case 0: out.writeByte(r.nextInt()); break;
   case 1: out.writeShort((short)(r.nextInt() & 0xFFFF)); break;
   case 2: out.writeInt(r.nextInt()); break;
   case 3: out.writeLong(r.nextLong()); break;

代码示例来源:origin: h2oai/h2o-2

@Override
 public void map (Chunk[]cs){
  if (_frac == 0) return;
  final Random rng = new Random();
  for (int c = 0; c < cs.length; c++) {
   for (int r = 0; r < cs[c]._len; r++) {
    rng.setSeed(_seed + 1234 * c ^ 1723 * (cs[c]._start + r)); //row+col-dependent RNG for reproducibility
    if (rng.nextDouble() < _frac) cs[c].setNA0(r);
   }
  }
 }
}

代码示例来源:origin: ankidroid/Anki-Android

public int _dueForDid(long did, int due) {
  JSONObject conf = mDecks.confForDid(did);
  // in order due?
  try {
    if (conf.getJSONObject("new").getInt("order") == Consts.NEW_CARDS_DUE) {
      return due;
    } else {
      // random mode; seed with note ts so all cards of this note get
      // the same random number
      Random r = new Random();
      r.setSeed(due);
      return r.nextInt(Math.max(due, 1000) - 1) + 1;
    }
  } catch (JSONException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

final long end = System.currentTimeMillis() + 5000;
final Random rand = new SecureRandom();
rand.setSeed(end);
int count = 1;
do {
  logger.debug("Log Message {}", count++);
  Thread.sleep(10 * rand.nextInt(100));
} while (System.currentTimeMillis() < end);
final File dir = new File(DIR);

代码示例来源:origin: apache/geode

@Override
protected final void postSetUpRegionVersionHolderSmallBitSetJUnitTest() throws Exception {
 long seed = System.nanoTime();
 random = new Random();
 random.setSeed(seed); // 1194319178069961L;
 System.out.println("RegionVersionHolderJUnitTest using random seed " + seed);
}

代码示例来源:origin: greenrobot/greenDAO

/**
   * Creates the same random sequence of indexes. To be used to select strings by {@link
   * #createFixedRandomStrings(int)}.
   */
  public static int[] getFixedRandomIndices(int count, int maxIndex) {
    int[] indices = new int[count];

    Random random = new Random();
    random.setSeed(StringGenerator.SEED);

    for (int i = 0; i < count; i++) {
      indices[i] = random.nextInt(maxIndex + 1);
    }

    return indices;
  }
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

final long end = System.currentTimeMillis() + 5000;
final Random rand = new SecureRandom();
rand.setSeed(end);
int count = 1;
do {
  logger.debug("Log Message {}", count++);
  Thread.sleep(10 * rand.nextInt(100));
} while (System.currentTimeMillis() < end);
final File dir = new File(DIR);

代码示例来源:origin: ankidroid/Anki-Android

Random r = new Random();
r.setSeed(mToday);
Collections.shuffle(mLrnDayQueue, r);

代码示例来源:origin: scouter-project/scouter

public static void main(String[] args) {
    long stime = System.currentTimeMillis();
    TopN<Integer> list = new TopN<Integer>(1000, TopN.DIRECTION.DESC);
    Random r = new Random();
    r.setSeed(System.currentTimeMillis());
    for (int i = 0; i < 100000; i++) {
      list.add(new Integer(r.nextInt(100000)));
    }
    System.out.println(list.size() + " : " + list.getList());
    long etime = System.currentTimeMillis();
    System.out.println((etime - stime) + " ms");

  }
}

代码示例来源:origin: apache/flink

long seed = random.nextLong();
random.setSeed(seed);
byte[] src = new byte[pageSize / 8];
for (int i = 0; i < 8; i++) {
random.setSeed(seed);
byte[] expected = new byte[pageSize / 8];
byte[] actual = new byte[pageSize / 8];
  int numBytes = random.nextInt(pageSize - 10) + 1;
  int pos = random.nextInt(pageSize - numBytes + 1);
  byte[] data = new byte[(random.nextInt(3) + 1) * numBytes];
  int dataStartPos = random.nextInt(data.length - numBytes + 1);

代码示例来源:origin: alibaba/jstorm

random = new Random();
random.setSeed(System.currentTimeMillis());
idGenerate = new Random(Utils.secureRandomLong());

代码示例来源:origin: scouter-project/scouter

public static void main(String[] args) {
    long stime = System.currentTimeMillis();
    TopN<Integer> list = new TopN<Integer>(1000, TopN.DIRECTION.DESC);
    Random r = new Random();
    r.setSeed(System.currentTimeMillis());
    for (int i = 0; i < 100000; i++) {
      list.add(new Integer(r.nextInt(100000)));
    }
    System.out.println(list.size() + " : " + list.getList());
    long etime = System.currentTimeMillis();
    System.out.println((etime - stime) + " ms");

  }
}

代码示例来源:origin: graphhopper/graphhopper

BBox b = mg.setBounds(0, d.width, 0, d.height);
if (fastPaint) {
  rand.setSeed(0);
  bitset.clear();
AllEdgesIterator edge = graph.getAllEdges();
while (edge.next()) {
  if (fastPaint && rand.nextInt(30) > 1)
    continue;

代码示例来源:origin: ankidroid/Anki-Android

Random r = new Random();
r.setSeed(mToday);
Collections.shuffle(mRevQueue, r);

代码示例来源:origin: scouter-project/scouter

public static void main(String[] args) {
    long stime = System.currentTimeMillis();
    TopN<Integer> list = new TopN<Integer>(1000, TopN.DIRECTION.DESC);
    Random r = new Random();
    r.setSeed(System.currentTimeMillis());
    for (int i = 0; i < 100000; i++) {
      list.add(new Integer(r.nextInt(100000)));
    }
    System.out.println(list.size() + " : " + list.getList());
    long etime = System.currentTimeMillis();
    System.out.println((etime - stime) + " ms");

  }
}

代码示例来源:origin: h2oai/h2o-3

int i = rng.nextInt(len);
 double weight = weightIdx == -1 ? 1 : _fr.vec(weightIdx).at(i);
 if (weight == 0)
 int i = rng.nextInt(len);
 double weight = weightIdx == -1 ? 1 : _fr.vec(weightIdx).at(i);
 if (weight == 0)
rng.setSeed(seed);
Collections.shuffle(trainLabels, rng);
rng.setSeed(seed);
Collections.shuffle(trainData, rng);

相关文章