/** * Gets a random color from the palette {@link #COLOR_WHEEL_PALETTE_REDUCED}, using the specified IRNG to determine * saturation, brightness, and hue. * @param rng used to choose everything * @return a randomly selected SColor from {@link #COLOR_WHEEL_PALETTE_REDUCED} */ public static SColor randomColorWheel(IRNG rng) { return COLOR_WHEEL_PALETTE_REDUCED[rng.nextInt(144)]; } /**
/** * Generates a random ordering with rng and applies the same ordering to all kinds of keys this has; they will * maintain their current association to other keys but their ordering/indices will change. * @param rng an IRNG to produce the random ordering this will use * @return this for chaining */ public MultiKey shuffle(IRNG rng) { if(keyCount > 0) { int[] ordering = rng.randomOrdering(keys[0].size); for (int i = 0; i < keyCount; i++) { keys[i].reorder(ordering); } } return this; }
protected String[] accentVowels(IRNG rng, String[] me, double influence) { String[] ret = new String[1000]; int otherCount = (int) (1000 * influence); int idx = 0; Matcher matcher; if (me.length > 0) { String[] tmp = new String[me.length]; rng.shuffle(me, tmp); for (idx = 0; idx < otherCount; idx++) { ret[idx] = tmp[idx % tmp.length] .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); matcher = repeats.matcher(ret[idx]); if (matcher.find()) { ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); } } for (; idx < 1000; idx++) { ret[idx] = tmp[idx % tmp.length]; } } else return new String[]{}; return ret; }
/** * Removes a circle from {@code zone}, by taking the circle's center in * {@code zone} 's border: {@code border}. * * @param border * {@code result}'s border. */ private void inebriate0(IRNG rng, List<Coord> zone, List<Coord> border, int nb) { assert !border.isEmpty(); assert !zone.isEmpty(); final int width = rng.nextInt(nb) + 1; final int height = rng.nextInt(nb) + 1; final int radius = Math.max(1, Math.round(nb * Math.min(width, height))); final Coord center = rng.getRandomElement(border); zone.remove(center); for (int dx = -radius; dx <= radius; ++dx) { final int high = (int) Math.floor(Math.sqrt(radius * radius - dx * dx)); for (int dy = -high; dy <= high; ++dy) { final Coord c = center.translate(dx, dy); zone.remove(c); if (zone.isEmpty()) return; } } }
throw new IllegalArgumentException("width and height must be greater than 2"); CoordPacker.init(); long columnAlterations = random.nextLong(0x1000000000000L); float columnBase = width / (Long.bitCount(columnAlterations) + 48.0f); long rowAlterations = random.nextLong(0x1000000000000L); float rowBase = height / (Long.bitCount(rowAlterations) + 48.0f); int m = random.nextInt(64), r = random.between(4, 12); temp = CoordPacker.mooreToCoord(m); Coord starter = CoordPacker.mooreToCoord(m); cl.add(Coord.get(columns[temp.x], rows[temp.y])); temp = CoordPacker.mooreToCoord(m); r = random.between(4, 12); for (int j = 0, p = r - 1; j < 3 && p > 2 && Math.min(random.nextDouble(), random.nextDouble()) < branchingChance; j++, p -= random.between(1, p)) { t = CoordPacker.mooreToCoord(m + p); cl.add(Coord.get(columns[t.x], rows[t.y]));
rng.randomOrdering(adjacency.maxAdjacent, reuse); int choice = rng.nextInt(adjacency.maxAdjacent);
if (me.length > 0) { String[] tmp = new String[me.length]; rng.shuffle(me, tmp); for (idx = 0; idx < 1000; idx++) { boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; if (subVowel && subCon) { ret[idx] = tmp[idx % tmp.length] .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)])
ssb.append(word(rng, true)); for (int i = 1; i < minWords; i++) { if (rng.nextDouble() < midPunctuationFrequency) { ssb.append(rng.getRandomElement(midPunctuation)); for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { if (rng.nextDouble() < midPunctuationFrequency) { ssb.append(rng.getRandomElement(midPunctuation)); ssb.append(rng.getRandomElement(endPunctuation)); return ssb.toString();
throw new IllegalArgumentException("width and height must be greater than 2"); CoordPacker.init(); long columnAlterations = (rng.nextLong() & 0xFFFFFFFFFFFFL); float columnBase = width / (Long.bitCount(columnAlterations) + 48.0f); long rowAlterations = (rng.nextLong() & 0xFFFFFFFFFFFFL); float rowBase = height / (Long.bitCount(rowAlterations) + 48.0f); int m = rng.nextInt(64); Coord temp = CoordPacker.mooreToCoord(m), next; temp = Coord.get(columns[temp.x], rows[temp.y]); for (int i = 0, r; i < 256; r = rng.between(4, 12), i += r, m += r) { next = CoordPacker.mooreToCoord(m); next = Coord.get(columns[next.x], rows[next.y]);
while (!added) float d = rng.nextFloat(); int xr = Math.round(minPosition.x + dimensions.x * d); d = rng.nextFloat(); int yr = Math.round(minPosition.y + dimensions.y * d); int listIndex = rng.nextInt(activePoints.size()); float d = rng.nextFloat(); float radius = minimumDistance + minimumDistance * d; float angle = pi2 * rng.nextFloat();
randomBits = random.nextLong(); for (long a = 1; a != 0; a <<= 1) { field[x][y++] = (randomBits & a) == 0; int x = random.nextInt(size), y = random.nextInt(size); field[x][y] ^= (q > random.nextDouble());
if (y + N >= OH) result[x + y * OW] = sample[random.nextInt(SW * SH)]; origins[x + y * OW] = -1; if (indexed) argmax = weightedRandom(candidates, random.nextDouble()); result[i] = sample[argmax]; origins[i] = -1;
this.rng = rng.copy(); this.elements = rng.shuffle(elements); size = this.elements.size(); double sz2 = size; for (int i = 0; i < indexSections.length - 1; i++) { indexSections[i] = PermutationGenerator.decodePermutation( rng.nextLong(PermutationGenerator.getTotalPermutations(portionSize)), portionSize, i * portionSize); sz2 -= portionSize; rng.nextLong(PermutationGenerator.getTotalPermutations((int)sz2)), (int)sz2, (indexSections.length - 1) * portionSize);
private double truncatedQuantile(double expected) { if(expected >= 0.5) return rng.nextDouble() * (1.0 - expected) * 2 + expected - (1.0 - expected); return rng.nextDouble() * expected * 2; } private double bathtubQuantile(double expected)
REDO: while (frustration < 10) { shift = rng.nextDouble(2048); shift2 = rng.between(4096, 8192); ctr = 0; for (int x = 0; x < width; x++) { regions = rng.shuffle(regions); while (regions.size() > 1)
/** * Looks up the given kind in the Map of biases this stores, and generates a random number using this object's RNG. * If the kind is in the Map, this adjusts the generated number so it matches a distribution that would have the * expected average the kind was associated with. The returned number will be a float between 0.0 and 1.0 * (exclusive on 1.0). If the kind is not in the map, this generates a float using RNG and no further changes. * @param kind the kind of bias to look up * @return a random float between 0.0 and 1.0, potentially influenced by the bias associated with kind, if present */ public float biasedFloat(String kind) { Double d = biases.get(kind); if(d == null) return rng.nextFloat(); return (float) quantile(d); }
Coord start = Coord.get(pair >>> 24 & 0xff, pair >>> 16 & 0xff), end = Coord.get(pair >>> 8 & 0xff, pair & 0xff); int ct = carverTable.random(rng.nextLong()); Direction dir; switch (ct) break; case BOX: markRectangle(end, rng.between(1, 5), rng.between(1, 5)); markRectangle(start, rng.between(1, 4), rng.between(1, 4)); store(); dir = Direction.getDirection(end.x - start.x, end.y - start.y); if(dir.isDiagonal()) dir = rng.nextBoolean() ? Direction.getCardinalDirection(dir.deltaX, 0) : Direction.getCardinalDirection(0, -dir.deltaY); while (start.x != end.x && start.y != end.y) markRectangleWalled(end, rng.between(1, 5), rng.between(1, 5)); markRectangleWalled(start, rng.between(1, 4), rng.between(1, 4)); store(); dir = Direction.getDirection(end.x - start.x, end.y - start.y); if(dir.isDiagonal()) dir = rng.nextBoolean() ? Direction.getCardinalDirection(dir.deltaX, 0) : Direction.getCardinalDirection(0, -dir.deltaY); while (start.x != end.x && start.y != end.y) markCircle(end, rng.between(2, 6)); markCircle(start, rng.between(2, 6)); store();
double syllableChance = rng.nextDouble(totalSyllableFrequency); int syllables = 1, i = 0; for (int s = 0; s < syllableFrequencies.length; s++) { if (rng.nextDouble() < vowelStartFrequency) { sb.append(rng.getRandomElement(openingVowels)); if (syllables == 1) sb.append(rng.getRandomElement(closingConsonants)); else sb.append(rng.getRandomElement(midConsonants)); i++; } else { sb.append(rng.getRandomElement(openingConsonants)); if (rng.nextDouble() < syllableEndFrequency) { close = rng.getRandomElement(closingSyllables); if (close.contains("@") && (syllables & 1) == 0) { redouble = true; else if (rng.nextDouble() < vowelEndFrequency) { ender.append(rng.getRandomElement(midVowels)); if (rng.nextDouble() < vowelSplitFrequency) { ender.append(rng.getRandomElement(vowelSplitters)) .append(rng.getRandomElement(midVowels)); ender.append(rng.getRandomElement(midVowels)); if (rng.nextDouble() < vowelSplitFrequency) { ender.append(rng.getRandomElement(vowelSplitters)) .append(rng.getRandomElement(midVowels));