/** * Creates a new dice roller that will use its own RNG, seeded with the given seed. * @param seed a long to use as a seed for a new RNG (can also be an int, short, or byte) */ public Dice(long seed) { rng = new GWTRNG(seed); } /**
/** * Returns an SColor that is randomly chosen from the color line between the * two provided colors from the two provided points. * * @param color1 * @param color2 * @param min The minimum percent towards the second color, as 0.0 to 1.0 * @param max The maximum percent towards the second color, as 0.0 to 1.0 * @return */ public SColor randomBlend(SColor color1, SColor color2, double min, double max) { return blend(color1, color2, rng.between(min, max)); }
public CloudAOE(Coord center, int volume, Radius radiusType) { GWTRNG rng = new GWTRNG(); seed = rng.getState(); spill = new Spill(rng); this.center = center; this.volume = volume; expanding = false; rt = radiusType; switch (radiusType) { case SPHERE: case CIRCLE: spill.measurement = Spill.Measurement.EUCLIDEAN; break; case CUBE: case SQUARE: spill.measurement = Spill.Measurement.CHEBYSHEV; break; default: spill.measurement = Spill.Measurement.MANHATTAN; break; } }
fresh = true; rng.setState(stateA, stateB); long seedA = rng.nextLong(), seedB = rng.nextLong(), seedC = rng.nextLong(); int t; landModifier = (landMod <= 0) ? rng.nextDouble(0.29) + 0.91 : landMod; coolingModifier = (coolMod <= 0) ? rng.nextDouble(0.45) * (rng.nextDouble()-0.5) + 1.1 : coolMod;
public static FakeLanguageGen randomLanguage(long seed) { GWTRNG rng = new GWTRNG(seed); int[] lengths = new int[rng.between(3, 5)]; System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); double[] chances = new double[lengths.length]; System.arraycopy(new double[]{ 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) }, 0, chances, 0, chances.length); double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); int sz = openCons.size(); int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); OrderedMap<String, String> parts0 = new OrderedMap<>(openVowels), int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); char[] nextAccents = new char[sz0], unaccented = new char[sz0]; int vowelAccent = rng.between(1, 7); for (int i = 0; i < sz0; i++) { nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; unaccented[i] = accentedVowels[vOrd[i + mn]][0]; if (rng.nextDouble() < 0.8) { for (int i = 0; i < sz0; i++) { char ac = nextAccents[i], ua = unaccented[i]; if (rng.nextDouble() < 0.75) { missingSounds.add("z"); Collections.addAll(forbidden, parts1.get("z").split(" "));
/** * Allows this Thesaurus to replace a specific keyword, typically containing multiple backtick characters ('`') so * it can't be confused with a "real word," with one of the words in synonyms (chosen in shuffled order). The * backtick is the only punctuation character that this class' word matcher considers part of a word, both for this * reason and because it is rarely used in English text. * @param keyword a word (typically containing backticks, '`') that will be replaced by a word from synonyms * @param synonyms a Collection of lower-case Strings with similar meaning and the same part of speech * @return this for chaining */ public Thesaurus addCategory(String keyword, Collection<String> synonyms) { if(synonyms.isEmpty()) return this; long prevState = rng.getState(); rng.setState(CrossHash.hash64(synonyms)); GapShuffler<String> shuffler = new GapShuffler<>(synonyms, rng); mappings.put(keyword, shuffler); rng.setState(prevState); return this; }
@Override public void appendSubstitution(MatchResult match, TextBuffer dest) { FakeLanguageGen lang = FakeLanguageGen.randomLanguage(rng.nextLong()); randomLanguages.add(lang); if(match.isCaptured(1)) { lang = FakeLanguageGen.randomLanguage(rng.nextLong()); randomLanguages.add(lang); do { latestGenerated = randomLanguages.get(0).word(rng, true, Math.min(rng.between(2, 5), rng.between(1, 5))) + "-" + randomLanguages.get(1).word(rng, true, Math.min(rng.between(2, 5), rng.between(1, 5))); }while (latestGenerated.length() <= 5 || latestGenerated.length() >= 17); dest.append(latestGenerated); } else { do{ latestGenerated = lang.word(rng, true, Math.min(rng.between(2, 5), rng.between(1, 5))); }while (latestGenerated.length() <= 2 || latestGenerated.length() >= 11); dest.append(latestGenerated); } } }
/** * Copies this ProbabilityTable so nothing in the copy is shared with the original, except for the T items (which * might not be possible to copy). The RNG is also copied. * @return a copy of this ProbabilityTable; no references should be shared except for T items */ public ProbabilityTable<T> copy() { ProbabilityTable<T> n = new ProbabilityTable<>(rng.getState()); n.weights.addAll(weights); n.table.putAll(table); for (int i = 0; i < extraTable.size(); i++) { n.extraTable.add(extraTable.get(i).copy()); } n.total = total; n.normalTotal = normalTotal; return n; }
String working = process(rng.getRandomElement(nationTerms)); int frustration = 0; while (frustration++ < 8 && similarFinder.matches(working)) working = process(rng.getRandomElement(nationTerms)); randomLanguages.clear(); KnownLanguageSubstitution sub = new KnownLanguageSubstitution(language);
/** * Generates a world using a random RNG state and all parameters randomized. * The worlds this produces will always have width and height as specified in the constructor (default 256x256). * You can call {@link #zoomIn(int, int, int)} to double the resolution and center on the specified area, but the width * and height of the 2D arrays this changed, such as {@link #heightData} and {@link #moistureData} will be the same. */ public void generate() { generate(rng.nextLong()); }
@Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ProbabilityTable<?> that = (ProbabilityTable<?>) o; if (!table.equals(that.table)) return false; if (!extraTable.equals(that.extraTable)) return false; if (!weights.equals(that.weights)) return false; return rng != null ? rng.equals(that.rng) : that.rng == null; }
@Override public int hashCode() { int result = table.hashCode(); result = 31 * result + extraTable.hashCode() | 0; result = 31 * result + weights.hashWisp() | 0; result = 31 * result + (rng != null ? rng.hashCode() : 0) | 0; return result; } }
/** * Returns an object randomly based on assigned weights. * * Returns null if no elements have been put in the table. * * @return the chosen object or null */ public T random() { if (table.isEmpty()) { return null; } int index = (int) ((total * ((long)rng.next(31))) >>> 31), sz = table.size(); for (int i = 0; i < sz; i++) { index -= weights.get(i); if (index < 0) return table.keyAt(i); } for (int i = 0; i < extraTable.size(); i++) { index -= weights.get(sz + i); if(index < 0) return extraTable.get(i).random(); } return null;//something went wrong, shouldn't have been able to get all the way through without finding an item }
if (rng.nextDouble() < alt.chance) { if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) break;
fresh = true; rng.setState(stateA, stateB); long seedA = rng.nextLong(), seedB = rng.nextLong(), seedC = rng.nextLong(); int t; landModifier = (landMod <= 0) ? rng.nextDouble(0.2) + 0.91 : landMod; coolingModifier = (coolMod <= 0) ? rng.nextDouble(0.45) * (rng.nextDouble()-0.5) + 1.1 : coolMod;
/** * Allows this Thesaurus to find the exact words in synonyms and, when requested, replace each occurrence with a * different word from the same Collection. Each word in synonyms should have the same part of speech, so "demon" * and "devils" should not be in the same list of synonyms (singular noun and plural noun), but "demon" and "devil" * could be (each is a singular noun). The Strings in synonyms should all be lower-case, since case is picked up * from the text as it is being replaced and not from the words themselves. Proper nouns should normally not be used * as synonyms, since this could get very confusing if it changed occurrences of "Germany" to "France" at random and * a character's name, like "Dorothy", to "Anne", "Emily", "Cynthia", etc. in the middle of a section about Dorothy. * The word matching pattern this uses only matches all-letter words, not words that contain hyphens, apostrophes, * or other punctuation. * @param synonyms a Collection of lower-case Strings with similar meaning and the same part of speech * @return this for chaining */ public Thesaurus addSynonyms(Collection<String> synonyms) { if(synonyms.isEmpty()) return this; long prevState = rng.getState(); rng.setState(CrossHash.hash64(synonyms)); GapShuffler<String> shuffler = new GapShuffler<>(synonyms, rng); for(String syn : synonyms) { mappings.put(syn, shuffler); } rng.setState(prevState); return this; }
@Override public String stringify(ProbabilityTable<K> item) { StringBuilder sb = new StringBuilder(256); appendQuoted(sb, StringKit.hex(item.getRandom().getState())); sb.append(' '); appendQuoted(sb, convertIntVLA.stringify(item.weights)); sb.append(' '); appendQuoted(sb, convertArrange.stringify(item.table)); for (int i = 0; i < item.extraTable.size(); i++) { sb.append(' '); appendQuoted(sb, stringify(item.extraTable.get(i))); } return sb.toString(); }