Refine search
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; }
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; }
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;
@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); } } } }
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); } }
/** * 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; } }
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"); } }
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);
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"); } }
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"); } }
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);