From 42b72c67faca32aaeae1d6c0bab1c076c073b5f7 Mon Sep 17 00:00:00 2001 From: Tommy Ettinger Date: Wed, 20 Sep 2017 21:29:05 -0700 Subject: [PATCH] Add CriticalRNG for super-luck, update others CriticalRNG should make some unusual cases easier to implement, where a character can exceed the normal limits of what some ability can do by sheer luck. It isn't a general RNG since it can and frequently will produce values that are larger or smaller than an arrays's limits if it's used to get a random element from an array as-is; instead it could be used to get multiple items from that array if the value is very high, or from a different array if it is high or low. Various subclasses of RNG hadn't been looked at in a while; some methods were marked GwtIncompatible but that no longer applied as of GWT 2.8.0, while others could be made more general thanks to changes in APIs elsewhere (String parameters were just passed to CrossHash, so they could be CharSequence parameters and so take StringBuilders and such). --- docs/squidlib-util/allclasses-frame.html | 1 + docs/squidlib-util/allclasses-noframe.html | 1 + docs/squidlib-util/constant-values.html | 14 +- docs/squidlib-util/index-files/index-13.html | 6 +- docs/squidlib-util/index-files/index-15.html | 22 +- docs/squidlib-util/index-files/index-18.html | 2 + docs/squidlib-util/index-files/index-19.html | 16 +- docs/squidlib-util/index-files/index-2.html | 9 +- docs/squidlib-util/index-files/index-20.html | 18 +- docs/squidlib-util/index-files/index-4.html | 38 + docs/squidlib-util/index-files/index-5.html | 4 +- docs/squidlib-util/index-files/index-6.html | 2 +- docs/squidlib-util/index-files/index-8.html | 14 +- docs/squidlib-util/overview-tree.html | 1 + docs/squidlib-util/serialized-form.html | 17 + .../squidpony/FakeLanguageGen.Alteration.html | 26 +- .../squidpony/FakeLanguageGen.Modifier.html | 62 +- .../FakeLanguageGen.SentenceForm.html | 34 +- .../squidpony/FakeLanguageGen.html | 202 +- .../annotation/class-use/GwtIncompatible.html | 36 - .../squidpony/class-use/FakeLanguageGen.html | 61 +- .../squidpony/squidmath/CosmicNumbering.html | 4 +- .../squidpony/squidmath/CriticalRNG.html | 878 ++++ .../squidpony/squidmath/CrossHash.html | 4 +- .../squidpony/squidmath/DeckRNG.html | 221 +- .../squidpony/squidmath/DharmaRNG.html | 377 +- .../squidpony/squidmath/EditRNG.html | 397 +- .../squidpony/squidmath/MeadNoise.html | 46 +- .../squidpony/squidmath/RNG.CustomRandom.html | 8 +- .../squidpony/squidmath/RNG.html | 144 +- .../squidpony/squidmath/StatefulRNG.html | 18 +- .../squidmath/class-use/CriticalRNG.html | 125 + .../squidpony/squidmath/class-use/RNG.html | 12 +- .../squidmath/class-use/RandomnessSource.html | 11 + .../squidmath/class-use/ShortSet.html | 4 + .../squidpony/squidmath/package-frame.html | 1 + .../squidpony/squidmath/package-summary.html | 220 +- .../squidpony/squidmath/package-tree.html | 1 + .../squidpony/FakeLanguageGen.Alteration.html | 4384 +++++++++-------- .../squidpony/FakeLanguageGen.Modifier.html | 4384 +++++++++-------- .../FakeLanguageGen.SentenceForm.html | 4384 +++++++++-------- .../src-html/squidpony/FakeLanguageGen.html | 4384 +++++++++-------- .../src-html/squidpony/StringKit.html | 2 +- .../squidpony/squidmath/CriticalRNG.html | 268 + .../src-html/squidpony/squidmath/DeckRNG.html | 1154 +++-- .../squidpony/squidmath/DharmaRNG.html | 1094 ++-- .../src-html/squidpony/squidmath/EditRNG.html | 1253 +++-- .../squidpony/squidmath/MeadNoise.html | 834 ++-- .../squidpony/squidmath/RNG.CustomRandom.html | 2154 ++++---- .../src-html/squidpony/squidmath/RNG.html | 2154 ++++---- .../squidpony/squidmath/StatefulRNG.html | 4 +- .../java/squidpony/squidmath/CriticalRNG.java | 196 + .../java/squidpony/squidmath/DeckRNG.java | 30 +- .../java/squidpony/squidmath/DharmaRNG.java | 66 +- .../java/squidpony/squidmath/EditRNG.java | 65 +- .../main/java/squidpony/squidmath/RNG.java | 22 +- .../java/squidpony/squidmath/StatefulRNG.java | 4 +- .../squidpony/examples/RNGFeatureTest.java | 24 +- 58 files changed, 15473 insertions(+), 14444 deletions(-) create mode 100644 docs/squidlib-util/squidpony/squidmath/CriticalRNG.html create mode 100644 docs/squidlib-util/squidpony/squidmath/class-use/CriticalRNG.html create mode 100644 docs/squidlib-util/src-html/squidpony/squidmath/CriticalRNG.html create mode 100644 squidlib-util/src/main/java/squidpony/squidmath/CriticalRNG.java diff --git a/docs/squidlib-util/allclasses-frame.html b/docs/squidlib-util/allclasses-frame.html index f2f904cb89..4fb9a7a13c 100644 --- a/docs/squidlib-util/allclasses-frame.html +++ b/docs/squidlib-util/allclasses-frame.html @@ -57,6 +57,7 @@

All Classes

  • CornerCaves
  • CosmicNumbering
  • CountConstraints
  • +
  • CriticalRNG
  • CrossHash
  • CrossHash.Falcon
  • CrossHash.IHasher
  • diff --git a/docs/squidlib-util/allclasses-noframe.html b/docs/squidlib-util/allclasses-noframe.html index b157744e2c..ab6fd10a21 100644 --- a/docs/squidlib-util/allclasses-noframe.html +++ b/docs/squidlib-util/allclasses-noframe.html @@ -57,6 +57,7 @@

    All Classes

  • CornerCaves
  • CosmicNumbering
  • CountConstraints
  • +
  • CriticalRNG
  • CrossHash
  • CrossHash.Falcon
  • CrossHash.IHasher
  • diff --git a/docs/squidlib-util/constant-values.html b/docs/squidlib-util/constant-values.html index 13e1e911a8..211d3806e6 100644 --- a/docs/squidlib-util/constant-values.html +++ b/docs/squidlib-util/constant-values.html @@ -287,14 +287,14 @@

    squidpony.*

    public static final String LATIN_EXTENDED_LETTERS -"\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJ\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012fi\u0307\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" +"\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJ\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012f\u0131\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" public static final String LATIN_EXTENDED_LETTERS_LOWER -"\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012fi\u0307\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" +"\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012f\u0131\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" @@ -308,14 +308,14 @@

    squidpony.*

    public static final String LATIN_LETTERS -"ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJabcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012fi\u0307\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJabcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012f\u0131\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" public static final String LATIN_LETTERS_LOWER -"abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012fi\u0307\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" +"abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012f\u0131\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237" @@ -329,21 +329,21 @@

    squidpony.*

    public static final String LETTERS -"ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJ\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039a\u039b\u039c\u039d\u039e\u039f\u03a0\u03a1\u03a3\u03a3\u03a4\u03a5\u03a6\u03a7\u03a8\u03a9\u0386\u0388\u0389\u038a\u038c\u038e\u038f\u03aa\u03ab\u03aa\u03ab\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041a\u041b\u041c\u041d\u041e\u041f\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042a\u042b\u042c\u042d\u042e\u042f\u0400\u0401\u0402\u0403\u0404\u0405\u0406\u0407\u0408\u0409\u040a\u040b\u040c\u040d\u040e\u040f\u0474\u0490abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012fi\u0307\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ac\u03ad\u03ae\u03af\u03cc\u03cd\u03ce\u03ca\u03cb\u0390\u03b0\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f\u0450\u0451\u0452\u0453\u0454\u0455\u0456\u0457\u0458\u0459\u045a\u045b\u045c\u045d\u045e\u045f\u0475\u0491" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJ\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039a\u039b\u039c\u039d\u039e\u039f\u03a0\u03a1\u03a3\u03a3\u03a4\u03a5\u03a6\u03a7\u03a8\u03a9\u0386\u0388\u0389\u038a\u038c\u038e\u038f\u03aa\u03ab\u03aa\u03ab\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041a\u041b\u041c\u041d\u041e\u041f\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042a\u042b\u042c\u042d\u042e\u042f\u0400\u0401\u0402\u0403\u0404\u0405\u0406\u0407\u0408\u0409\u040a\u040b\u040c\u040d\u040e\u040f\u0474\u0490abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012f\u0131\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ac\u03ad\u03ae\u03af\u03cc\u03cd\u03ce\u03ca\u03cb\u0390\u03b0\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f\u0450\u0451\u0452\u0453\u0454\u0455\u0456\u0457\u0458\u0459\u045a\u045b\u045c\u045d\u045e\u045f\u0475\u0491" public static final String LETTERS_AND_NUMBERS -"ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJ\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039a\u039b\u039c\u039d\u039e\u039f\u03a0\u03a1\u03a3\u03a3\u03a4\u03a5\u03a6\u03a7\u03a8\u03a9\u0386\u0388\u0389\u038a\u038c\u038e\u038f\u03aa\u03ab\u03aa\u03ab\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041a\u041b\u041c\u041d\u041e\u041f\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042a\u042b\u042c\u042d\u042e\u042f\u0400\u0401\u0402\u0403\u0404\u0405\u0406\u0407\u0408\u0409\u040a\u040b\u040c\u040d\u040e\u040f\u0474\u0490abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012fi\u0307\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ac\u03ad\u03ae\u03af\u03cc\u03cd\u03ce\u03ca\u03cb\u0390\u03b0\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f\u0450\u0451\u0452\u0453\u0454\u0455\u0456\u0457\u0458\u0459\u045a\u045b\u045c\u045d\u045e\u045f\u0475\u04910123456789" +"ABCDEFGHIJKLMNOPQRSTUVWXYZ\u00c0\u00c1\u00c2\u00c3\u00c4\u00c5\u00c6\u00c7\u00c8\u00c9\u00ca\u00cb\u00cc\u00cd\u00ce\u00cf\u00d0\u00d1\u00d2\u00d3\u00d4\u00d5\u00d6\u00d8\u00d9\u00da\u00db\u00dc\u00dd\u00de\u0100\u0102\u0104\u0106\u0108\u010a\u010c\u010e\u0110\u0112\u0114\u0116\u0118\u011a\u011c\u011e\u0120\u0122\u0124\u0126\u0128\u012a\u012c\u012e\u0130\u0134\u0136\u0139\u013b\u013d\u013f\u0141\u0143\u0145\u0147\u014a\u014c\u014e\u0150\u0152\u0154\u0156\u0158\u015a\u015c\u015e\u0160\u0162\u0164\u0168\u016a\u016c\u016e\u0170\u0172\u0174\u0176\u0178\u0179\u017b\u017d\u01fa\u01fc\u01fe\u0218\u021a\u1e80\u1e82\u1e84\u1ef2\u00dfSFJ\u0391\u0392\u0393\u0394\u0395\u0396\u0397\u0398\u0399\u039a\u039b\u039c\u039d\u039e\u039f\u03a0\u03a1\u03a3\u03a3\u03a4\u03a5\u03a6\u03a7\u03a8\u03a9\u0386\u0388\u0389\u038a\u038c\u038e\u038f\u03aa\u03ab\u03aa\u03ab\u0410\u0411\u0412\u0413\u0414\u0415\u0416\u0417\u0418\u0419\u041a\u041b\u041c\u041d\u041e\u041f\u0420\u0421\u0422\u0423\u0424\u0425\u0426\u0427\u0428\u0429\u042a\u042b\u042c\u042d\u042e\u042f\u0400\u0401\u0402\u0403\u0404\u0405\u0406\u0407\u0408\u0409\u040a\u040b\u040c\u040d\u040e\u040f\u0474\u0490abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012f\u0131\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ac\u03ad\u03ae\u03af\u03cc\u03cd\u03ce\u03ca\u03cb\u0390\u03b0\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f\u0450\u0451\u0452\u0453\u0454\u0455\u0456\u0457\u0458\u0459\u045a\u045b\u045c\u045d\u045e\u045f\u0475\u04910123456789" public static final String LETTERS_LOWER -"abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012fi\u0307\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ac\u03ad\u03ae\u03af\u03cc\u03cd\u03ce\u03ca\u03cb\u0390\u03b0\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f\u0450\u0451\u0452\u0453\u0454\u0455\u0456\u0457\u0458\u0459\u045a\u045b\u045c\u045d\u045e\u045f\u0475\u0491" +"abcdefghijklmnopqrstuvwxyz\u00e0\u00e1\u00e2\u00e3\u00e4\u00e5\u00e6\u00e7\u00e8\u00e9\u00ea\u00eb\u00ec\u00ed\u00ee\u00ef\u00f0\u00f1\u00f2\u00f3\u00f4\u00f5\u00f6\u00f8\u00f9\u00fa\u00fb\u00fc\u00fd\u00fe\u0101\u0103\u0105\u0107\u0109\u010b\u010d\u010f\u0111\u0113\u0115\u0117\u0119\u011b\u011d\u011f\u0121\u0123\u0125\u0127\u0129\u012b\u012d\u012f\u0131\u0135\u0137\u013a\u013c\u013e\u0140\u0142\u0144\u0146\u0148\u014b\u014d\u014f\u0151\u0153\u0155\u0157\u0159\u015b\u015d\u015f\u0161\u0163\u0165\u0169\u016b\u016d\u016f\u0171\u0173\u0175\u0177\u00ff\u017a\u017c\u017e\u01fb\u01fd\u01ff\u0219\u021b\u1e81\u1e83\u1e85\u1ef3\u00df\u017f\u0192\u0237\u03b1\u03b2\u03b3\u03b4\u03b5\u03b6\u03b7\u03b8\u03b9\u03ba\u03bb\u03bc\u03bd\u03be\u03bf\u03c0\u03c1\u03c2\u03c3\u03c4\u03c5\u03c6\u03c7\u03c8\u03c9\u03ac\u03ad\u03ae\u03af\u03cc\u03cd\u03ce\u03ca\u03cb\u0390\u03b0\u0430\u0431\u0432\u0433\u0434\u0435\u0436\u0437\u0438\u0439\u043a\u043b\u043c\u043d\u043e\u043f\u0440\u0441\u0442\u0443\u0444\u0445\u0446\u0447\u0448\u0449\u044a\u044b\u044c\u044d\u044e\u044f\u0450\u0451\u0452\u0453\u0454\u0455\u0456\u0457\u0458\u0459\u045a\u045b\u045c\u045d\u045e\u045f\u0475\u0491" diff --git a/docs/squidlib-util/index-files/index-13.html b/docs/squidlib-util/index-files/index-13.html index ebe82f0c81..dad35ae188 100644 --- a/docs/squidlib-util/index-files/index-13.html +++ b/docs/squidlib-util/index-files/index-13.html @@ -723,7 +723,7 @@

    L

    Identical to Double.longBitsToDouble(long) on desktop; optimized on GWT.
    -
    longFloor(float) - Static method in class squidpony.squidmath.MeadNoise
    +
    longFloor(double) - Static method in class squidpony.squidmath.MeadNoise
    Like Math.floor(double), but returns an int.
    @@ -845,6 +845,10 @@

    L

    The LightRNG used as a RandomnessSource for the RNG this object uses.
    +
    luck - Variable in class squidpony.squidmath.CriticalRNG
    +
    +
    Positive for higher results, negative for lower results; usually this is small, between -0.5f and 0.5f .
    +
    $ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z  diff --git a/docs/squidlib-util/index-files/index-15.html b/docs/squidlib-util/index-files/index-15.html index 75d6119e15..88af3eb94c 100644 --- a/docs/squidlib-util/index-files/index-15.html +++ b/docs/squidlib-util/index-files/index-15.html @@ -401,6 +401,8 @@

    N

    Generates and returns a block of 256 pseudo-random long values.
    +
    nextBoolean() - Method in class squidpony.squidmath.CriticalRNG
    +
     
    nextBoolean() - Method in class squidpony.squidmath.DeckRNG
     
    nextBoolean() - Method in class squidpony.squidmath.DharmaRNG
    @@ -495,6 +497,10 @@

    N

    Generate a random vector.
    +
    nextDouble() - Method in class squidpony.squidmath.CriticalRNG
    +
     
    +
    nextDouble(double) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    nextDouble() - Method in class squidpony.squidmath.DeckRNG
    Generate a random double, altering the result if recently generated results have been leaning @@ -597,6 +603,8 @@

    N

     
    nextDouble() - Method in class squidpony.squidmath.XorRNG
     
    +
    nextFloat() - Method in class squidpony.squidmath.CriticalRNG
    +
     
    nextFloat() - Method in class squidpony.squidmath.DeckRNG
     
    nextFloat() - Method in class squidpony.squidmath.DharmaRNG
    @@ -642,6 +650,8 @@

    N

     
    nextFloat() - Method in class squidpony.squidmath.XorRNG
     
    +
    nextGaussian() - Method in class squidpony.squidmath.CriticalRNG
    +
     
    nextGaussian() - Method in class squidpony.squidmath.DeckRNG
     
    nextGaussian() - Method in class squidpony.squidmath.DharmaRNG
    @@ -658,6 +668,10 @@

    N

     
    nextInt() - Method in class squidpony.squidmath.BirdRNG
     
    +
    nextInt(int) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    +
    nextInt() - Method in class squidpony.squidmath.CriticalRNG
    +
     
    nextInt(int) - Method in class squidpony.squidmath.DeckRNG
    Returns a random integer below the given bound, or 0 if the bound is 0 or @@ -826,6 +840,8 @@

    N

    Gets a pseudo-random int, which can be positive or negative but is likely to be drawn from less possible options than the full range of Integer.MIN_VALUE to Integer.MAX_VALUE.
    +
    nextIntHasty(int) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    nextIntHasty(int) - Method in class squidpony.squidmath.DeckRNG
    Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
    @@ -860,6 +876,10 @@

    N

    Can return any long, positive or negative, of any size permissible in a 64-bit signed integer.
    +
    nextLong() - Method in class squidpony.squidmath.CriticalRNG
    +
     
    +
    nextLong(long) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    nextLong() - Method in class squidpony.squidmath.DeckRNG
    Returns a random long, which may be positive or negative.
    @@ -1099,8 +1119,6 @@

    N

     
    noise(double, double, int) - Static method in class squidpony.squidmath.MeadNoise
     
    -
    noise(float, float, int) - Static method in class squidpony.squidmath.MeadNoise
    -
     
    noise(double, double, double, int) - Static method in class squidpony.squidmath.MeadNoise
     
    noise(float, float, float, int) - Static method in class squidpony.squidmath.MeadNoise
    diff --git a/docs/squidlib-util/index-files/index-18.html b/docs/squidlib-util/index-files/index-18.html index af4732ac0b..c893439fb8 100644 --- a/docs/squidlib-util/index-files/index-18.html +++ b/docs/squidlib-util/index-files/index-18.html @@ -106,6 +106,8 @@

    Q

     
    querp(float, float, float) - Static method in class squidpony.squidmath.MeadNoise
     
    +
    querp(double, double, double) - Static method in class squidpony.squidmath.MeadNoise
    +
     
    querp(double, double, double) - Static method in class squidpony.squidmath.TabbyNoise
     
    queryCache(int, int, int, int, int) - Method in class squidpony.squidgrid.FOVCache
    diff --git a/docs/squidlib-util/index-files/index-19.html b/docs/squidlib-util/index-files/index-19.html index 15c1522f34..1554ab4545 100644 --- a/docs/squidlib-util/index-files/index-19.html +++ b/docs/squidlib-util/index-files/index-19.html @@ -368,14 +368,6 @@

    R

    Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
    -
    randomOrdering(int) - Method in class squidpony.squidmath.DharmaRNG
    -
    -
    Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
    -
    -
    randomOrdering(int) - Method in class squidpony.squidmath.EditRNG
    -
    -
    Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
    -
    randomOrdering(int) - Method in class squidpony.squidmath.RNG
    Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
    @@ -452,12 +444,6 @@

    R

    randomRegion(RNG, int) - Method in class squidpony.squidmath.GreasedRegion
     
    -
    randomRotation(List<T>) - Method in class squidpony.squidmath.DeckRNG
    -
     
    -
    randomRotation(List<T>) - Method in class squidpony.squidmath.DharmaRNG
    -
     
    -
    randomRotation(List<T>) - Method in class squidpony.squidmath.EditRNG
    -
     
    randomRotation(List<T>) - Method in class squidpony.squidmath.RNG
    Given a List l, this selects a random element of l to be the first value in the returned list l2.
    @@ -1978,7 +1964,7 @@

    R

    Seeded constructor; uses LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, tiny state size, and excellent 64-bit number generation.
    -
    RNG(String) - Constructor for class squidpony.squidmath.RNG
    +
    RNG(CharSequence) - Constructor for class squidpony.squidmath.RNG
    String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, diff --git a/docs/squidlib-util/index-files/index-2.html b/docs/squidlib-util/index-files/index-2.html index 934ef9dc49..8dc34e5255 100644 --- a/docs/squidlib-util/index-files/index-2.html +++ b/docs/squidlib-util/index-files/index-2.html @@ -584,6 +584,11 @@

    A

    Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for an alien species.
    +
    ALIEN_U - Static variable in class squidpony.FakeLanguageGen
    +
    +
    Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for + an alien species.
    +
    ALL - Static variable in class squidpony.squidgrid.mapping.SectionDungeonGenerator
    Constant for features being added to all environment types.
    @@ -1118,10 +1123,6 @@

    A

    asRandom() - Method in class squidpony.squidmath.DeckRNG
     
    -
    asRandom() - Method in class squidpony.squidmath.DharmaRNG
    -
     
    -
    asRandom() - Method in class squidpony.squidmath.EditRNG
    -
     
    asRandom() - Method in class squidpony.squidmath.RNG
     
    AStarSearch - Class in squidpony.squidmath
    diff --git a/docs/squidlib-util/index-files/index-20.html b/docs/squidlib-util/index-files/index-20.html index d03fe4eb15..710a199d3a 100644 --- a/docs/squidlib-util/index-files/index-20.html +++ b/docs/squidlib-util/index-files/index-20.html @@ -1420,22 +1420,6 @@

    S

    shuffle(Collection<T>) - Method in class squidpony.squidmath.DeckRNG
     
    -
    shuffle(T[], T[]) - Method in class squidpony.squidmath.DharmaRNG
    -
     
    -
    shuffle(Collection<T>) - Method in class squidpony.squidmath.DharmaRNG
    -
     
    -
    shuffle(T[]) - Method in class squidpony.squidmath.DharmaRNG
    -
    -
    Shuffle an array using the Fisher-Yates algorithm.
    -
    -
    shuffle(T[], T[]) - Method in class squidpony.squidmath.EditRNG
    -
     
    -
    shuffle(Collection<T>) - Method in class squidpony.squidmath.EditRNG
    -
     
    -
    shuffle(T[]) - Method in class squidpony.squidmath.EditRNG
    -
    -
    Shuffle an array using the Fisher-Yates algorithm.
    -
    shuffle(RNG) - Method in class squidpony.squidmath.IntVLA
    Shuffles this IntVLA in place using the given RNG.
    @@ -2324,7 +2308,7 @@

    S

    Seeded constructor uses LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size.
    -
    StatefulRNG(String) - Constructor for class squidpony.squidmath.StatefulRNG
    +
    StatefulRNG(CharSequence) - Constructor for class squidpony.squidmath.StatefulRNG
    String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size.
    diff --git a/docs/squidlib-util/index-files/index-4.html b/docs/squidlib-util/index-files/index-4.html index ceb1c820b3..140d997688 100644 --- a/docs/squidlib-util/index-files/index-4.html +++ b/docs/squidlib-util/index-files/index-4.html @@ -1773,6 +1773,44 @@

    C

    Creates a pip that falls within the required distance from the current distribution.
    +
    CriticalRNG - Class in squidpony.squidmath
    +
    +
    A type of RNG that can generate values larger or smaller than the normal maximum or minimum, based on a modifier.
    +
    +
    CriticalRNG() - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with a luck factor of 0 and a randomly-seeded ThrustRNG for its RandomnessSource.
    +
    +
    CriticalRNG(long) - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource.
    +
    +
    CriticalRNG(CharSequence) - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource (this + will hash seedString using CrossHash.hash64(CharSequence) and use the result to seed the ThrustRNG).
    +
    +
    CriticalRNG(RandomnessSource) - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource.
    +
    +
    CriticalRNG(float) - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with the given luck factor and a randomly-seeded ThrustRNG for its RandomnessSource.
    +
    +
    CriticalRNG(long, float) - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with the given luck factor and a ThrustRNG with the given seed for its RandomnessSource.
    +
    +
    CriticalRNG(CharSequence, float) - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource (this + will hash seedString using CrossHash.hash64(CharSequence) and use the result to seed the ThrustRNG).
    +
    +
    CriticalRNG(RandomnessSource, float) - Constructor for class squidpony.squidmath.CriticalRNG
    +
    +
    Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource.
    +
    crossConnect(int, int, Map<Coord, List<Coord>>) - Static method in class squidpony.squidgrid.mapping.SymmetryDungeonGenerator
     
    CrossHash - Class in squidpony.squidmath
    diff --git a/docs/squidlib-util/index-files/index-5.html b/docs/squidlib-util/index-files/index-5.html index 03435d951c..7f358376be 100644 --- a/docs/squidlib-util/index-files/index-5.html +++ b/docs/squidlib-util/index-files/index-5.html @@ -153,7 +153,7 @@

    D

    Construct a new DeckRNG with the given seed.
    -
    DeckRNG(String) - Constructor for class squidpony.squidmath.DeckRNG
    +
    DeckRNG(CharSequence) - Constructor for class squidpony.squidmath.DeckRNG
    String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size.
    @@ -653,7 +653,7 @@

    D

    Construct a new DharmaRNG with the given seed.
    -
    DharmaRNG(String) - Constructor for class squidpony.squidmath.DharmaRNG
    +
    DharmaRNG(CharSequence) - Constructor for class squidpony.squidmath.DharmaRNG
    String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, diff --git a/docs/squidlib-util/index-files/index-6.html b/docs/squidlib-util/index-files/index-6.html index 85e3ad62d8..8a65e84c77 100644 --- a/docs/squidlib-util/index-files/index-6.html +++ b/docs/squidlib-util/index-files/index-6.html @@ -114,7 +114,7 @@

    E

    Construct a new EditRNG with the given seed.
    -
    EditRNG(String) - Constructor for class squidpony.squidmath.EditRNG
    +
    EditRNG(CharSequence) - Constructor for class squidpony.squidmath.EditRNG
    Construct a new EditRNG with the given seed.
    diff --git a/docs/squidlib-util/index-files/index-8.html b/docs/squidlib-util/index-files/index-8.html index 1c59c5c8df..7d5415d18c 100644 --- a/docs/squidlib-util/index-files/index-8.html +++ b/docs/squidlib-util/index-files/index-8.html @@ -1745,6 +1745,14 @@

    G

    Gets a single random Coord from this using the given RNG (which can be seeded); returns null if this is empty.
    +
    getRandomElement(T[]) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    +
    getRandomElement(List<T>) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    +
    getRandomElement(ShortSet) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    +
    getRandomElement(Collection<T>) - Method in class squidpony.squidmath.CriticalRNG
    +
     
    getRandomElement(T[]) - Method in class squidpony.squidmath.DeckRNG
    Returns a random element from the provided array and maintains object @@ -1831,12 +1839,6 @@

    G

     
    getRandomness() - Method in class squidpony.squidmath.RNG
     
    -
    getRandomStartIterable(List<T>) - Method in class squidpony.squidmath.DeckRNG
    -
     
    -
    getRandomStartIterable(List<T>) - Method in class squidpony.squidmath.DharmaRNG
    -
     
    -
    getRandomStartIterable(List<T>) - Method in class squidpony.squidmath.EditRNG
    -
     
    getRandomStartIterable(List<T>) - Method in class squidpony.squidmath.RNG
    Get an Iterable that starts at a random location in list and continues on through list in its current order.
    diff --git a/docs/squidlib-util/overview-tree.html b/docs/squidlib-util/overview-tree.html index 1b54873b7c..f947cff5cf 100644 --- a/docs/squidlib-util/overview-tree.html +++ b/docs/squidlib-util/overview-tree.html @@ -361,6 +361,7 @@

    Class Hierarchy

  • squidpony.tileset.Ref2CornerCaves
  • squidpony.squidmath.RNG (implements java.io.Serializable)
      +
    • squidpony.squidmath.CriticalRNG
    • squidpony.squidmath.DharmaRNG (implements java.io.Serializable)
    • squidpony.squidmath.StatefulRNG
        diff --git a/docs/squidlib-util/serialized-form.html b/docs/squidlib-util/serialized-form.html index 8fc659233b..7d17cb51f5 100644 --- a/docs/squidlib-util/serialized-form.html +++ b/docs/squidlib-util/serialized-form.html @@ -1793,6 +1793,23 @@

        connections

    • +
    • + + +

      Class squidpony.squidmath.CriticalRNG extends RNG implements Serializable

      +
        +
      • +

        Serialized Fields

        +
          +
        • +

          luck

          +
          float luck
          +
          Positive for higher results, negative for lower results; usually this is small, between -0.5f and 0.5f .
          +
        • +
        +
      • +
      +
    • diff --git a/docs/squidlib-util/squidpony/FakeLanguageGen.Alteration.html b/docs/squidlib-util/squidpony/FakeLanguageGen.Alteration.html index 797e81de75..9b5c05691e 100644 --- a/docs/squidlib-util/squidpony/FakeLanguageGen.Alteration.html +++ b/docs/squidlib-util/squidpony/FakeLanguageGen.Alteration.html @@ -117,7 +117,7 @@

      Class FakeLanguageGen

      -
      public static class FakeLanguageGen.Alteration
      +
      public static class FakeLanguageGen.Alteration
       extends Object
       implements Serializable
      @@ -248,7 +248,7 @@

      Field Detail

      • replacer

        -
        public regexodus.Replacer replacer
        +
        public regexodus.Replacer replacer
      @@ -257,7 +257,7 @@

      replacer

      @@ -266,7 +266,7 @@

      replacement

    • @@ -283,7 +283,7 @@

      Constructor Detail

      @@ -292,7 +292,7 @@

      Alteration

      @@ -302,7 +302,7 @@

      Alteration

      • Alteration

        -
        public Alteration(String pattern,
        +
        public Alteration(String pattern,
                           String replacement,
                           double chance)
      • @@ -313,7 +313,7 @@

        Alteration

        • Alteration

          -
          public Alteration(regexodus.Pattern pattern,
          +
          public Alteration(regexodus.Pattern pattern,
                             String replacement,
                             double chance)
        • @@ -332,7 +332,7 @@

          Method Detail

          • equals

            -
            public boolean equals(Object o)
            +
            public boolean equals(Object o)
            Overrides:
            equals in class Object
            @@ -345,7 +345,7 @@

            equals

            • hashCode

              -
              public int hashCode()
              +
              public int hashCode()
              Overrides:
              hashCode in class Object
              @@ -358,7 +358,7 @@

              hashCode



              -
              public static class FakeLanguageGen.Modifier
              +
              public static class FakeLanguageGen.Modifier
               extends Object
               implements Serializable
              @@ -386,7 +386,7 @@

              Field Detail

              @@ -395,7 +395,7 @@

              alterations

              @@ -405,7 +405,7 @@

              LISP

              @@ -415,7 +415,7 @@

              HISS

              @@ -425,7 +425,7 @@

              STUTTER

              Deprecated. This Modifier doesn't do anything, and isn't needed.
              This was used in an earlier version, which attempted to use a Romanization technique that would use Greek letters and several accented Latin letters to try to accurately represent some of the complex orthography of @@ -513,7 +513,7 @@

              Constructor Detail

              @@ -522,7 +522,7 @@

              Modifier

              @@ -532,7 +532,7 @@

              Modifier

              • Modifier

                -
                public Modifier(String pattern,
                +
                public Modifier(String pattern,
                                 String replacement,
                                 double chance)
              • @@ -543,7 +543,7 @@

                Modifier

                @@ -560,7 +560,7 @@

                Method Detail

                @@ -570,7 +570,7 @@

                modify

                • charReplacementTable

                  -
                  public static FakeLanguageGen.Modifier charReplacementTable(String initial,
                  +
                  public static FakeLanguageGen.Modifier charReplacementTable(String initial,
                                                                               String change)
                  Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and change to be the same length, but will use the lesser length if they are not equal-length. Because of the @@ -590,7 +590,7 @@

                  charReplacementTable

                  • replacementTable

                    -
                    public static FakeLanguageGen.Modifier replacementTable(OrderedMap<String,String> map)
                    +
                    public static FakeLanguageGen.Modifier replacementTable(OrderedMap<String,String> map)
                    Creates a Modifier that will replace the nth String key in map with the nth value. Because of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, @@ -613,7 +613,7 @@

                    replacementTable

                    • replacementTable

                      -
                      public static FakeLanguageGen.Modifier replacementTable(String... pairs)
                      +
                      public static FakeLanguageGen.Modifier replacementTable(String... pairs)
                      Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. This overload of replacementTable allows full regex syntax for search and replacement Strings, @@ -636,7 +636,7 @@

                      replacementTable

                      • insertVowel

                        -
                        public static FakeLanguageGen.Modifier insertVowel(String insertion,
                        +
                        public static FakeLanguageGen.Modifier insertVowel(String insertion,
                                                                            double chance)
                        Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel @@ -657,7 +657,7 @@

                        insertVowel

                        • insertConsonant

                          -
                          public static FakeLanguageGen.Modifier insertConsonant(String insertion,
                          +
                          public static FakeLanguageGen.Modifier insertConsonant(String insertion,
                                                                                  double chance)
                          Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant (at any point in a word that had @@ -678,7 +678,7 @@

                          insertConsonant

                          • insertOpeningVowel

                            -
                            public static FakeLanguageGen.Modifier insertOpeningVowel(String insertion,
                            +
                            public static FakeLanguageGen.Modifier insertOpeningVowel(String insertion,
                                                                                       double chance)
                            Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel at the start of a word with a probability of @@ -700,7 +700,7 @@

                            insertOpeningVowel

                            • insertOpeningConsonant

                              -
                              public static FakeLanguageGen.Modifier insertOpeningConsonant(String insertion,
                              +
                              public static FakeLanguageGen.Modifier insertOpeningConsonant(String insertion,
                                                                                             double chance)
                              Adds the potential for the String insertion to be used as a consonant in addition to the consonants that the language already uses; insertion will replace an existing consonant at the start of a word with a @@ -722,7 +722,7 @@

                              insertOpeningConsonant

                              • insertClosingVowel

                                -
                                public static FakeLanguageGen.Modifier insertClosingVowel(String insertion,
                                +
                                public static FakeLanguageGen.Modifier insertClosingVowel(String insertion,
                                                                                           double chance)
                                Adds the potential for the String insertion to be used as a vowel in addition to the vowels that the language already uses; insertion will replace an existing vowel at the end of a word with a probability of @@ -744,7 +744,7 @@

                                insertClosingVowel

                                + + + +
                                  +
                                • +

                                  ALIEN_U

                                  +
                                  public static final FakeLanguageGen ALIEN_U
                                  +
                                  Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for + an alien species. This alien language is meant to have an abrupt change mid-word for many words, with the suffix + of roughly half of words using the letter "e", which is absent from the rest of the language; these suffixes can + also use consonant clusters, which are similarly absent elsewhere. The suffixes would make sense as a historical + relic or as a linguistic holdout from a historical merger. As the name would suggest, it strongly prefers + using the vowel "u", with it present in about half the groups, and can use the umlaut accent "ü" on some vowels. + The consonants completely avoid hard sounds like "t" and "k", and don't cluster; they often have special marks. + This should be relatively easy to pronounce for an alien language, though the words are rather long. +
                                  + Üweħid vuŕeħid deẃul leŋul waloyeyür; äyovavü...
                                  +
                                • +
                                • registered

                                  -
                                  public static final FakeLanguageGen[] registered
                                  +
                                  public static final FakeLanguageGen[] registered
                                  An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric codes for languages in the serializeToString() output, but neither is dependent on the other if this @@ -1554,7 +1580,7 @@

                                  Constructor Detail

                                  • FakeLanguageGen

                                    -
                                    public FakeLanguageGen()
                                    +
                                    public FakeLanguageGen()
                                    Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH .
                                  @@ -1564,7 +1590,7 @@

                                  FakeLanguageGen

                                  • FakeLanguageGen

                                    -
                                    public FakeLanguageGen(String[] openingVowels,
                                    +
                                    public FakeLanguageGen(String[] openingVowels,
                                                            String[] midVowels,
                                                            String[] openingConsonants,
                                                            String[] midConsonants,
                                    @@ -1619,7 +1645,7 @@ 

                                    FakeLanguageGen

                                    • FakeLanguageGen

                                      -
                                      public FakeLanguageGen(String[] openingVowels,
                                      +
                                      public FakeLanguageGen(String[] openingVowels,
                                                              String[] midVowels,
                                                              String[] openingConsonants,
                                                              String[] midConsonants,
                                      @@ -1705,7 +1731,7 @@ 

                                      removeAccents

                                      @@ -1714,7 +1740,7 @@

                                      randomLanguage

                                      @@ -1723,7 +1749,7 @@

                                      randomLanguage

                                      @@ -1733,7 +1759,7 @@

                                      checkAll

                                      • checkVulgarity

                                        -
                                        public static boolean checkVulgarity(CharSequence testing)
                                        +
                                        public static boolean checkVulgarity(CharSequence testing)
                                        Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers @@ -1752,7 +1778,7 @@

                                        checkVulgarity

                                        • word

                                          -
                                          public String word(boolean capitalize)
                                          +
                                          public String word(boolean capitalize)
                                          Generate a word from this FakeLanguageGen, using and changing the current seed.
                                          Parameters:
                                          @@ -1768,7 +1794,7 @@

                                          word

                                          • word

                                            -
                                            public String word(RNG rng,
                                            +
                                            public String word(RNG rng,
                                                                boolean capitalize)
                                            Generate a word from this FakeLanguageGen using the specified RNG.
                                            @@ -1786,7 +1812,7 @@

                                            word

                                            • word

                                              -
                                              public String word(RNG rng,
                                              +
                                              public String word(RNG rng,
                                                                  boolean capitalize,
                                                                  int approxSyllables)
                                              Generate a word from this FakeLanguageGen using the specified RNG.
                                              @@ -1805,7 +1831,7 @@

                                              word

                                              • word

                                                -
                                                public String word(RNG rng,
                                                +
                                                public String word(RNG rng,
                                                                    boolean capitalize,
                                                                    int approxSyllables,
                                                                    regexodus.Pattern[] additionalChecks)
                                                @@ -1825,7 +1851,7 @@

                                                word

                                                • word

                                                  -
                                                  public String word(StatefulRNG rng,
                                                  +
                                                  public String word(StatefulRNG rng,
                                                                      boolean capitalize,
                                                                      int approxSyllables,
                                                                      long... reseeds)
                                                  @@ -1845,7 +1871,7 @@

                                                  word

                                                  • sentence

                                                    -
                                                    public String sentence(int minWords,
                                                    +
                                                    public String sentence(int minWords,
                                                                            int maxWords)
                                                    Generate a sentence from this FakeLanguageGen, using and changing the current seed.
                                                    @@ -1863,7 +1889,7 @@

                                                    sentence

                                                    • sentence

                                                      -
                                                      public String sentence(RNG rng,
                                                      +
                                                      public String sentence(RNG rng,
                                                                              int minWords,
                                                                              int maxWords)
                                                      Generate a sentence from this FakeLanguageGen, using and changing the current seed.
                                                      @@ -1882,7 +1908,7 @@

                                                      sentence

                                                      • sentence

                                                        -
                                                        public String sentence(int minWords,
                                                        +
                                                        public String sentence(int minWords,
                                                                                int maxWords,
                                                                                String[] midPunctuation,
                                                                                String[] endPunctuation,
                                                        @@ -1909,7 +1935,7 @@ 

                                                        sentence

                                                        • sentence

                                                          -
                                                          public String sentence(RNG rng,
                                                          +
                                                          public String sentence(RNG rng,
                                                                                  int minWords,
                                                                                  int maxWords,
                                                                                  String[] midPunctuation,
                                                          @@ -1938,7 +1964,7 @@ 

                                                          sentence

                                                          • sentence

                                                            -
                                                            public String sentence(int minWords,
                                                            +
                                                            public String sentence(int minWords,
                                                                                    int maxWords,
                                                                                    String[] midPunctuation,
                                                                                    String[] endPunctuation,
                                                            @@ -1967,7 +1993,7 @@ 

                                                            sentence

                                                            • sentence

                                                              -
                                                              public String sentence(RNG rng,
                                                              +
                                                              public String sentence(RNG rng,
                                                                                      int minWords,
                                                                                      int maxWords,
                                                                                      String[] midPunctuation,
                                                              @@ -1998,7 +2024,7 @@ 

                                                              sentence

                                                              • merge1000

                                                                -
                                                                protected String[] merge1000(RNG rng,
                                                                +
                                                                protected String[] merge1000(RNG rng,
                                                                                              String[] me,
                                                                                              String[] other,
                                                                                              double otherInfluence)
                                                                @@ -2010,7 +2036,7 @@

                                                                merge1000

                                                                • accentVowels

                                                                  -
                                                                  protected String[] accentVowels(RNG rng,
                                                                  +
                                                                  protected String[] accentVowels(RNG rng,
                                                                                                   String[] me,
                                                                                                   double influence)
                                                                • @@ -2021,7 +2047,7 @@

                                                                  accentVowels

                                                                  • accentConsonants

                                                                    -
                                                                    protected String[] accentConsonants(RNG rng,
                                                                    +
                                                                    protected String[] accentConsonants(RNG rng,
                                                                                                         String[] me,
                                                                                                         double influence)
                                                                  • @@ -2032,7 +2058,7 @@

                                                                    accentConsonants

                                                                    • accentBoth

                                                                      -
                                                                      protected String[] accentBoth(RNG rng,
                                                                      +
                                                                      protected String[] accentBoth(RNG rng,
                                                                                                     String[] me,
                                                                                                     double vowelInfluence,
                                                                                                     double consonantInfluence)
                                                                      @@ -2044,7 +2070,7 @@

                                                                      accentBoth

                                                                      @@ -2054,7 +2080,7 @@

                                                                      mix

                                                                      • mix

                                                                        -
                                                                        public FakeLanguageGen mix(double myWeight,
                                                                        +
                                                                        public FakeLanguageGen mix(double myWeight,
                                                                                                    FakeLanguageGen other1,
                                                                                                    double weight1,
                                                                                                    Object... pairs)
                                                                        @@ -2094,7 +2120,7 @@

                                                                        mix

                                                                        • mixAll

                                                                          -
                                                                          public static FakeLanguageGen mixAll(Object... pairs)
                                                                          +
                                                                          public static FakeLanguageGen mixAll(Object... pairs)
                                                                          Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double @@ -2122,7 +2148,7 @@

                                                                          mixAll

                                                                          @@ -2132,7 +2158,7 @@

                                                                          addAccents

                                                                          @@ -2141,7 +2167,7 @@

                                                                          removeAccents

                                                                          - -<T> List<T> -RNG.randomRotation(List<T> l) -
                                                                          Given a List l, this selects a random element of l to be the first value in the returned list l2.
                                                                          - - - -<T> List<T> -EditRNG.randomRotation(List<T> l)  - - -<T> List<T> -DharmaRNG.randomRotation(List<T> l)  - - -<T> List<T> -DeckRNG.randomRotation(List<T> l)  - - -<T> T[] -EditRNG.shuffle(T[] elements) -
                                                                          Shuffle an array using the Fisher-Yates algorithm.
                                                                          - - - -<T> T[] -DharmaRNG.shuffle(T[] elements) -
                                                                          Shuffle an array using the Fisher-Yates algorithm.
                                                                          - - - -<T> T[] -DeckRNG.shuffle(T[] elements) -
                                                                          Shuffle an array using the Fisher-Yates algorithm.
                                                                          - - diff --git a/docs/squidlib-util/squidpony/class-use/FakeLanguageGen.html b/docs/squidlib-util/squidpony/class-use/FakeLanguageGen.html index f1bd3047ec..0937a3e500 100644 --- a/docs/squidlib-util/squidpony/class-use/FakeLanguageGen.html +++ b/docs/squidlib-util/squidpony/class-use/FakeLanguageGen.html @@ -140,30 +140,37 @@

                                                                          Uses of

                                                                          + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - -
                                                                          static FakeLanguageGenFakeLanguageGen.ALIEN_U +
                                                                          Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for + an alien species.
                                                                          +
                                                                          static FakeLanguageGen FakeLanguageGen.ARABIC_ROMANIZED
                                                                          Imitation Arabic, using mostly the Latin alphabet but with some Greek letters for tough transliteration topics.
                                                                          static FakeLanguageGen FakeLanguageGen.DEMONIC
                                                                          Fantasy language that might be suitable for a language spoken by demons, aggressive warriors, or people who seek to emulate or worship similar groups.
                                                                          static FakeLanguageGen FakeLanguageGen.ELF
                                                                          Fantasy language that tries to imitate the various languages spoken by elves in J.R.R.
                                                                          static FakeLanguageGen FakeLanguageGen.ENGLISH
                                                                          Imitation English; may seem closer to Dutch in some generated text, and is not exactly the best imitation.
                                                                          static FakeLanguageGen FakeLanguageGen.FANCY_FANTASY_NAME
                                                                          A mix of four different languages with some accented characters added onto an ASCII base, that can be good for @@ -171,134 +178,134 @@

                                                                          Uses of +

                                                                          static FakeLanguageGen FakeLanguageGen.FANTASY_NAME
                                                                          A mix of four different languages, using only ASCII characters, that is meant for generating single words for creature or place names in fantasy settings.
                                                                          static FakeLanguageGen FakeLanguageGen.FRENCH
                                                                          Imitation modern French, using the (many) accented vowels that are present in the language.
                                                                          static FakeLanguageGen FakeLanguageGen.GOBLIN
                                                                          Fantasy language that might be suitable for stealthy humanoids, such as goblins, or as a secret language used by humans who want to avoid notice.
                                                                          static FakeLanguageGen FakeLanguageGen.GREEK_AUTHENTIC
                                                                          Imitation ancient Greek, using the original Greek alphabet.
                                                                          static FakeLanguageGen FakeLanguageGen.GREEK_ROMANIZED
                                                                          Imitation ancient Greek, romanized to use the Latin alphabet.
                                                                          static FakeLanguageGen FakeLanguageGen.HINDI_ROMANIZED
                                                                          Imitation Hindi, romanized to use the Latin alphabet using accented glyphs similar to the IAST standard.
                                                                          static FakeLanguageGen FakeLanguageGen.INFERNAL
                                                                          Fantasy language that might be suitable for a language spoken by fiends, users of witchcraft, or people who seek to emulate or worship similar groups.
                                                                          static FakeLanguageGen FakeLanguageGen.INUKTITUT
                                                                          Imitation text from an approximation of one of the Inuktitut languages spoken by various people of the Arctic and nearby areas.
                                                                          static FakeLanguageGen FakeLanguageGen.JAPANESE_ROMANIZED
                                                                          Imitation Japanese, romanized to use the Latin alphabet.
                                                                          static FakeLanguageGen FakeLanguageGen.KOREAN_ROMANIZED
                                                                          Imitation text from an approximation of Korean, using the Revised Romanization method that is official in South Korea today and is easier to type.
                                                                          FakeLanguageGen NaturalLanguageCipher.language
                                                                          The FakeLanguageGen this will use to construct words; normally one of the static fields in FakeLanguageGen or a FakeLanguageGen produced by using the mix() method of one of them.
                                                                          FakeLanguageGen LanguageCipher.language
                                                                          The FakeLanguageGen this will use to construct words; normally one of the static fields in FakeLanguageGen or a FakeLanguageGen produced by using the mix() method of one of them.
                                                                          FakeLanguageGen FakeLanguageGen.SentenceForm.language 
                                                                          static FakeLanguageGen FakeLanguageGen.LOVECRAFT
                                                                          Ia! Ia! Cthulhu Rl'yeh ftaghn! Useful for generating cultist ramblings or unreadable occult texts.
                                                                          static FakeLanguageGen FakeLanguageGen.MONGOLIAN
                                                                          Imitation text from an approximation of one of the languages spoken in the 13th-century Mongol Empire.
                                                                          static FakeLanguageGen FakeLanguageGen.NAHUATL
                                                                          Imitation text from an approximation of the language spoken by the Aztec people and also over a million contemporary people in parts of Mexico.
                                                                          static FakeLanguageGen FakeLanguageGen.NORSE
                                                                          Somewhat close to Old Norse, which is itself very close to Icelandic, so this uses Icelandic spelling rules.
                                                                          static FakeLanguageGen[] FakeLanguageGen.registered
                                                                          An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages nor does it store modifications or mixes of languages.
                                                                          static FakeLanguageGen FakeLanguageGen.RUSSIAN_AUTHENTIC
                                                                          Imitation modern Russian, using the authentic Cyrillic alphabet used in Russia and other countries.
                                                                          static FakeLanguageGen FakeLanguageGen.RUSSIAN_ROMANIZED
                                                                          Imitation modern Russian, romanized to use the Latin alphabet.
                                                                          static FakeLanguageGen FakeLanguageGen.SIMPLISH
                                                                          English-like language that omits complex spelling and doesn't include any of the uncommon word endings of English @@ -306,13 +313,13 @@

                                                                          Uses of +

                                                                          static FakeLanguageGen FakeLanguageGen.SOMALI
                                                                          Imitation Somali, using the Latin alphabet.
                                                                          static FakeLanguageGen FakeLanguageGen.SWAHILI
                                                                          Swahili is one of the more commonly-spoken languages in sub-Saharan Africa, and serves mainly as a shared language diff --git a/docs/squidlib-util/squidpony/squidmath/CosmicNumbering.html b/docs/squidlib-util/squidpony/squidmath/CosmicNumbering.html index 4678ac2de6..ab36498f57 100644 --- a/docs/squidlib-util/squidpony/squidmath/CosmicNumbering.html +++ b/docs/squidlib-util/squidpony/squidmath/CosmicNumbering.html @@ -50,7 +50,7 @@
                                                                          DeckRNG(long seed) -
                                                                          Construct a new DeckRNG with the given seed.
                                                                          +
                                                                          DeckRNG(CharSequence seedString) +
                                                                          String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low + period (which rarely matters for games), and has good speed and tiny state size.
                                                                          DeckRNG(RandomnessSource random) -
                                                                          Seeds this DeckRNG using the RandomnessSource it is given.
                                                                          +
                                                                          DeckRNG(long seed) +
                                                                          Construct a new DeckRNG with the given seed.
                                                                          DeckRNG(String seedString) -
                                                                          String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low - period (which rarely matters for games), and has good speed and tiny state size.
                                                                          +
                                                                          DeckRNG(RandomnessSource random) +
                                                                          Seeds this DeckRNG using the RandomnessSource it is given.
                                                                          @@ -300,107 +300,101 @@

                                                                          Method Summary

                                                                          getRandomness()  -<T> Iterable<T> -getRandomStartIterable(List<T> list) -
                                                                          Get an Iterable that starts at a random location in list and continues on through list in its current order.
                                                                          - - - long getState()
                                                                          Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                          - + int getStep()  - + int hashCode()  - + int next(int bits)
                                                                          Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                          - + boolean nextBoolean()
                                                                          Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                          - + double nextDouble()
                                                                          Generate a random double, altering the result if recently generated results have been leaning away from this class' fairness value.
                                                                          - + double nextDouble(double max)
                                                                          This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                          - + float nextFloat()
                                                                          This returns a maximum of 0.99999994 because that is the largest Float value that is less than 1.0f
                                                                          - + double nextGaussian()  - + int nextInt()
                                                                          Returns a random integer, which may be positive or negative.
                                                                          - + int nextInt(int bound)
                                                                          Returns a random integer below the given bound, or 0 if the bound is 0 or negative.
                                                                          - + int nextIntHasty(int bound)
                                                                          Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                          - + long nextLong()
                                                                          Returns a random long, which may be positive or negative.
                                                                          - + long nextLong(long bound)
                                                                          Returns a random long below the given bound, or 0 if the bound is 0 or negative.
                                                                          - + int[] randomOrdering(int length)
                                                                          Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                          - + <T> List<T> randomPortion(List<T> data, int count)
                                                                          Gets a random portion of a List and returns it as a new List.
                                                                          - + <T> T[] randomPortion(T[] data, T[] output) @@ -408,7 +402,7 @@

                                                                          Method Summary

                                                                          it can, and then returns output.
                                        - + int[] randomRange(int start, int end, @@ -416,49 +410,43 @@

                                        Method Summary

                                        Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                        - -<T> List<T> -randomRotation(List<T> l) -
                                        Given a List l, this selects a random element of l to be the first value in the returned list l2.
                                        - - - + void setRandomness(RandomnessSource random)
                                        Reseeds this DeckRNG using the RandomnessSource it is given.
                                        - + void setState(long state)
                                        Sets the state of the random number generator to a given long, which will alter future random numbers this produces based on the state.
                                        - + void setStep(int step)  - + <T> ArrayList<T> shuffle(Collection<T> elements)
                                        Shuffles a Collection of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                        - + <T> T[] shuffle(T[] elements)
                                        Shuffle an array using the Fisher-Yates algorithm.
                                        - + <T> T[] shuffle(T[] elements, T[] dest)
                                        Shuffle an array using the Fisher-Yates algorithm.
                                        - + String toString()  @@ -468,7 +456,7 @@

                                        Method Summary

                                        Methods inherited from class squidpony.squidmath.RNG

                                        -approximateBits, getRandomCellsIterable, getRandomUniqueCells, getRandomUniqueCells, getRandomUniqueCells, nextBytes, nextCoord, randomInterleave, randomOrdering, shuffle, shuffleInPlace
                                      • +approximateBits, getRandomCellsIterable, getRandomStartIterable, getRandomUniqueCells, getRandomUniqueCells, getRandomUniqueCells, nextBytes, nextCoord, randomInterleave, randomOrdering, randomRotation, shuffle, shuffleInPlace
                                      • @@ -497,7 +485,7 @@

                                        Constructor Detail

                                        @@ -507,7 +495,7 @@

                                        DeckRNG

                                        • DeckRNG

                                          -
                                          public DeckRNG(long seed)
                                          +
                                          public DeckRNG(long seed)
                                          Construct a new DeckRNG with the given seed.
                                          Parameters:
                                          @@ -515,13 +503,13 @@

                                          DeckRNG

                                        - +
                                        • DeckRNG

                                          -
                                          public DeckRNG(String seedString)
                                          +
                                          public DeckRNG(CharSequence seedString)
                                          String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size.
                                          @@ -536,7 +524,7 @@

                                          DeckRNG

                                          • DeckRNG

                                            -
                                            public DeckRNG(RandomnessSource random)
                                            +
                                            public DeckRNG(RandomnessSource random)
                                            Seeds this DeckRNG using the RandomnessSource it is given. Does not assign the RandomnessSource to any fields that would affect future pseudo-random number generation.
                                            @@ -559,7 +547,7 @@

                                            Method Detail

                                            • nextDouble

                                              -
                                              public double nextDouble()
                                              +
                                              public double nextDouble()
                                              Generate a random double, altering the result if recently generated results have been leaning away from this class' fairness value.
                                              @@ -576,7 +564,7 @@

                                              nextDouble

                                              • nextDouble

                                                -
                                                public double nextDouble(double max)
                                                +
                                                public double nextDouble(double max)
                                                This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                Overrides:
                                                @@ -592,7 +580,7 @@

                                                nextDouble

                                                • between

                                                  -
                                                  public double between(double min,
                                                  +
                                                  public double between(double min,
                                                                         double max)
                                                  Returns a value from a even distribution from min (inclusive) to max (exclusive).
                                                  @@ -613,7 +601,7 @@

                                                  between

                                                  • between

                                                    -
                                                    public int between(int min,
                                                    +
                                                    public int between(int min,
                                                                        int max)
                                                    Returns a value between min (inclusive) and max (exclusive). @@ -636,7 +624,7 @@

                                                    between

                                                    • betweenWeighted

                                                      -
                                                      public int betweenWeighted(int min,
                                                      +
                                                      public int betweenWeighted(int min,
                                                                                  int max,
                                                                                  int samples)
                                                      Returns the average of a number of randomly selected numbers from the @@ -667,7 +655,7 @@

                                                      betweenWeighted

                                                      • getRandomElement

                                                        -
                                                        public <T> T getRandomElement(T[] array)
                                                        +
                                                        public <T> T getRandomElement(T[] array)
                                                        Returns a random element from the provided array and maintains object type.
                                                        @@ -688,7 +676,7 @@

                                                        getRandomElement

                                                        • getRandomElement

                                                          -
                                                          public <T> T getRandomElement(List<T> list)
                                                          +
                                                          public <T> T getRandomElement(List<T> list)
                                                          Returns a random element from the provided list. If the list is empty then null is returned.
                                                          @@ -709,7 +697,7 @@

                                                          getRandomElement

                                                          • getRandomElement

                                                            -
                                                            public short getRandomElement(ShortSet set)
                                                            +
                                                            public short getRandomElement(ShortSet set)
                                                            Returns a random element from the provided ShortSet. If the set is empty then an exception is thrown. @@ -733,7 +721,7 @@

                                                            getRandomElement

                                                            • getRandomElement

                                                              -
                                                              public <T> T getRandomElement(Collection<T> coll)
                                                              +
                                                              public <T> T getRandomElement(Collection<T> coll)
                                                              Returns a random element from the provided Collection, which should have predictable iteration order if you want predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted @@ -764,7 +752,7 @@

                                                              getRandomElement

                                                              • nextGaussian

                                                                -
                                                                public double nextGaussian()
                                                                +
                                                                public double nextGaussian()
                                                                Overrides:
                                                                nextGaussian in class RNG
                                                                @@ -779,7 +767,7 @@

                                                                nextGaussian

                                                                • nextInt

                                                                  -
                                                                  public int nextInt(int bound)
                                                                  +
                                                                  public int nextInt(int bound)
                                                                  Returns a random integer below the given bound, or 0 if the bound is 0 or negative. Affects the current fortune.
                                                                  @@ -800,7 +788,7 @@

                                                                  nextInt

                                                                  • shuffle

                                                                    -
                                                                    public <T> T[] shuffle(T[] elements)
                                                                    +
                                                                    public <T> T[] shuffle(T[] elements)
                                                                    Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays.
                                                                    https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                    @@ -822,7 +810,7 @@

                                                                    shuffle

                                                                    • randomOrdering

                                                                      -
                                                                      public int[] randomOrdering(int length)
                                                                      +
                                                                      public int[] randomOrdering(int length)
                                                                      Generates a random permutation of the range from 0 (inclusive) to length (exclusive). Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                      @@ -841,7 +829,7 @@

                                                                      randomOrdering

                                                                      • nextIntHasty

                                                                        -
                                                                        public int nextIntHasty(int bound)
                                                                        +
                                                                        public int nextIntHasty(int bound)
                                                                        Returns a random non-negative integer below the given bound, or 0 if the bound is 0. Uses a slightly optimized technique. This method is considered "hasty" since it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also @@ -863,7 +851,7 @@

                                                                        nextIntHasty

                                                                        • nextInt

                                                                          -
                                                                          public int nextInt()
                                                                          +
                                                                          public int nextInt()
                                                                          Returns a random integer, which may be positive or negative.
                                                                          Overrides:
                                                                          @@ -879,7 +867,7 @@

                                                                          nextInt

                                                                          • nextLong

                                                                            -
                                                                            public long nextLong()
                                                                            +
                                                                            public long nextLong()
                                                                            Returns a random long, which may be positive or negative.
                                                                            Overrides:
                                                                            @@ -895,7 +883,7 @@

                                                                            nextLong

                                                                            • nextLong

                                                                              -
                                                                              public long nextLong(long bound)
                                                                              +
                                                                              public long nextLong(long bound)
                                                                              Returns a random long below the given bound, or 0 if the bound is 0 or negative.
                                                                              @@ -914,7 +902,7 @@

                                                                              nextLong

                                                                              • next

                                                                                -
                                                                                public int next(int bits)
                                                                                +
                                                                                public int next(int bits)
                                                                                Description copied from class: RNG
                                                                                Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                @@ -933,7 +921,7 @@

                                                                                next

                                                                                - - - -
                                                                                  -
                                                                                • -

                                                                                  randomRotation

                                                                                  -
                                                                                  public <T> List<T> randomRotation(List<T> l)
                                                                                  -
                                                                                  Description copied from class: RNG
                                                                                  -
                                                                                  Given a List l, this selects a random element of l to be the first value in the returned list l2. It - retains the order of elements in l after that random element and makes them follow the first element in l2, and - loops around to use elements from the start of l after it has placed the last element of l into l2. -
                                                                                  - Essentially, it does what it says on the tin. It randomly rotates the List l. -
                                                                                  - If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable() - should have better performance.
                                                                                  -
                                                                                  -
                                                                                  Overrides:
                                                                                  -
                                                                                  randomRotation in class RNG
                                                                                  -
                                                                                  Type Parameters:
                                                                                  -
                                                                                  T - No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                  -
                                                                                  Parameters:
                                                                                  -
                                                                                  l - A List that will not be modified by this method. All elements of this parameter will be - shared with the returned List.
                                                                                  -
                                                                                  Returns:
                                                                                  -
                                                                                  A shallow copy of l that has been rotated so its first element has been randomly chosen - from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last - element of l, then element 1, etc.
                                                                                  -
                                                                                  -
                                                                                • -
                                                                                - - - -
                                                                                  -
                                                                                • -

                                                                                  getRandomStartIterable

                                                                                  -
                                                                                  public <T> Iterable<T> getRandomStartIterable(List<T> list)
                                                                                  -
                                                                                  Description copied from class: RNG
                                                                                  -
                                                                                  Get an Iterable that starts at a random location in list and continues on through list in its current order. - Loops around to the beginning after it gets to the end, stops when it returns to the starting location. -
                                                                                  - You should not modify list while you use the returned reference. And there'll be no - ConcurrentModificationException to detect such erroneous uses.
                                                                                  -
                                                                                  -
                                                                                  Overrides:
                                                                                  -
                                                                                  getRandomStartIterable in class RNG
                                                                                  -
                                                                                  Parameters:
                                                                                  -
                                                                                  list - A list with a constant-time List.get(int) method (otherwise performance degrades).
                                                                                  -
                                                                                  Returns:
                                                                                  -
                                                                                  An Iterable that iterates over list but start at - a random index. If the chosen index is i, the iterator - will return: - list[i]; list[i+1]; ...; list[list.length() - 1]; list[0]; list[i-1]
                                                                                  -
                                                                                  -
                                                                                • -
                                                                                • between

                                                                                  -
                                                                                  public long between(long min,
                                                                                  +
                                                                                  public long between(long min,
                                                                                                       long max)
                                                                                  Returns a value between min (inclusive) and max (exclusive).

                                                                                  @@ -1030,7 +961,7 @@

                                                                                  between

                                                                                  • shuffle

                                                                                    -
                                                                                    public <T> T[] shuffle(T[] elements,
                                                                                    +
                                                                                    public <T> T[] shuffle(T[] elements,
                                                                                                            T[] dest)
                                                                                    Shuffle an array using the Fisher-Yates algorithm.
                                                                                    @@ -1054,7 +985,7 @@

                                                                                    shuffle

                                                                                    • shuffle

                                                                                      -
                                                                                      public <T> ArrayList<T> shuffle(Collection<T> elements)
                                                                                      +
                                                                                      public <T> ArrayList<T> shuffle(Collection<T> elements)
                                                                                      Description copied from class: RNG
                                                                                      Shuffles a Collection of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                      @@ -1075,7 +1006,7 @@

                                                                                      shuffle

                                                                                      • nextFloat

                                                                                        -
                                                                                        public float nextFloat()
                                                                                        +
                                                                                        public float nextFloat()
                                                                                        Description copied from class: RNG
                                                                                        This returns a maximum of 0.99999994 because that is the largest Float value that is less than 1.0f
                                                                                        @@ -1093,7 +1024,7 @@

                                                                                        nextFloat

                                                                                        • nextBoolean

                                                                                          -
                                                                                          public boolean nextBoolean()
                                                                                          +
                                                                                          public boolean nextBoolean()
                                                                                          Description copied from class: RNG
                                                                                          Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                          @@ -1110,7 +1041,7 @@

                                                                                          nextBoolean

                                                                                          • getRandomness

                                                                                            -
                                                                                            public RandomnessSource getRandomness()
                                                                                            +
                                                                                            public RandomnessSource getRandomness()
                                                                                            Overrides:
                                                                                            getRandomness in class RNG
                                                                                            @@ -1123,7 +1054,7 @@

                                                                                            getRandomness

                                                                                            • setRandomness

                                                                                              -
                                                                                              public void setRandomness(RandomnessSource random)
                                                                                              +
                                                                                              public void setRandomness(RandomnessSource random)
                                                                                              Reseeds this DeckRNG using the RandomnessSource it is given. Does not assign the RandomnessSource to any fields that would affect future pseudo-random number generation.
                                                                                              @@ -1140,7 +1071,7 @@

                                                                                              setRandomness

                                                                                              • copy

                                                                                                -
                                                                                                public RNG copy()
                                                                                                +
                                                                                                public RNG copy()
                                                                                                Creates a copy of this DeckRNG; it will generate the same random numbers, given the same calls in order, as this DeckRNG at the point copy() is called. The copy will not share references with this DeckRNG.
                                                                                                @@ -1159,7 +1090,7 @@

                                                                                                copy

                                                                                                • randomPortion

                                                                                                  -
                                                                                                  public <T> T[] randomPortion(T[] data,
                                                                                                  +
                                                                                                  public <T> T[] randomPortion(T[] data,
                                                                                                                                T[] output)
                                                                                                  Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as it can, and then returns output. Will only use a given position in the given data at most once; does this by @@ -1187,7 +1118,7 @@

                                                                                                  randomPortion

                                                                                                  • randomPortion

                                                                                                    -
                                                                                                    public <T> List<T> randomPortion(List<T> data,
                                                                                                    +
                                                                                                    public <T> List<T> randomPortion(List<T> data,
                                                                                                                                      int count)
                                                                                                    Gets a random portion of a List and returns it as a new List. Will only use a given position in the given List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                    @@ -1210,7 +1141,7 @@

                                                                                                    randomPortion

                                                                                                    • randomRange

                                                                                                      -
                                                                                                      public int[] randomRange(int start,
                                                                                                      +
                                                                                                      public int[] randomRange(int start,
                                                                                                                                int end,
                                                                                                                                int count)
                                                                                                      Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements. @@ -1233,7 +1164,7 @@

                                                                                                      randomRange

                                                                                                      • getState

                                                                                                        -
                                                                                                        public long getState()
                                                                                                        +
                                                                                                        public long getState()
                                                                                                        Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                                                        Overrides:
                                                                                                        @@ -1249,7 +1180,7 @@

                                                                                                        getState

                                                                                                        • setState

                                                                                                          -
                                                                                                          public void setState(long state)
                                                                                                          +
                                                                                                          public void setState(long state)
                                                                                                          Sets the state of the random number generator to a given long, which will alter future random numbers this produces based on the state. Setting the state always causes the "deck" of random grades to be shuffled.
                                                                                                          @@ -1266,7 +1197,7 @@

                                                                                                          setState

                                                                                                          • toString

                                                                                                            -
                                                                                                            public String toString()
                                                                                                            +
                                                                                                            public String toString()
                                                                                                            Overrides:
                                                                                                            toString in class StatefulRNG
                                                                                                            @@ -1279,7 +1210,7 @@

                                                                                                            toString

                                                                                                            • equals

                                                                                                              -
                                                                                                              public boolean equals(Object o)
                                                                                                              +
                                                                                                              public boolean equals(Object o)
                                                                                                              Overrides:
                                                                                                              equals in class RNG
                                                                                                              @@ -1292,7 +1223,7 @@

                                                                                                              equals

                                                                                                              • hashCode

                                                                                                                -
                                                                                                                public int hashCode()
                                                                                                                +
                                                                                                                public int hashCode()
                                                                                                                Overrides:
                                                                                                                hashCode in class RNG
                                                                                                                @@ -1305,7 +1236,7 @@

                                                                                                                hashCode

                                                                                                                @@ -1314,7 +1245,7 @@

                                                                                                                getStep

                                                                                                              • diff --git a/docs/squidlib-util/squidpony/squidmath/DharmaRNG.html b/docs/squidlib-util/squidpony/squidmath/DharmaRNG.html index 236d8b7026..539343c52a 100644 --- a/docs/squidlib-util/squidpony/squidmath/DharmaRNG.html +++ b/docs/squidlib-util/squidpony/squidmath/DharmaRNG.html @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10}; +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10}; var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -118,7 +118,7 @@

                                                                                                                Class DharmaRNG



                                                                                                              -
                                                                                                              public class DharmaRNG
                                                                                                              +
                                                                                                              public class DharmaRNG
                                                                                                               extends RNG
                                                                                                               implements Serializable
                                                                                                              An alteration to a RandomnessSource that attempts to produce values that are perceived as fair to an imperfect user. @@ -203,34 +203,34 @@

                                                                                                              Constructor Summary

                                                                                                              +DharmaRNG(CharSequence seedString) +
                                                                                                              String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a + seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, + tiny state size, and excellent 64-bit number generation.
                                                                                                              + + + DharmaRNG(long seed)
                                                                                                              Construct a new DharmaRNG with the given seed.
                                                                                                              - + DharmaRNG(long seed, double fairness)
                                                                                                              Construct a new DharmaRNG with the given seed.
                                                                                                              - + DharmaRNG(RandomnessSource rs)
                                                                                                              Construct a new DharmaRNG with the given seed.
                                                                                                              - + DharmaRNG(RandomnessSource rs, double fairness)
                                                                                                              Construct a new DharmaRNG with the given seed.
                                                                                                              - -DharmaRNG(String seedString) -
                                                                                                              String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a - seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, - tiny state size, and excellent 64-bit number generation.
                                                                                                              - - DharmaRNG(String seedString, double fairness) @@ -255,10 +255,6 @@

                                                                                                              Method Summary

                                                                                                              Method and Description -Random -asRandom()  - - double between(double min, double max) @@ -266,21 +262,21 @@

                                                                                                              Method Summary

                                                                                                              (exclusive).
                                                                                                              - + int between(int min, int max)
                                                                                                              Returns a value between min (inclusive) and max (exclusive).
                                                                                                              - + long between(long min, long max)
                                                                                                              Returns a value between min (inclusive) and max (exclusive).
                                                                                                              - + int betweenWeighted(int min, int max, @@ -289,30 +285,30 @@

                                                                                                              Method Summary

                                                                                                              provided range, with min being inclusive and max being exclusive.
                                                                                                      - + RNG copy()
                                                                                                      Creates a copy of this DharmaRNG; it will generate the same random numbers, given the same calls in order, as this DharmaRNG at the point copy() is called.
                                                                                                      - + boolean equals(Object o)  - + double getFairness()
                                                                                                      Gets the measure that this class uses for RNG fairness, defaulting to 0.54 (always between 0.0 and 1.0).
                                                                                                      - + double getFortune()
                                                                                                      Gets the status of the fortune used when calculating fairness adjustments.
                                                                                                      - + <T> T getRandomElement(Collection<T> coll)
                                                                                                      Returns a random element from the provided Collection, which should have predictable iteration order if you want @@ -320,121 +316,109 @@

                                                                                                      Method Summary

                                                                                                      (just not predictably in all cases).
                                                                                                      - + <T> T getRandomElement(List<T> list)
                                                                                                      Returns a random element from the provided list.
                                                                                                      - + short getRandomElement(ShortSet set)
                                                                                                      Returns a random element from the provided ShortSet.
                                                                                                      - + <T> T getRandomElement(T[] array)
                                                                                                      Returns a random element from the provided array and maintains object type.
                                                                                                      - + RandomnessSource getRandomness()  - -<T> Iterable<T> -getRandomStartIterable(List<T> list) -
                                                                                                      Get an Iterable that starts at a random location in list and continues on through list in its current order.
                                                                                                      - - - + int hashCode()  - + int next(int bits)
                                                                                                      Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                      - + boolean nextBoolean()
                                                                                                      Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                      - + double nextDouble()
                                                                                                      Generate a random double, altering the result if recently generated results have been leaning away from this class' fairness value.
                                                                                                      - + double nextDouble(double max)
                                                                                                      This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                      - + float nextFloat()
                                                                                                      This returns a maximum of 0.99999994 because that is the largest Float value that is less than 1.0f
                                                                                                      - + double nextGaussian()  - + int nextInt()
                                                                                                      Returns a random integer, which may be positive or negative.
                                                                                                      - + int nextInt(int bound)
                                                                                                      Returns a random integer below the given bound, or 0 if the bound is 0 or negative.
                                                                                                      - + int nextIntHasty(int bound)
                                                                                                      Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                      - + long nextLong()
                                                                                                      Returns a random long, which may be positive or negative.
                                                                                                      - + long nextLong(long bound)
                                                                                                      Returns a random long below the given bound, or 0 if the bound is 0 or negative.
                                                                                                      - -int[] -randomOrdering(int length) -
                                                                                                      Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                      - - - + <T> List<T> randomPortion(List<T> data, int count)
                                                                                                      Gets a random portion of a List and returns it as a new List.
                                                                                                      - + <T> T[] randomPortion(T[] data, T[] output) @@ -442,7 +426,7 @@

                                                                                                      Method Summary

                                                                                                      it can, and then returns output.
                                                                                                  - + int[] randomRange(int start, int end, @@ -450,49 +434,24 @@

                                                                                                  Method Summary

                                                                                                  Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                  - -<T> List<T> -randomRotation(List<T> l) -
                                                                                                  Given a List l, this selects a random element of l to be the first value in the returned list l2.
                                                                                                  - - - + void resetFortune()
                                                                                                  Resets the stored history this RNG uses to try to ensure fairness.
                                                                                                  - + void setFairness(double fairness)
                                                                                                  Sets the measure that this class uses for RNG fairness, which must always be between 0.0 and 1.0, and will be set to 0.54 if an invalid value is passed.
                                                                                                  - + void setRandomness(RandomnessSource random)  - -<T> ArrayList<T> -shuffle(Collection<T> elements) -
                                                                                                  Shuffles a Collection of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                  - - - -<T> T[] -shuffle(T[] elements) -
                                                                                                  Shuffle an array using the Fisher-Yates algorithm.
                                                                                                  - - - -<T> T[] -shuffle(T[] elements, - T[] dest) -
                                                                                                  Shuffle an array using the Fisher-Yates algorithm.
                                                                                                  - - - + String toString()  @@ -502,7 +461,7 @@

                                                                                                  Method Summary

                                                                                                  Methods inherited from class squidpony.squidmath.RNG

                                                                                                  -approximateBits, getRandomCellsIterable, getRandomUniqueCells, getRandomUniqueCells, getRandomUniqueCells, nextBytes, nextCoord, randomInterleave, randomOrdering, shuffle, shuffleInPlace
                                                                                                • +approximateBits, asRandom, getRandomCellsIterable, getRandomStartIterable, getRandomUniqueCells, getRandomUniqueCells, getRandomUniqueCells, nextBytes, nextCoord, randomInterleave, randomOrdering, randomOrdering, randomRotation, shuffle, shuffle, shuffle, shuffle, shuffleInPlace
                                                                                                • @@ -531,7 +490,7 @@

                                                                                                  Constructor Detail

                                                                                                  @@ -541,7 +500,7 @@

                                                                                                  DharmaRNG

                                                                                                  • DharmaRNG

                                                                                                    -
                                                                                                    public DharmaRNG(long seed)
                                                                                                    +
                                                                                                    public DharmaRNG(long seed)
                                                                                                    Construct a new DharmaRNG with the given seed.
                                                                                                    Parameters:
                                                                                                    @@ -555,7 +514,7 @@

                                                                                                    DharmaRNG

                                                                                                    • DharmaRNG

                                                                                                      -
                                                                                                      public DharmaRNG(long seed,
                                                                                                      +
                                                                                                      public DharmaRNG(long seed,
                                                                                                                        double fairness)
                                                                                                      Construct a new DharmaRNG with the given seed.
                                                                                                      @@ -565,13 +524,13 @@

                                                                                                      DharmaRNG

                                                                                                    - +
                                                                                                    • DharmaRNG

                                                                                                      -
                                                                                                      public DharmaRNG(String seedString)
                                                                                                      +
                                                                                                      public DharmaRNG(CharSequence seedString)
                                                                                                      String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                      @@ -587,7 +546,7 @@

                                                                                                      DharmaRNG

                                                                                                      • DharmaRNG

                                                                                                        -
                                                                                                        public DharmaRNG(String seedString,
                                                                                                        +
                                                                                                        public DharmaRNG(String seedString,
                                                                                                                          double fairness)
                                                                                                        String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, @@ -604,7 +563,7 @@

                                                                                                        DharmaRNG

                                                                                                        • DharmaRNG

                                                                                                          -
                                                                                                          public DharmaRNG(RandomnessSource rs)
                                                                                                          +
                                                                                                          public DharmaRNG(RandomnessSource rs)
                                                                                                          Construct a new DharmaRNG with the given seed.
                                                                                                          Parameters:
                                                                                                          @@ -618,7 +577,7 @@

                                                                                                          DharmaRNG

                                                                                                          • DharmaRNG

                                                                                                            -
                                                                                                            public DharmaRNG(RandomnessSource rs,
                                                                                                            +
                                                                                                            public DharmaRNG(RandomnessSource rs,
                                                                                                                              double fairness)
                                                                                                            Construct a new DharmaRNG with the given seed.
                                                                                                            @@ -642,7 +601,7 @@

                                                                                                            Method Detail

                                                                                                            • nextDouble

                                                                                                              -
                                                                                                              public double nextDouble()
                                                                                                              +
                                                                                                              public double nextDouble()
                                                                                                              Generate a random double, altering the result if recently generated results have been leaning away from this class' fairness value.
                                                                                                              @@ -659,7 +618,7 @@

                                                                                                              nextDouble

                                                                                                              • nextDouble

                                                                                                                -
                                                                                                                public double nextDouble(double max)
                                                                                                                +
                                                                                                                public double nextDouble(double max)
                                                                                                                This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                Overrides:
                                                                                                                @@ -675,7 +634,7 @@

                                                                                                                nextDouble

                                                                                                                • between

                                                                                                                  -
                                                                                                                  public double between(double min,
                                                                                                                  +
                                                                                                                  public double between(double min,
                                                                                                                                         double max)
                                                                                                                  Returns a value from a even distribution from min (inclusive) to max (exclusive).
                                                                                                                  @@ -696,7 +655,7 @@

                                                                                                                  between

                                                                                                                  • between

                                                                                                                    -
                                                                                                                    public int between(int min,
                                                                                                                    +
                                                                                                                    public int between(int min,
                                                                                                                                        int max)
                                                                                                                    Returns a value between min (inclusive) and max (exclusive). @@ -719,7 +678,7 @@

                                                                                                                    between

                                                                                                                    • betweenWeighted

                                                                                                                      -
                                                                                                                      public int betweenWeighted(int min,
                                                                                                                      +
                                                                                                                      public int betweenWeighted(int min,
                                                                                                                                                  int max,
                                                                                                                                                  int samples)
                                                                                                                      Returns the average of a number of randomly selected numbers from the @@ -750,7 +709,7 @@

                                                                                                                      betweenWeighted

                                                                                                                      • getRandomElement

                                                                                                                        -
                                                                                                                        public <T> T getRandomElement(T[] array)
                                                                                                                        +
                                                                                                                        public <T> T getRandomElement(T[] array)
                                                                                                                        Returns a random element from the provided array and maintains object type.
                                                                                                                        @@ -771,7 +730,7 @@

                                                                                                                        getRandomElement

                                                                                                                        • getRandomElement

                                                                                                                          -
                                                                                                                          public <T> T getRandomElement(List<T> list)
                                                                                                                          +
                                                                                                                          public <T> T getRandomElement(List<T> list)
                                                                                                                          Returns a random element from the provided list. If the list is empty then null is returned.
                                                                                                                          @@ -792,7 +751,7 @@

                                                                                                                          getRandomElement

                                                                                                                          • getRandomElement

                                                                                                                            -
                                                                                                                            public short getRandomElement(ShortSet set)
                                                                                                                            +
                                                                                                                            public short getRandomElement(ShortSet set)
                                                                                                                            Returns a random element from the provided ShortSet. If the set is empty then an exception is thrown. @@ -816,7 +775,7 @@

                                                                                                                            getRandomElement

                                                                                                                            • getRandomElement

                                                                                                                              -
                                                                                                                              public <T> T getRandomElement(Collection<T> coll)
                                                                                                                              +
                                                                                                                              public <T> T getRandomElement(Collection<T> coll)
                                                                                                                              Returns a random element from the provided Collection, which should have predictable iteration order if you want predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted @@ -847,7 +806,7 @@

                                                                                                                              getRandomElement

                                                                                                                              • nextGaussian

                                                                                                                                -
                                                                                                                                public double nextGaussian()
                                                                                                                                +
                                                                                                                                public double nextGaussian()
                                                                                                                                Overrides:
                                                                                                                                nextGaussian in class RNG
                                                                                                                                @@ -862,7 +821,7 @@

                                                                                                                                nextGaussian

                                                                                                                                • nextInt

                                                                                                                                  -
                                                                                                                                  public int nextInt(int bound)
                                                                                                                                  +
                                                                                                                                  public int nextInt(int bound)
                                                                                                                                  Returns a random integer below the given bound, or 0 if the bound is 0 or negative. Affects the current fortune.
                                                                                                                                  @@ -881,7 +840,7 @@

                                                                                                                                  nextInt

                                                                                                                                  • nextInt

                                                                                                                                    -
                                                                                                                                    public int nextInt()
                                                                                                                                    +
                                                                                                                                    public int nextInt()
                                                                                                                                    Returns a random integer, which may be positive or negative. Affects the current fortune.
                                                                                                                                    Overrides:
                                                                                                                                    @@ -897,7 +856,7 @@

                                                                                                                                    nextInt

                                                                                                                                    • nextLong

                                                                                                                                      -
                                                                                                                                      public long nextLong()
                                                                                                                                      +
                                                                                                                                      public long nextLong()
                                                                                                                                      Returns a random long, which may be positive or negative. Affects the current fortune.
                                                                                                                                      Overrides:
                                                                                                                                      @@ -913,7 +872,7 @@

                                                                                                                                      nextLong

                                                                                                                                      • nextLong

                                                                                                                                        -
                                                                                                                                        public long nextLong(long bound)
                                                                                                                                        +
                                                                                                                                        public long nextLong(long bound)
                                                                                                                                        Returns a random long below the given bound, or 0 if the bound is 0 or negative.
                                                                                                                                        @@ -932,7 +891,7 @@

                                                                                                                                        nextLong

                                                                                                                                        • getFairness

                                                                                                                                          -
                                                                                                                                          public double getFairness()
                                                                                                                                          +
                                                                                                                                          public double getFairness()
                                                                                                                                          Gets the measure that this class uses for RNG fairness, defaulting to 0.54 (always between 0.0 and 1.0).
                                                                                                                                          Returns:
                                                                                                                                          @@ -946,7 +905,7 @@

                                                                                                                                          getFairness

                                                                                                                                          • setFairness

                                                                                                                                            -
                                                                                                                                            public void setFairness(double fairness)
                                                                                                                                            +
                                                                                                                                            public void setFairness(double fairness)
                                                                                                                                            Sets the measure that this class uses for RNG fairness, which must always be between 0.0 and 1.0, and will be set to 0.54 if an invalid value is passed.
                                                                                                                                            @@ -961,7 +920,7 @@

                                                                                                                                            setFairness

                                                                                                                                            • getFortune

                                                                                                                                              -
                                                                                                                                              public double getFortune()
                                                                                                                                              +
                                                                                                                                              public double getFortune()
                                                                                                                                              Gets the status of the fortune used when calculating fairness adjustments.
                                                                                                                                              Returns:
                                                                                                                                              @@ -975,7 +934,7 @@

                                                                                                                                              getFortune

                                                                                                                                              • resetFortune

                                                                                                                                                -
                                                                                                                                                public void resetFortune()
                                                                                                                                                +
                                                                                                                                                public void resetFortune()
                                                                                                                                                Resets the stored history this RNG uses to try to ensure fairness.
                                                                                                                                              @@ -985,7 +944,7 @@

                                                                                                                                              resetFortune

                                                                                                                                              • next

                                                                                                                                                -
                                                                                                                                                public int next(int bits)
                                                                                                                                                +
                                                                                                                                                public int next(int bits)
                                                                                                                                                Description copied from class: RNG
                                                                                                                                                Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                @@ -998,138 +957,13 @@

                                                                                                                                                next

                                                                                                                                              - - - -
                                                                                                                                                -
                                                                                                                                              • -

                                                                                                                                                asRandom

                                                                                                                                                -
                                                                                                                                                public Random asRandom()
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                                Overrides:
                                                                                                                                                -
                                                                                                                                                asRandom in class RNG
                                                                                                                                                -
                                                                                                                                                Returns:
                                                                                                                                                -
                                                                                                                                                a Random instance that can be used for legacy compatibility
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                              • -
                                                                                                                                              - - - -
                                                                                                                                                -
                                                                                                                                              • -

                                                                                                                                                randomRotation

                                                                                                                                                -
                                                                                                                                                public <T> List<T> randomRotation(List<T> l)
                                                                                                                                                -
                                                                                                                                                Description copied from class: RNG
                                                                                                                                                -
                                                                                                                                                Given a List l, this selects a random element of l to be the first value in the returned list l2. It - retains the order of elements in l after that random element and makes them follow the first element in l2, and - loops around to use elements from the start of l after it has placed the last element of l into l2. -
                                                                                                                                                - Essentially, it does what it says on the tin. It randomly rotates the List l. -
                                                                                                                                                - If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable() - should have better performance.
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                                Overrides:
                                                                                                                                                -
                                                                                                                                                randomRotation in class RNG
                                                                                                                                                -
                                                                                                                                                Type Parameters:
                                                                                                                                                -
                                                                                                                                                T - No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                                                                                -
                                                                                                                                                Parameters:
                                                                                                                                                -
                                                                                                                                                l - A List that will not be modified by this method. All elements of this parameter will be - shared with the returned List.
                                                                                                                                                -
                                                                                                                                                Returns:
                                                                                                                                                -
                                                                                                                                                A shallow copy of l that has been rotated so its first element has been randomly chosen - from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last - element of l, then element 1, etc.
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                              • -
                                                                                                                                              - - - -
                                                                                                                                                -
                                                                                                                                              • -

                                                                                                                                                getRandomStartIterable

                                                                                                                                                -
                                                                                                                                                public <T> Iterable<T> getRandomStartIterable(List<T> list)
                                                                                                                                                -
                                                                                                                                                Description copied from class: RNG
                                                                                                                                                -
                                                                                                                                                Get an Iterable that starts at a random location in list and continues on through list in its current order. - Loops around to the beginning after it gets to the end, stops when it returns to the starting location. -
                                                                                                                                                - You should not modify list while you use the returned reference. And there'll be no - ConcurrentModificationException to detect such erroneous uses.
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                                Overrides:
                                                                                                                                                -
                                                                                                                                                getRandomStartIterable in class RNG
                                                                                                                                                -
                                                                                                                                                Parameters:
                                                                                                                                                -
                                                                                                                                                list - A list with a constant-time List.get(int) method (otherwise performance degrades).
                                                                                                                                                -
                                                                                                                                                Returns:
                                                                                                                                                -
                                                                                                                                                An Iterable that iterates over list but start at - a random index. If the chosen index is i, the iterator - will return: - list[i]; list[i+1]; ...; list[list.length() - 1]; list[0]; list[i-1]
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                              • -
                                                                                                                                              - - - - - -
                                                                                                                                                -
                                                                                                                                              • -

                                                                                                                                                shuffle

                                                                                                                                                -
                                                                                                                                                public <T> T[] shuffle(T[] elements,
                                                                                                                                                -                       T[] dest)
                                                                                                                                                -
                                                                                                                                                Description copied from class: RNG
                                                                                                                                                -
                                                                                                                                                Shuffle an array using the Fisher-Yates algorithm. DO NOT give the same array for both elements and - dest, since the prior contents of dest are rearranged before elements is used, and if they refer to the same - array, then you can end up with bizarre bugs where one previously-unique item shows up dozens of times. If - possible, create a new array with the same length as elements and pass it in as dest; the returned value can be - assigned to whatever you want and will have the same items as the newly-formed array. -
                                                                                                                                                - https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                                Overrides:
                                                                                                                                                -
                                                                                                                                                shuffle in class RNG
                                                                                                                                                -
                                                                                                                                                Type Parameters:
                                                                                                                                                -
                                                                                                                                                T - can be any non-primitive type.
                                                                                                                                                -
                                                                                                                                                Parameters:
                                                                                                                                                -
                                                                                                                                                elements - an array of T; will not be modified
                                                                                                                                                -
                                                                                                                                                dest - Where to put the shuffle. If it does not have the same length as elements, this will use the - randomPortion method of this class to fill the smaller dest. MUST NOT be the same array as elements!
                                                                                                                                                -
                                                                                                                                                Returns:
                                                                                                                                                -
                                                                                                                                                dest after modifications
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                              • -
                                                                                                                                              - - - -
                                                                                                                                                -
                                                                                                                                              • -

                                                                                                                                                shuffle

                                                                                                                                                -
                                                                                                                                                public <T> ArrayList<T> shuffle(Collection<T> elements)
                                                                                                                                                -
                                                                                                                                                Description copied from class: RNG
                                                                                                                                                -
                                                                                                                                                Shuffles a Collection of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                                Overrides:
                                                                                                                                                -
                                                                                                                                                shuffle in class RNG
                                                                                                                                                -
                                                                                                                                                Type Parameters:
                                                                                                                                                -
                                                                                                                                                T - can be any non-primitive type.
                                                                                                                                                -
                                                                                                                                                Parameters:
                                                                                                                                                -
                                                                                                                                                elements - a Collection of T; will not be modified
                                                                                                                                                -
                                                                                                                                                Returns:
                                                                                                                                                -
                                                                                                                                                a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                -
                                                                                                                                                -
                                                                                                                                              • -
                                                                                                                                              • between

                                                                                                                                                -
                                                                                                                                                public long between(long min,
                                                                                                                                                +
                                                                                                                                                public long between(long min,
                                                                                                                                                                     long max)
                                                                                                                                                Returns a value between min (inclusive) and max (exclusive).

                                                                                                                                                @@ -1146,56 +980,13 @@

                                                                                                                                                between

                                                                                                                                            - - - - - -
                                                                                                                                              -
                                                                                                                                            • -

                                                                                                                                              shuffle

                                                                                                                                              -
                                                                                                                                              public <T> T[] shuffle(T[] elements)
                                                                                                                                              -
                                                                                                                                              Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays. -
                                                                                                                                              - https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                              -
                                                                                                                                              -
                                                                                                                                              Overrides:
                                                                                                                                              -
                                                                                                                                              shuffle in class RNG
                                                                                                                                              -
                                                                                                                                              Type Parameters:
                                                                                                                                              -
                                                                                                                                              T - can be any non-primitive type.
                                                                                                                                              -
                                                                                                                                              Parameters:
                                                                                                                                              -
                                                                                                                                              elements - an array of T; will not be modified
                                                                                                                                              -
                                                                                                                                              Returns:
                                                                                                                                              -
                                                                                                                                              a shuffled copy of elements
                                                                                                                                              -
                                                                                                                                              -
                                                                                                                                            • -
                                                                                                                                            - - - -
                                                                                                                                              -
                                                                                                                                            • -

                                                                                                                                              randomOrdering

                                                                                                                                              -
                                                                                                                                              public int[] randomOrdering(int length)
                                                                                                                                              -
                                                                                                                                              Generates a random permutation of the range from 0 (inclusive) to length (exclusive). - Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                              -
                                                                                                                                              -
                                                                                                                                              Overrides:
                                                                                                                                              -
                                                                                                                                              randomOrdering in class RNG
                                                                                                                                              -
                                                                                                                                              Parameters:
                                                                                                                                              -
                                                                                                                                              length - the size of the ordering to produce
                                                                                                                                              -
                                                                                                                                              Returns:
                                                                                                                                              -
                                                                                                                                              a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                              -
                                                                                                                                              -
                                                                                                                                            • -
                                                                                                                                            • nextIntHasty

                                                                                                                                              -
                                                                                                                                              public int nextIntHasty(int bound)
                                                                                                                                              +
                                                                                                                                              public int nextIntHasty(int bound)
                                                                                                                                              Returns a random non-negative integer below the given bound, or 0 if the bound is 0. Uses a slightly optimized technique. This method is considered "hasty" since it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also @@ -1217,7 +1008,7 @@

                                                                                                                                              nextIntHasty

                                                                                                                                              • nextFloat

                                                                                                                                                -
                                                                                                                                                public float nextFloat()
                                                                                                                                                +
                                                                                                                                                public float nextFloat()
                                                                                                                                                Description copied from class: RNG
                                                                                                                                                This returns a maximum of 0.99999994 because that is the largest Float value that is less than 1.0f
                                                                                                                                                @@ -1235,7 +1026,7 @@

                                                                                                                                                nextFloat

                                                                                                                                                • nextBoolean

                                                                                                                                                  -
                                                                                                                                                  public boolean nextBoolean()
                                                                                                                                                  +
                                                                                                                                                  public boolean nextBoolean()
                                                                                                                                                  Description copied from class: RNG
                                                                                                                                                  Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                  @@ -1252,7 +1043,7 @@

                                                                                                                                                  nextBoolean

                                                                                                                                                  • getRandomness

                                                                                                                                                    -
                                                                                                                                                    public RandomnessSource getRandomness()
                                                                                                                                                    +
                                                                                                                                                    public RandomnessSource getRandomness()
                                                                                                                                                    Overrides:
                                                                                                                                                    getRandomness in class RNG
                                                                                                                                                    @@ -1265,7 +1056,7 @@

                                                                                                                                                    getRandomness

                                                                                                                                                    • setRandomness

                                                                                                                                                      -
                                                                                                                                                      public void setRandomness(RandomnessSource random)
                                                                                                                                                      +
                                                                                                                                                      public void setRandomness(RandomnessSource random)
                                                                                                                                                      Overrides:
                                                                                                                                                      setRandomness in class RNG
                                                                                                                                                      @@ -1278,7 +1069,7 @@

                                                                                                                                                      setRandomness

                                                                                                                                                      • copy

                                                                                                                                                        -
                                                                                                                                                        public RNG copy()
                                                                                                                                                        +
                                                                                                                                                        public RNG copy()
                                                                                                                                                        Creates a copy of this DharmaRNG; it will generate the same random numbers, given the same calls in order, as this DharmaRNG at the point copy() is called. The copy will not share references with this DharmaRNG.
                                                                                                                                                        @@ -1297,7 +1088,7 @@

                                                                                                                                                        copy

                                                                                                                                                        • randomPortion

                                                                                                                                                          -
                                                                                                                                                          public <T> T[] randomPortion(T[] data,
                                                                                                                                                          +
                                                                                                                                                          public <T> T[] randomPortion(T[] data,
                                                                                                                                                                                        T[] output)
                                                                                                                                                          Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as it can, and then returns output. Will only use a given position in the given data at most once; does this by @@ -1325,7 +1116,7 @@

                                                                                                                                                          randomPortion

                                                                                                                                                          • randomPortion

                                                                                                                                                            -
                                                                                                                                                            public <T> List<T> randomPortion(List<T> data,
                                                                                                                                                            +
                                                                                                                                                            public <T> List<T> randomPortion(List<T> data,
                                                                                                                                                                                              int count)
                                                                                                                                                            Gets a random portion of a List and returns it as a new List. Will only use a given position in the given List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                            @@ -1348,7 +1139,7 @@

                                                                                                                                                            randomPortion

                                                                                                                                                            • randomRange

                                                                                                                                                              -
                                                                                                                                                              public int[] randomRange(int start,
                                                                                                                                                              +
                                                                                                                                                              public int[] randomRange(int start,
                                                                                                                                                                                        int end,
                                                                                                                                                                                        int count)
                                                                                                                                                              Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements. @@ -1371,7 +1162,7 @@

                                                                                                                                                              randomRange

                                                                                                                                                              • toString

                                                                                                                                                                -
                                                                                                                                                                public String toString()
                                                                                                                                                                +
                                                                                                                                                                public String toString()
                                                                                                                                                                Overrides:
                                                                                                                                                                toString in class RNG
                                                                                                                                                                @@ -1384,7 +1175,7 @@

                                                                                                                                                                toString

                                                                                                                                                                • equals

                                                                                                                                                                  -
                                                                                                                                                                  public boolean equals(Object o)
                                                                                                                                                                  +
                                                                                                                                                                  public boolean equals(Object o)
                                                                                                                                                                  Overrides:
                                                                                                                                                                  equals in class RNG
                                                                                                                                                                  @@ -1397,7 +1188,7 @@

                                                                                                                                                                  equals

                                                                                                                                                                  • hashCode

                                                                                                                                                                    -
                                                                                                                                                                    public int hashCode()
                                                                                                                                                                    +
                                                                                                                                                                    public int hashCode()
                                                                                                                                                                    Overrides:
                                                                                                                                                                    hashCode in class RNG
                                                                                                                                                                    diff --git a/docs/squidlib-util/squidpony/squidmath/EditRNG.html b/docs/squidlib-util/squidpony/squidmath/EditRNG.html index 6065edda3d..90a7ee98ea 100644 --- a/docs/squidlib-util/squidpony/squidmath/EditRNG.html +++ b/docs/squidlib-util/squidpony/squidmath/EditRNG.html @@ -18,7 +18,7 @@ catch(err) { } //--> -var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10,"i35":10,"i36":10,"i37":10,"i38":10,"i39":10,"i40":10,"i41":10}; +var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10,"i6":10,"i7":10,"i8":10,"i9":10,"i10":10,"i11":10,"i12":10,"i13":10,"i14":10,"i15":10,"i16":10,"i17":10,"i18":10,"i19":10,"i20":10,"i21":10,"i22":10,"i23":10,"i24":10,"i25":10,"i26":10,"i27":10,"i28":10,"i29":10,"i30":10,"i31":10,"i32":10,"i33":10,"i34":10}; var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; var altColor = "altColor"; var rowColor = "rowColor"; @@ -123,7 +123,7 @@

                                                                                                                                                                    Class EditRNG



                                                                                                                                                                    -
                                                                                                                                                                    public class EditRNG
                                                                                                                                                                    +
                                                                                                                                                                    public class EditRNG
                                                                                                                                                                     extends StatefulRNG
                                                                                                                                                                     implements Serializable
                                                                                                                                                                    A subclass of StatefulRNG (and thus RNG) that allows customizing many parts of the random number generation. @@ -241,46 +241,46 @@

                                                                                                                                                                    Constructor Summary

                                                                                                                                                                    -EditRNG(long seed) +EditRNG(CharSequence seed)
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    +EditRNG(long seed) +
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    + + + EditRNG(long seed, double expected)
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    - + EditRNG(long seed, double expected, double centrality)
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    - + EditRNG(RandomnessSource rs)
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    - + EditRNG(RandomnessSource rs, double expected)
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    - + EditRNG(RandomnessSource rs, double expected, double centrality)
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    - -EditRNG(String seed) -
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    - - EditRNG(String seed, double expected) @@ -310,10 +310,6 @@

                                                                                                                                                                    Method Summary

                                                                                                                                                                    Method and Description -Random -asRandom()  - - double between(double min, double max) @@ -321,21 +317,21 @@

                                                                                                                                                                    Method Summary

                                                                                                                                                                    (exclusive).
                                                                                                                                                                    - + int between(int min, int max)
                                                                                                                                                                    Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                    - + long between(long min, long max)
                                                                                                                                                                    Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                    - + int betweenWeighted(int min, int max, @@ -344,30 +340,30 @@

                                                                                                                                                                    Method Summary

                                                                                                                                                                    provided range, with min being inclusive and max being exclusive.
                                                                                                                                                              - + RNG copy()
                                                                                                                                                              Creates a copy of this StatefulRNG; it will generate the same random numbers, given the same calls in order, as this StatefulRNG at the point copy() is called.
                                                                                                                                                              - + boolean equals(Object o)  - + double getCentrality()
                                                                                                                                                              Gets the current centrality measure of this EditRNG.
                                                                                                                                                              - + double getExpected()
                                                                                                                                                              Gets the current expected average for this EditRNG.
                                                                                                                                                              - + <T> T getRandomElement(Collection<T> coll)
                                                                                                                                                              Returns a random element from the provided Collection, which should have predictable iteration order if you want @@ -375,133 +371,121 @@

                                                                                                                                                              Method Summary

                                                                                                                                                              (just not predictably in all cases).
                                                                                                                                                              - + <T> T getRandomElement(List<T> list)
                                                                                                                                                              Returns a random element from the provided list.
                                                                                                                                                              - + short getRandomElement(ShortSet set)
                                                                                                                                                              Returns a random element from the provided ShortSet.
                                                                                                                                                              - + <T> T getRandomElement(T[] array)
                                                                                                                                                              Returns a random element from the provided array and maintains object type.
                                                                                                                                                              - + RandomnessSource getRandomness()  - -<T> Iterable<T> -getRandomStartIterable(List<T> list) -
                                                                                                                                                              Get an Iterable that starts at a random location in list and continues on through list in its current order.
                                                                                                                                                              - - - + double getRawLatest()
                                                                                                                                                              Gets the latest "un-biased" random double used to produce the most recent (potentially) biased random number generated for another method in this class, such as nextDouble(), between(), or getRandomElement().
                                                                                                                                                              - + long getState()
                                                                                                                                                              Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                                                                                                              - + int hashCode()  - + int next(int bits)
                                                                                                                                                              Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                              - + boolean nextBoolean()
                                                                                                                                                              Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                              - + double nextDouble()
                                                                                                                                                              Generate a random double, altered to try to match the expected average and centrality.
                                                                                                                                                              - + double nextDouble(double max)
                                                                                                                                                              This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                              - + float nextFloat()
                                                                                                                                                              This returns a maximum of 0.99999994 because that is the largest Float value that is less than 1.0f
                                                                                                                                                              - + double nextGaussian()  - + int nextInt()
                                                                                                                                                              Returns a random integer, which may be positive or negative.
                                                                                                                                                              - + int nextInt(int bound)
                                                                                                                                                              Returns a random integer below the given bound, or 0 if the bound is 0 or negative.
                                                                                                                                                              - + int nextIntHasty(int bound)
                                                                                                                                                              Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                              - + long nextLong()
                                                                                                                                                              Returns a random long, which may be positive or negative.
                                                                                                                                                              - + long nextLong(long bound)
                                                                                                                                                              Returns a random long below the given bound, or 0 if the bound is 0 or negative.
                                                                                                                                                              - -int[] -randomOrdering(int length) -
                                                                                                                                                              Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                              - - - + <T> List<T> randomPortion(List<T> data, int count)
                                                                                                                                                              Gets a random portion of a List and returns it as a new List.
                                                                                                                                                              - + <T> T[] randomPortion(T[] data, T[] output) @@ -509,7 +493,7 @@

                                                                                                                                                              Method Summary

                                                                                                                                                              it can, and then returns output.
                                                                                                                                                          - + int[] randomRange(int start, int end, @@ -517,56 +501,31 @@

                                                                                                                                                          Method Summary

                                                                                                                                                          Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                          - -<T> List<T> -randomRotation(List<T> l) -
                                                                                                                                                          Given a List l, this selects a random element of l to be the first value in the returned list l2.
                                                                                                                                                          - - - + void setCentrality(double centrality)
                                                                                                                                                          Gets the current centrality measure of this EditRNG.
                                                                                                                                                          - + void setExpected(double expected)
                                                                                                                                                          Sets the expected average for random doubles this produces, which must always be between 0.1 and 0.9, and will be set to 0.5 if an invalid value is passed.
                                                                                                                                                          - + void setRandomness(RandomnessSource random)  - + void setState(long state)
                                                                                                                                                          Sets the state of the random number generator to a given long, which will alter future random numbers this produces based on the state.
                                                                                                                                                          - -<T> ArrayList<T> -shuffle(Collection<T> elements) -
                                                                                                                                                          Shuffles a Collection of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                          - - - -<T> T[] -shuffle(T[] elements) -
                                                                                                                                                          Shuffle an array using the Fisher-Yates algorithm.
                                                                                                                                                          - - - -<T> T[] -shuffle(T[] elements, - T[] dest) -
                                                                                                                                                          Shuffle an array using the Fisher-Yates algorithm.
                                                                                                                                                          - - - + String toString()  @@ -576,7 +535,7 @@

                                                                                                                                                          Method Summary

                                                                                                                                                          Methods inherited from class squidpony.squidmath.RNG

                                                                                                                                                          -approximateBits, getRandomCellsIterable, getRandomUniqueCells, getRandomUniqueCells, getRandomUniqueCells, nextBytes, nextCoord, randomInterleave, randomOrdering, shuffle, shuffleInPlace
                                                                                                                                                        • +approximateBits, asRandom, getRandomCellsIterable, getRandomStartIterable, getRandomUniqueCells, getRandomUniqueCells, getRandomUniqueCells, nextBytes, nextCoord, randomInterleave, randomOrdering, randomOrdering, randomRotation, shuffle, shuffle, shuffle, shuffle, shuffleInPlace
                                                                                                                                                        • @@ -605,7 +564,7 @@

                                                                                                                                                          Field Detail

                                                                                                                                                          • rawLatest

                                                                                                                                                            -
                                                                                                                                                            public double rawLatest
                                                                                                                                                            +
                                                                                                                                                            public double rawLatest
                                                                                                                                                            The latest generated double, between 0.0 and 1.0, before changes for centrality and expected average. Doubles are used to generate all random numbers this class produces, so be aware that calling getRandomElement() will change this just as much as nextDouble(), nextInt(), or between() will. Primarily useful to obtain @@ -629,7 +588,7 @@

                                                                                                                                                            Constructor Detail

                                                                                                                                                            • EditRNG

                                                                                                                                                              -
                                                                                                                                                              public EditRNG()
                                                                                                                                                              +
                                                                                                                                                              public EditRNG()
                                                                                                                                                              Constructs an EditRNG with a pseudo-random seed from Math.random().
                                                                                                                                                            @@ -639,7 +598,7 @@

                                                                                                                                                            EditRNG

                                                                                                                                                            • EditRNG

                                                                                                                                                              -
                                                                                                                                                              public EditRNG(long seed)
                                                                                                                                                              +
                                                                                                                                                              public EditRNG(long seed)
                                                                                                                                                              Construct a new EditRNG with the given seed.
                                                                                                                                                              Parameters:
                                                                                                                                                              @@ -647,13 +606,13 @@

                                                                                                                                                              EditRNG

                                                                                                                                                            - +
                                                                                                                                                            • EditRNG

                                                                                                                                                              -
                                                                                                                                                              public EditRNG(String seed)
                                                                                                                                                              +
                                                                                                                                                              public EditRNG(CharSequence seed)
                                                                                                                                                              Construct a new EditRNG with the given seed.
                                                                                                                                                              Parameters:
                                                                                                                                                              @@ -667,7 +626,7 @@

                                                                                                                                                              EditRNG

                                                                                                                                                              • EditRNG

                                                                                                                                                                -
                                                                                                                                                                public EditRNG(long seed,
                                                                                                                                                                +
                                                                                                                                                                public EditRNG(long seed,
                                                                                                                                                                                double expected)
                                                                                                                                                                Construct a new EditRNG with the given seed.
                                                                                                                                                                @@ -683,7 +642,7 @@

                                                                                                                                                                EditRNG

                                                                                                                                                                • EditRNG

                                                                                                                                                                  -
                                                                                                                                                                  public EditRNG(String seed,
                                                                                                                                                                  +
                                                                                                                                                                  public EditRNG(String seed,
                                                                                                                                                                                  double expected)
                                                                                                                                                                  Construct a new EditRNG with the given seed.
                                                                                                                                                                  @@ -699,7 +658,7 @@

                                                                                                                                                                  EditRNG

                                                                                                                                                                  • EditRNG

                                                                                                                                                                    -
                                                                                                                                                                    public EditRNG(long seed,
                                                                                                                                                                    +
                                                                                                                                                                    public EditRNG(long seed,
                                                                                                                                                                                    double expected,
                                                                                                                                                                                    double centrality)
                                                                                                                                                                    Construct a new EditRNG with the given seed.
                                                                                                                                                                    @@ -718,7 +677,7 @@

                                                                                                                                                                    EditRNG

                                                                                                                                                                    • EditRNG

                                                                                                                                                                      -
                                                                                                                                                                      public EditRNG(String seed,
                                                                                                                                                                      +
                                                                                                                                                                      public EditRNG(String seed,
                                                                                                                                                                                      double expected,
                                                                                                                                                                                      double centrality)
                                                                                                                                                                      Construct a new EditRNG with the given seed.
                                                                                                                                                                      @@ -737,7 +696,7 @@

                                                                                                                                                                      EditRNG

                                                                                                                                                                      • EditRNG

                                                                                                                                                                        -
                                                                                                                                                                        public EditRNG(RandomnessSource rs)
                                                                                                                                                                        +
                                                                                                                                                                        public EditRNG(RandomnessSource rs)
                                                                                                                                                                        Construct a new EditRNG with the given seed.
                                                                                                                                                                        Parameters:
                                                                                                                                                                        @@ -751,7 +710,7 @@

                                                                                                                                                                        EditRNG

                                                                                                                                                                        • EditRNG

                                                                                                                                                                          -
                                                                                                                                                                          public EditRNG(RandomnessSource rs,
                                                                                                                                                                          +
                                                                                                                                                                          public EditRNG(RandomnessSource rs,
                                                                                                                                                                                          double expected)
                                                                                                                                                                          Construct a new EditRNG with the given seed.
                                                                                                                                                                          @@ -767,7 +726,7 @@

                                                                                                                                                                          EditRNG

                                                                                                                                                                          • EditRNG

                                                                                                                                                                            -
                                                                                                                                                                            public EditRNG(RandomnessSource rs,
                                                                                                                                                                            +
                                                                                                                                                                            public EditRNG(RandomnessSource rs,
                                                                                                                                                                                            double expected,
                                                                                                                                                                                            double centrality)
                                                                                                                                                                            Construct a new EditRNG with the given seed.
                                                                                                                                                                            @@ -794,7 +753,7 @@

                                                                                                                                                                            Method Detail

                                                                                                                                                                            • nextDouble

                                                                                                                                                                              -
                                                                                                                                                                              public double nextDouble()
                                                                                                                                                                              +
                                                                                                                                                                              public double nextDouble()
                                                                                                                                                                              Generate a random double, altered to try to match the expected average and centrality.
                                                                                                                                                                              Overrides:
                                                                                                                                                                              @@ -810,7 +769,7 @@

                                                                                                                                                                              nextDouble

                                                                                                                                                                              • nextDouble

                                                                                                                                                                                -
                                                                                                                                                                                public double nextDouble(double max)
                                                                                                                                                                                +
                                                                                                                                                                                public double nextDouble(double max)
                                                                                                                                                                                This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                Overrides:
                                                                                                                                                                                @@ -826,7 +785,7 @@

                                                                                                                                                                                nextDouble

                                                                                                                                                                                • between

                                                                                                                                                                                  -
                                                                                                                                                                                  public double between(double min,
                                                                                                                                                                                  +
                                                                                                                                                                                  public double between(double min,
                                                                                                                                                                                                         double max)
                                                                                                                                                                                  Returns a value from a even distribution from min (inclusive) to max (exclusive).
                                                                                                                                                                                  @@ -847,7 +806,7 @@

                                                                                                                                                                                  between

                                                                                                                                                                                  • between

                                                                                                                                                                                    -
                                                                                                                                                                                    public int between(int min,
                                                                                                                                                                                    +
                                                                                                                                                                                    public int between(int min,
                                                                                                                                                                                                        int max)
                                                                                                                                                                                    Returns a value between min (inclusive) and max (exclusive). @@ -870,7 +829,7 @@

                                                                                                                                                                                    between

                                                                                                                                                                                    • between

                                                                                                                                                                                      -
                                                                                                                                                                                      public long between(long min,
                                                                                                                                                                                      +
                                                                                                                                                                                      public long between(long min,
                                                                                                                                                                                                           long max)
                                                                                                                                                                                      Description copied from class: RNG
                                                                                                                                                                                      Returns a value between min (inclusive) and max (exclusive). @@ -894,7 +853,7 @@

                                                                                                                                                                                      between

                                                                                                                                                                                      • betweenWeighted

                                                                                                                                                                                        -
                                                                                                                                                                                        public int betweenWeighted(int min,
                                                                                                                                                                                        +
                                                                                                                                                                                        public int betweenWeighted(int min,
                                                                                                                                                                                                                    int max,
                                                                                                                                                                                                                    int samples)
                                                                                                                                                                                        Returns the average of a number of randomly selected numbers from the @@ -925,7 +884,7 @@

                                                                                                                                                                                        betweenWeighted

                                                                                                                                                                                        • getRandomElement

                                                                                                                                                                                          -
                                                                                                                                                                                          public <T> T getRandomElement(T[] array)
                                                                                                                                                                                          +
                                                                                                                                                                                          public <T> T getRandomElement(T[] array)
                                                                                                                                                                                          Returns a random element from the provided array and maintains object type.
                                                                                                                                                                                          @@ -946,7 +905,7 @@

                                                                                                                                                                                          getRandomElement

                                                                                                                                                                                          • getRandomElement

                                                                                                                                                                                            -
                                                                                                                                                                                            public <T> T getRandomElement(List<T> list)
                                                                                                                                                                                            +
                                                                                                                                                                                            public <T> T getRandomElement(List<T> list)
                                                                                                                                                                                            Returns a random element from the provided list. If the list is empty then null is returned.
                                                                                                                                                                                            @@ -967,7 +926,7 @@

                                                                                                                                                                                            getRandomElement

                                                                                                                                                                                            • getRandomElement

                                                                                                                                                                                              -
                                                                                                                                                                                              public short getRandomElement(ShortSet set)
                                                                                                                                                                                              +
                                                                                                                                                                                              public short getRandomElement(ShortSet set)
                                                                                                                                                                                              Returns a random element from the provided ShortSet. If the set is empty then an exception is thrown. @@ -991,7 +950,7 @@

                                                                                                                                                                                              getRandomElement

                                                                                                                                                                                              • getRandomElement

                                                                                                                                                                                                -
                                                                                                                                                                                                public <T> T getRandomElement(Collection<T> coll)
                                                                                                                                                                                                +
                                                                                                                                                                                                public <T> T getRandomElement(Collection<T> coll)
                                                                                                                                                                                                Returns a random element from the provided Collection, which should have predictable iteration order if you want predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted @@ -1022,7 +981,7 @@

                                                                                                                                                                                                getRandomElement

                                                                                                                                                                                                • nextGaussian

                                                                                                                                                                                                  -
                                                                                                                                                                                                  public double nextGaussian()
                                                                                                                                                                                                  +
                                                                                                                                                                                                  public double nextGaussian()
                                                                                                                                                                                                  Overrides:
                                                                                                                                                                                                  nextGaussian in class RNG
                                                                                                                                                                                                  @@ -1037,7 +996,7 @@

                                                                                                                                                                                                  nextGaussian

                                                                                                                                                                                                  • nextInt

                                                                                                                                                                                                    -
                                                                                                                                                                                                    public int nextInt(int bound)
                                                                                                                                                                                                    +
                                                                                                                                                                                                    public int nextInt(int bound)
                                                                                                                                                                                                    Returns a random integer below the given bound, or 0 if the bound is 0 or negative.
                                                                                                                                                                                                    @@ -1056,7 +1015,7 @@

                                                                                                                                                                                                    nextInt

                                                                                                                                                                                                    • nextInt

                                                                                                                                                                                                      -
                                                                                                                                                                                                      public int nextInt()
                                                                                                                                                                                                      +
                                                                                                                                                                                                      public int nextInt()
                                                                                                                                                                                                      Returns a random integer, which may be positive or negative.
                                                                                                                                                                                                      Overrides:
                                                                                                                                                                                                      @@ -1072,7 +1031,7 @@

                                                                                                                                                                                                      nextInt

                                                                                                                                                                                                      • nextLong

                                                                                                                                                                                                        -
                                                                                                                                                                                                        public long nextLong()
                                                                                                                                                                                                        +
                                                                                                                                                                                                        public long nextLong()
                                                                                                                                                                                                        Returns a random long, which may be positive or negative.
                                                                                                                                                                                                        Overrides:
                                                                                                                                                                                                        @@ -1088,7 +1047,7 @@

                                                                                                                                                                                                        nextLong

                                                                                                                                                                                                        • nextLong

                                                                                                                                                                                                          -
                                                                                                                                                                                                          public long nextLong(long bound)
                                                                                                                                                                                                          +
                                                                                                                                                                                                          public long nextLong(long bound)
                                                                                                                                                                                                          Returns a random long below the given bound, or 0 if the bound is 0 or negative.
                                                                                                                                                                                                          @@ -1107,7 +1066,7 @@

                                                                                                                                                                                                          nextLong

                                                                                                                                                                                                          • getExpected

                                                                                                                                                                                                            -
                                                                                                                                                                                                            public double getExpected()
                                                                                                                                                                                                            +
                                                                                                                                                                                                            public double getExpected()
                                                                                                                                                                                                            Gets the current expected average for this EditRNG.
                                                                                                                                                                                                            Returns:
                                                                                                                                                                                                            @@ -1121,7 +1080,7 @@

                                                                                                                                                                                                            getExpected

                                                                                                                                                                                                            • setExpected

                                                                                                                                                                                                              -
                                                                                                                                                                                                              public void setExpected(double expected)
                                                                                                                                                                                                              +
                                                                                                                                                                                                              public void setExpected(double expected)
                                                                                                                                                                                                              Sets the expected average for random doubles this produces, which must always be between 0.1 and 0.9, and will be set to 0.5 if an invalid value is passed.
                                                                                                                                                                                                              @@ -1136,7 +1095,7 @@

                                                                                                                                                                                                              setExpected

                                                                                                                                                                                                              • getCentrality

                                                                                                                                                                                                                -
                                                                                                                                                                                                                public double getCentrality()
                                                                                                                                                                                                                +
                                                                                                                                                                                                                public double getCentrality()
                                                                                                                                                                                                                Gets the current centrality measure of this EditRNG. Centrality has several possible effects: When positive, makes the generator more likely to generate values close to the average (bell curve). @@ -1157,7 +1116,7 @@

                                                                                                                                                                                                                getCentrality

                                                                                                                                                                                                                • setCentrality

                                                                                                                                                                                                                  -
                                                                                                                                                                                                                  public void setCentrality(double centrality)
                                                                                                                                                                                                                  +
                                                                                                                                                                                                                  public void setCentrality(double centrality)
                                                                                                                                                                                                                  Gets the current centrality measure of this EditRNG. Centrality has several possible effects: When positive, makes the generator more likely to generate values close to the average (bell curve). @@ -1178,7 +1137,7 @@

                                                                                                                                                                                                                  setCentrality

                                                                                                                                                                                                                  • next

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public int next(int bits)
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    public int next(int bits)
                                                                                                                                                                                                                    Description copied from class: RNG
                                                                                                                                                                                                                    Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                                                                                    @@ -1191,138 +1150,13 @@

                                                                                                                                                                                                                    next

                                                                                                                                                                                                                  - - - -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -

                                                                                                                                                                                                                    asRandom

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public Random asRandom()
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Overrides:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    asRandom in class RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Returns:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    a Random instance that can be used for legacy compatibility
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -
                                                                                                                                                                                                                  - - - -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -

                                                                                                                                                                                                                    randomRotation

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public <T> List<T> randomRotation(List<T> l)
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Description copied from class: RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Given a List l, this selects a random element of l to be the first value in the returned list l2. It - retains the order of elements in l after that random element and makes them follow the first element in l2, and - loops around to use elements from the start of l after it has placed the last element of l into l2. -
                                                                                                                                                                                                                    - Essentially, it does what it says on the tin. It randomly rotates the List l. -
                                                                                                                                                                                                                    - If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable() - should have better performance.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Overrides:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    randomRotation in class RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Type Parameters:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    T - No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    l - A List that will not be modified by this method. All elements of this parameter will be - shared with the returned List.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Returns:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    A shallow copy of l that has been rotated so its first element has been randomly chosen - from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last - element of l, then element 1, etc.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -
                                                                                                                                                                                                                  - - - -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -

                                                                                                                                                                                                                    getRandomStartIterable

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public <T> Iterable<T> getRandomStartIterable(List<T> list)
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Description copied from class: RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Get an Iterable that starts at a random location in list and continues on through list in its current order. - Loops around to the beginning after it gets to the end, stops when it returns to the starting location. -
                                                                                                                                                                                                                    - You should not modify list while you use the returned reference. And there'll be no - ConcurrentModificationException to detect such erroneous uses.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Overrides:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    getRandomStartIterable in class RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    list - A list with a constant-time List.get(int) method (otherwise performance degrades).
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Returns:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    An Iterable that iterates over list but start at - a random index. If the chosen index is i, the iterator - will return: - list[i]; list[i+1]; ...; list[list.length() - 1]; list[0]; list[i-1]
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -
                                                                                                                                                                                                                  - - - - - -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -

                                                                                                                                                                                                                    shuffle

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public <T> T[] shuffle(T[] elements,
                                                                                                                                                                                                                    -                       T[] dest)
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Description copied from class: RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Shuffle an array using the Fisher-Yates algorithm. DO NOT give the same array for both elements and - dest, since the prior contents of dest are rearranged before elements is used, and if they refer to the same - array, then you can end up with bizarre bugs where one previously-unique item shows up dozens of times. If - possible, create a new array with the same length as elements and pass it in as dest; the returned value can be - assigned to whatever you want and will have the same items as the newly-formed array. -
                                                                                                                                                                                                                    - https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Overrides:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    shuffle in class RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Type Parameters:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    T - can be any non-primitive type.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    elements - an array of T; will not be modified
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    dest - Where to put the shuffle. If it does not have the same length as elements, this will use the - randomPortion method of this class to fill the smaller dest. MUST NOT be the same array as elements!
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Returns:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    dest after modifications
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -
                                                                                                                                                                                                                  - - - -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -

                                                                                                                                                                                                                    shuffle

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public <T> ArrayList<T> shuffle(Collection<T> elements)
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Description copied from class: RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Shuffles a Collection of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Overrides:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    shuffle in class RNG
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Type Parameters:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    T - can be any non-primitive type.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Parameters:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    elements - a Collection of T; will not be modified
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    Returns:
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    -
                                                                                                                                                                                                                  • -
                                                                                                                                                                                                                  • nextFloat

                                                                                                                                                                                                                    -
                                                                                                                                                                                                                    public float nextFloat()
                                                                                                                                                                                                                    +
                                                                                                                                                                                                                    public float nextFloat()
                                                                                                                                                                                                                    Description copied from class: RNG
                                                                                                                                                                                                                    This returns a maximum of 0.99999994 because that is the largest Float value that is less than 1.0f
                                                                                                                                                                                                                    @@ -1340,7 +1174,7 @@

                                                                                                                                                                                                                    nextFloat

                                                                                                                                                                                                                    • nextBoolean

                                                                                                                                                                                                                      -
                                                                                                                                                                                                                      public boolean nextBoolean()
                                                                                                                                                                                                                      +
                                                                                                                                                                                                                      public boolean nextBoolean()
                                                                                                                                                                                                                      Description copied from class: RNG
                                                                                                                                                                                                                      Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                                                                                      @@ -1357,7 +1191,7 @@

                                                                                                                                                                                                                      nextBoolean

                                                                                                                                                                                                                      • getRandomness

                                                                                                                                                                                                                        -
                                                                                                                                                                                                                        public RandomnessSource getRandomness()
                                                                                                                                                                                                                        +
                                                                                                                                                                                                                        public RandomnessSource getRandomness()
                                                                                                                                                                                                                        Overrides:
                                                                                                                                                                                                                        getRandomness in class RNG
                                                                                                                                                                                                                        @@ -1370,7 +1204,7 @@

                                                                                                                                                                                                                        getRandomness

                                                                                                                                                                                                                        • setRandomness

                                                                                                                                                                                                                          -
                                                                                                                                                                                                                          public void setRandomness(RandomnessSource random)
                                                                                                                                                                                                                          +
                                                                                                                                                                                                                          public void setRandomness(RandomnessSource random)
                                                                                                                                                                                                                          Overrides:
                                                                                                                                                                                                                          setRandomness in class StatefulRNG
                                                                                                                                                                                                                          @@ -1385,7 +1219,7 @@

                                                                                                                                                                                                                          setRandomness

                                                                                                                                                                                                                          • randomPortion

                                                                                                                                                                                                                            -
                                                                                                                                                                                                                            public <T> T[] randomPortion(T[] data,
                                                                                                                                                                                                                            +
                                                                                                                                                                                                                            public <T> T[] randomPortion(T[] data,
                                                                                                                                                                                                                                                          T[] output)
                                                                                                                                                                                                                            Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as it can, and then returns output. Will only use a given position in the given data at most once; does this by @@ -1413,7 +1247,7 @@

                                                                                                                                                                                                                            randomPortion

                                                                                                                                                                                                                            • randomPortion

                                                                                                                                                                                                                              -
                                                                                                                                                                                                                              public <T> List<T> randomPortion(List<T> data,
                                                                                                                                                                                                                              +
                                                                                                                                                                                                                              public <T> List<T> randomPortion(List<T> data,
                                                                                                                                                                                                                                                                int count)
                                                                                                                                                                                                                              Gets a random portion of a List and returns it as a new List. Will only use a given position in the given List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                              @@ -1436,7 +1270,7 @@

                                                                                                                                                                                                                              randomPortion

                                                                                                                                                                                                                              • randomRange

                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                public int[] randomRange(int start,
                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                public int[] randomRange(int start,
                                                                                                                                                                                                                                                          int end,
                                                                                                                                                                                                                                                          int count)
                                                                                                                                                                                                                                Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements. @@ -1459,7 +1293,7 @@

                                                                                                                                                                                                                                randomRange

                                                                                                                                                                                                                                • getRawLatest

                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                  public double getRawLatest()
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  public double getRawLatest()
                                                                                                                                                                                                                                  Gets the latest "un-biased" random double used to produce the most recent (potentially) biased random number generated for another method in this class, such as nextDouble(), between(), or getRandomElement(). This is a double between 0.0 (inclusive) and 1.0 (exclusive).
                                                                                                                                                                                                                                  @@ -1475,7 +1309,7 @@

                                                                                                                                                                                                                                  getRawLatest

                                                                                                                                                                                                                                  • copy

                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                    public RNG copy()
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    public RNG copy()
                                                                                                                                                                                                                                    Creates a copy of this StatefulRNG; it will generate the same random numbers, given the same calls in order, as this StatefulRNG at the point copy() is called. The copy will not share references with this StatefulRNG.
                                                                                                                                                                                                                                    @@ -1492,7 +1326,7 @@

                                                                                                                                                                                                                                    copy

                                                                                                                                                                                                                                    • getState

                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                      public long getState()
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      public long getState()
                                                                                                                                                                                                                                      Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                                                                                                                                                                                      Overrides:
                                                                                                                                                                                                                                      @@ -1508,7 +1342,7 @@

                                                                                                                                                                                                                                      getState

                                                                                                                                                                                                                                      • setState

                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                        public void setState(long state)
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        public void setState(long state)
                                                                                                                                                                                                                                        Sets the state of the random number generator to a given long, which will alter future random numbers this produces based on the state.
                                                                                                                                                                                                                                        @@ -1525,7 +1359,7 @@

                                                                                                                                                                                                                                        setState

                                                                                                                                                                                                                                        • toString

                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                          public String toString()
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          public String toString()
                                                                                                                                                                                                                                          Overrides:
                                                                                                                                                                                                                                          toString in class StatefulRNG
                                                                                                                                                                                                                                          @@ -1538,7 +1372,7 @@

                                                                                                                                                                                                                                          toString

                                                                                                                                                                                                                                          • equals

                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            public boolean equals(Object o)
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            public boolean equals(Object o)
                                                                                                                                                                                                                                            Overrides:
                                                                                                                                                                                                                                            equals in class RNG
                                                                                                                                                                                                                                            @@ -1551,63 +1385,20 @@

                                                                                                                                                                                                                                            equals

                                                                                                                                                                                                                                            - - - - - -
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                            • -

                                                                                                                                                                                                                                              shuffle

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public <T> T[] shuffle(T[] elements)
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays. -
                                                                                                                                                                                                                                              - https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Overrides:
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              shuffle in class RNG
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Type Parameters:
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              T - can be any non-primitive type.
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Parameters:
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              elements - an array of T; will not be modified
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Returns:
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              a shuffled copy of elements
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                            • -
                                                                                                                                                                                                                                            - - - -
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                            • -

                                                                                                                                                                                                                                              randomOrdering

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public int[] randomOrdering(int length)
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Generates a random permutation of the range from 0 (inclusive) to length (exclusive). - Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Overrides:
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              randomOrdering in class RNG
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Parameters:
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              length - the size of the ordering to produce
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              Returns:
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                            • -
                                                                                                                                                                                                                                            • nextIntHasty

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public int nextIntHasty(int bound)
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public int nextIntHasty(int bound)
                                                                                                                                                                                                                                              Returns a random non-negative integer below the given bound, or 0 if the bound is 0. Uses a slightly optimized technique. This method is considered "hasty" since it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also diff --git a/docs/squidlib-util/squidpony/squidmath/MeadNoise.html b/docs/squidlib-util/squidpony/squidmath/MeadNoise.html index 5e44e03ba4..faa4023332 100644 --- a/docs/squidlib-util/squidpony/squidmath/MeadNoise.html +++ b/docs/squidlib-util/squidpony/squidmath/MeadNoise.html @@ -386,7 +386,7 @@

                                                                                                                                                                                                                                              Method Summary

                                                                                                                                                                                                                                              static long -longFloor(float t) +longFloor(double t)
                                                                                                                                                                                                                                              Like Math.floor(double), but returns an int.
                                                                                                                                                                                                                                              @@ -447,10 +447,10 @@

                                                                                                                                                                                                                                              Method Summary

                                                                                                                                                                                                                                              int seed)  -static float -noise(float x, - float y, - int seed)  +static double +querp(double start, + double end, + double a)  static float @@ -1036,13 +1036,13 @@

                                                                                                                                                                                                                                              fastFloor

                                                                                                                                                                                                                                          - +
                                                                                                                                                                                                                                          • longFloor

                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            public static long longFloor(float t)
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            public static long longFloor(double t)
                                                                                                                                                                                                                                            Like Math.floor(double), but returns an int. Doesn't consider weird floats like INFINITY and NaN.
                                                                                                                                                                                                                                            Parameters:
                                                                                                                                                                                                                                            @@ -1058,31 +1058,31 @@

                                                                                                                                                                                                                                            longFloor

                                                                                                                                                                                                                                            • querp

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public static float querp(float start,
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public static float querp(float start,
                                                                                                                                                                                                                                                                         float end,
                                                                                                                                                                                                                                                                         float a)
                                                                                                                                                                                                                                            - +
                                                                                                                                                                                                                                            • -

                                                                                                                                                                                                                                              noise

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public static double noise(double x,
                                                                                                                                                                                                                                              -                           double y,
                                                                                                                                                                                                                                              -                           int seed)
                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                              querp

                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public static double querp(double start,
                                                                                                                                                                                                                                              +                           double end,
                                                                                                                                                                                                                                              +                           double a)
                                                                                                                                                                                                                                            - +
                                                                                                                                                                                                                                            • noise

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public static float noise(float x,
                                                                                                                                                                                                                                              -                          float y,
                                                                                                                                                                                                                                              -                          int seed)
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public static double noise(double x,
                                                                                                                                                                                                                                              +                           double y,
                                                                                                                                                                                                                                              +                           int seed)
                                                                                                                                                                                                                                            @@ -1091,7 +1091,7 @@

                                                                                                                                                                                                                                            noise

                                                                                                                                                                                                                                            • noise

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public static double noise(double x,
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public static double noise(double x,
                                                                                                                                                                                                                                                                          double y,
                                                                                                                                                                                                                                                                          double z,
                                                                                                                                                                                                                                                                          int seed)
                                                                                                                                                                                                                                              @@ -1103,7 +1103,7 @@

                                                                                                                                                                                                                                              noise

                                                                                                                                                                                                                                              • noise

                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                public static float noise(float x,
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                public static float noise(float x,
                                                                                                                                                                                                                                                                           float y,
                                                                                                                                                                                                                                                                           float z,
                                                                                                                                                                                                                                                                           int seed)
                                                                                                                                                                                                                                                @@ -1115,7 +1115,7 @@

                                                                                                                                                                                                                                                noise

                                                                                                                                                                                                                                                • noise

                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                  public static double noise(double x,
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  public static double noise(double x,
                                                                                                                                                                                                                                                                              double y,
                                                                                                                                                                                                                                                                              double z,
                                                                                                                                                                                                                                                                              double w,
                                                                                                                                                                                                                                                  @@ -1128,7 +1128,7 @@ 

                                                                                                                                                                                                                                                  noise

                                                                                                                                                                                                                                                  • noise

                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                    public static double noise(float x,
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    public static double noise(float x,
                                                                                                                                                                                                                                                                                float y,
                                                                                                                                                                                                                                                                                float z,
                                                                                                                                                                                                                                                                                float w,
                                                                                                                                                                                                                                                    @@ -1141,7 +1141,7 @@ 

                                                                                                                                                                                                                                                    noise

                                                                                                                                                                                                                                                    • noise

                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                      public static double noise(double x,
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      public static double noise(double x,
                                                                                                                                                                                                                                                                                  double y,
                                                                                                                                                                                                                                                                                  double z,
                                                                                                                                                                                                                                                                                  double w,
                                                                                                                                                                                                                                                      @@ -1156,7 +1156,7 @@ 

                                                                                                                                                                                                                                                      noise

                                                                                                                                                                                                                                                      • noise

                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                        public static double noise(float x,
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        public static double noise(float x,
                                                                                                                                                                                                                                                                                    float y,
                                                                                                                                                                                                                                                                                    float z,
                                                                                                                                                                                                                                                                                    float w,
                                                                                                                                                                                                                                                        diff --git a/docs/squidlib-util/squidpony/squidmath/RNG.CustomRandom.html b/docs/squidlib-util/squidpony/squidmath/RNG.CustomRandom.html
                                                                                                                                                                                                                                                        index d2465b8b1d..568548e8eb 100644
                                                                                                                                                                                                                                                        --- a/docs/squidlib-util/squidpony/squidmath/RNG.CustomRandom.html
                                                                                                                                                                                                                                                        +++ b/docs/squidlib-util/squidpony/squidmath/RNG.CustomRandom.html
                                                                                                                                                                                                                                                        @@ -122,7 +122,7 @@ 

                                                                                                                                                                                                                                                        Class RNG.CustomRandom



                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            public static class RNG.CustomRandom
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            public static class RNG.CustomRandom
                                                                                                                                                                                                                                             extends Random
                                                                                                                                                                                                                                            A subclass of java.util.Random that uses a RandomnessSource supplied by the user instead of the default.
                                                                                                                                                                                                                                            @@ -214,7 +214,7 @@

                                                                                                                                                                                                                                            Constructor Detail

                                                                                                                                                                                                                                            • CustomRandom

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public CustomRandom()
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public CustomRandom()
                                                                                                                                                                                                                                              Creates a new random number generator. This constructor uses a LightRNG with a random seed.
                                                                                                                                                                                                                                            • @@ -225,7 +225,7 @@

                                                                                                                                                                                                                                              CustomRandom

                                                                                                                                                                                                                                              • CustomRandom

                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                public CustomRandom(RandomnessSource randomnessSource)
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                public CustomRandom(RandomnessSource randomnessSource)
                                                                                                                                                                                                                                                Creates a new random number generator. This constructor uses the seed of the given RandomnessSource if it has been seeded.
                                                                                                                                                                                                                                                @@ -248,7 +248,7 @@

                                                                                                                                                                                                                                                Method Detail

                                                                                                                                                                                                                                                • next

                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                  protected int next(int bits)
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  protected int next(int bits)
                                                                                                                                                                                                                                                  Generates the next pseudorandom number. Subclasses should override this, as this is used by all other methods.

                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/squidpony/squidmath/RNG.html b/docs/squidlib-util/squidpony/squidmath/RNG.html index 57fe794831..84c21fd298 100644 --- a/docs/squidlib-util/squidpony/squidmath/RNG.html +++ b/docs/squidlib-util/squidpony/squidmath/RNG.html @@ -113,11 +113,11 @@

                                                                                                                                                                                                                                                  Class RNG

                                                                                                                                                                                                                                                Direct Known Subclasses:
                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                DharmaRNG, StatefulRNG
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                CriticalRNG, DharmaRNG, StatefulRNG


                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                public class RNG
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                public class RNG
                                                                                                                                                                                                                                                 extends Object
                                                                                                                                                                                                                                                 implements Serializable
                                                                                                                                                                                                                                                A wrapper class for working with random number generators in a more friendly way. @@ -272,23 +272,23 @@

                                                                                                                                                                                                                                                Constructor Summary

                                                                                                                                                                                                                                                +RNG(CharSequence seedString) +
                                                                                                                                                                                                                                                String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a + seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, + tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                + + + RNG(long seed)
                                                                                                                                                                                                                                                Seeded constructor; uses LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                - + RNG(RandomnessSource random)
                                                                                                                                                                                                                                                Uses the provided source of randomness for all calculations.
                                                                                                                                                                                                                                                - -RNG(String seedString) -
                                                                                                                                                                                                                                                String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a - seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, - tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                - -
                                                                                                                                                                                                                                              @@ -638,7 +638,7 @@

                                                                                                                                                                                                                                              Field Detail

                                                                                                                                                                                                                                              • DOUBLE_UNIT

                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                protected static final double DOUBLE_UNIT
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                protected static final double DOUBLE_UNIT
                                                                                                                                                                                                                                                A very small multiplier used to reduce random numbers to from the [0.0,9007199254740991.0) range to the [0.0,1.0) range. Equivalent to 1.0 / (1 << 53), if that number makes more sense to you, but the source uses the hexadecimal double literal 0x1p-53. The hex literals are a nice "hidden feature" of Java @@ -655,7 +655,7 @@

                                                                                                                                                                                                                                                DOUBLE_UNIT

                                                                                                                                                                                                                                              @@ -738,18 +740,18 @@

                                                                                                                                                                                                                                              RNG

                                                                                                                                                                                                                                              • RNG

                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                public RNG(long seed)
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                public RNG(long seed)
                                                                                                                                                                                                                                                Seeded constructor; uses LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                              - +
                                                                                                                                                                                                                                              • RNG

                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                public RNG(String seedString)
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                public RNG(CharSequence seedString)
                                                                                                                                                                                                                                                String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                @@ -761,9 +763,10 @@

                                                                                                                                                                                                                                                RNG

                                                                                                                                                                                                                                                • RNG

                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                  public RNG(RandomnessSource random)
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  public RNG(RandomnessSource random)
                                                                                                                                                                                                                                                  Uses the provided source of randomness for all calculations. This - constructor should be used if an alternate RandomnessSource other than LightRNG is desirable.
                                                                                                                                                                                                                                                  + constructor should be used if an alternate RandomnessSource other than LightRNG is desirable. + If the parameter is null, this is equivalent to using RNG() as the constructor.
                                                                                                                                                                                                                                Parameters:
                                                                                                                                                                                                                                random - the source of pseudo-randomness, such as a MersenneTwister or SobolQRNG object
                                                                                                                                                                                                                                @@ -784,7 +787,7 @@

                                                                                                                                                                                                                                Method Detail

                                                                                                                                                                                                                                • asRandom

                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                  public Random asRandom()
                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                  public Random asRandom()
                                                                                                                                                                                                                                  Returns:
                                                                                                                                                                                                                                  a Random instance that can be used for legacy compatibility
                                                                                                                                                                                                                                  @@ -797,7 +800,7 @@

                                                                                                                                                                                                                                  asRandom

                                                                                                                                                                                                                                  • between

                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                    public double between(double min,
                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                    public double between(double min,
                                                                                                                                                                                                                                                           double max)
                                                                                                                                                                                                                                    Returns a value from an even distribution from min (inclusive) to max (exclusive).
                                                                                                                                                                                                                                    @@ -816,7 +819,7 @@

                                                                                                                                                                                                                                    between

                                                                                                                                                                                                                                    • between

                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                      public int between(int min,
                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                      public int between(int min,
                                                                                                                                                                                                                                                          int max)
                                                                                                                                                                                                                                      Returns a value between min (inclusive) and max (exclusive).

                                                                                                                                                                                                                                      @@ -837,7 +840,7 @@

                                                                                                                                                                                                                                      between

                                                                                                                                                                                                                                      • between

                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                        public long between(long min,
                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                        public long between(long min,
                                                                                                                                                                                                                                                             long max)
                                                                                                                                                                                                                                        Returns a value between min (inclusive) and max (exclusive).

                                                                                                                                                                                                                                        @@ -858,7 +861,7 @@

                                                                                                                                                                                                                                        between

                                                                                                                                                                                                                                        • betweenWeighted

                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                          public int betweenWeighted(int min,
                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                          public int betweenWeighted(int min,
                                                                                                                                                                                                                                                                      int max,
                                                                                                                                                                                                                                                                      int samples)
                                                                                                                                                                                                                                          Returns the average of a number of randomly selected numbers from the @@ -887,7 +890,7 @@

                                                                                                                                                                                                                                          betweenWeighted

                                                                                                                                                                                                                                          • getRandomElement

                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                            public <T> T getRandomElement(T[] array)
                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                            public <T> T getRandomElement(T[] array)
                                                                                                                                                                                                                                            Returns a random element from the provided array and maintains object type.
                                                                                                                                                                                                                                            @@ -906,7 +909,7 @@

                                                                                                                                                                                                                                            getRandomElement

                                                                                                                                                                                                                                            • getRandomElement

                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                              public <T> T getRandomElement(List<T> list)
                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                              public <T> T getRandomElement(List<T> list)
                                                                                                                                                                                                                                              Returns a random element from the provided list. If the list is empty then null is returned.
                                                                                                                                                                                                                                              @@ -925,7 +928,7 @@

                                                                                                                                                                                                                                              getRandomElement

                                                                                                                                                                                                                                              • getRandomElement

                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                public short getRandomElement(ShortSet set)
                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                public short getRandomElement(ShortSet set)
                                                                                                                                                                                                                                                Returns a random element from the provided ShortSet. If the set is empty then an exception is thrown.

                                                                                                                                                                                                                                                @@ -947,7 +950,7 @@

                                                                                                                                                                                                                                                getRandomElement

                                                                                                                                                                                                                                                • getRandomElement

                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                  public <T> T getRandomElement(Collection<T> coll)
                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                  public <T> T getRandomElement(Collection<T> coll)
                                                                                                                                                                                                                                                  Returns a random element from the provided Collection, which should have predictable iteration order if you want predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted @@ -976,7 +979,7 @@

                                                                                                                                                                                                                                                  getRandomElement

                                                                                                                                                                                                                                                  • randomRotation

                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                    public <T> List<T> randomRotation(List<T> l)
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    public <T> List<T> randomRotation(List<T> l)
                                                                                                                                                                                                                                                    Given a List l, this selects a random element of l to be the first value in the returned list l2. It retains the order of elements in l after that random element and makes them follow the first element in l2, and loops around to use elements from the start of l after it has placed the last element of l into l2. @@ -984,7 +987,8 @@

                                                                                                                                                                                                                                                    randomRotation

                                                                                                                                                                                                                                                    Essentially, it does what it says on the tin. It randomly rotates the List l.
                                                                                                                                                                                                                                                    If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable() - should have better performance.
                                                                                                                                                                                                                                                    + should have better performance. This was GWT incompatible before GWT 2.8.0 became the version SquidLib uses; now + this method works fine with GWT.
                                                                                                                                                                                                                                                  Type Parameters:
                                                                                                                                                                                                                                                  T - No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                                                                                                                                                                                  @@ -1004,7 +1008,7 @@

                                                                                                                                                                                                                                                  randomRotation

                                                                                                                                                                                                                                                  • getRandomStartIterable

                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                    public <T> Iterable<T> getRandomStartIterable(List<T> list)
                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                    public <T> Iterable<T> getRandomStartIterable(List<T> list)
                                                                                                                                                                                                                                                    Get an Iterable that starts at a random location in list and continues on through list in its current order. Loops around to the beginning after it gets to the end, stops when it returns to the starting location.
                                                                                                                                                                                                                                                    @@ -1027,7 +1031,7 @@

                                                                                                                                                                                                                                                    getRandomStartIterable

                                                                                                                                                                                                                                                    • getRandomCellsIterable

                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                      public Iterable<CoordgetRandomCellsIterable(int width,
                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                      public Iterable<CoordgetRandomCellsIterable(int width,
                                                                                                                                                                                                                                                                                                     int height,
                                                                                                                                                                                                                                                                                                     int size)
                                                                                                                                                                                                                                                      Use that to get random cells in a rectangular map.
                                                                                                                                                                                                                                                      @@ -1050,7 +1054,7 @@

                                                                                                                                                                                                                                                      getRandomCellsIterable

                                                                                                                                                                                                                                                      • getRandomUniqueCells

                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                        public Coord[] getRandomUniqueCells(int startX,
                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                        public Coord[] getRandomUniqueCells(int startX,
                                                                                                                                                                                                                                                                                             int startY,
                                                                                                                                                                                                                                                                                             int width,
                                                                                                                                                                                                                                                                                             int height)
                                                                                                                                                                                                                                                        @@ -1073,7 +1077,7 @@

                                                                                                                                                                                                                                                        getRandomUniqueCells

                                                                                                                                                                                                                                                        • getRandomUniqueCells

                                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                                          public Coord[] getRandomUniqueCells(int startX,
                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                          public Coord[] getRandomUniqueCells(int startX,
                                                                                                                                                                                                                                                                                               int startY,
                                                                                                                                                                                                                                                                                               int width,
                                                                                                                                                                                                                                                                                               int height,
                                                                                                                                                                                                                                                          @@ -1099,7 +1103,7 @@ 

                                                                                                                                                                                                                                                          getRandomUniqueCells

                                                                                                                                                                                                                                                          • getRandomUniqueCells

                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                            public Coord[] getRandomUniqueCells(int startX,
                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                            public Coord[] getRandomUniqueCells(int startX,
                                                                                                                                                                                                                                                                                                 int startY,
                                                                                                                                                                                                                                                                                                 int width,
                                                                                                                                                                                                                                                                                                 int height,
                                                                                                                                                                                                                                                            @@ -1128,7 +1132,7 @@ 

                                                                                                                                                                                                                                                            getRandomUniqueCells

                                                                                                                                                                                                                                                            • shuffle

                                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                                              public <T> T[] shuffle(T[] elements)
                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                              public <T> T[] shuffle(T[] elements)
                                                                                                                                                                                                                                                              Shuffle an array using the Fisher-Yates algorithm and returns a shuffled copy. GWT-compatible since GWT 2.8.0, which is the default if you use libGDX 1.9.5 or higher.
                                                                                                                                                                                                                                                              @@ -1151,7 +1155,7 @@

                                                                                                                                                                                                                                                              shuffle

                                                                                                                                                                                                                                                              • shuffleInPlace

                                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                                public <T> T[] shuffleInPlace(T[] elements)
                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                public <T> T[] shuffleInPlace(T[] elements)
                                                                                                                                                                                                                                                                Shuffles an array in place using the Fisher-Yates algorithm. If you don't want the array modified, use shuffle(Object[], Object[]). Unlike shuffle(Object[]), this is GWT-compatible. @@ -1175,7 +1179,7 @@

                                                                                                                                                                                                                                                                shuffleInPlace

                                                                                                                                                                                                                                                                • shuffle

                                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                                  public <T> T[] shuffle(T[] elements,
                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                  public <T> T[] shuffle(T[] elements,
                                                                                                                                                                                                                                                                                          T[] dest)
                                                                                                                                                                                                                                                                  Shuffle an array using the Fisher-Yates algorithm. DO NOT give the same array for both elements and dest, since the prior contents of dest are rearranged before elements is used, and if they refer to the same @@ -1202,7 +1206,7 @@

                                                                                                                                                                                                                                                                  shuffle

                                                                                                                                                                                                                                                                  • shuffle

                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                    public <T> ArrayList<T> shuffle(Collection<T> elements)
                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                    public <T> ArrayList<T> shuffle(Collection<T> elements)
                                                                                                                                                                                                                                                                    Shuffles a Collection of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                                                                                                                                    Type Parameters:
                                                                                                                                                                                                                                                                    @@ -1220,7 +1224,7 @@

                                                                                                                                                                                                                                                                    shuffle

                                                                                                                                                                                                                                                                    • shuffle

                                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                                      public <T> ArrayList<T> shuffle(Collection<T> elements,
                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                      public <T> ArrayList<T> shuffle(Collection<T> elements,
                                                                                                                                                                                                                                                                                                       ArrayList<T> buf)
                                                                                                                                                                                                                                                                      Shuffles a Collection of T using the Fisher-Yates algorithm. The result is allocated if buf is null or if buf isn't empty, @@ -1241,7 +1245,7 @@

                                                                                                                                                                                                                                                                      shuffle

                                                                                                                                                                                                                                                                      • randomOrdering

                                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                                        public int[] randomOrdering(int length)
                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                        public int[] randomOrdering(int length)
                                                                                                                                                                                                                                                                        Generates a random permutation of the range from 0 (inclusive) to length (exclusive). Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                        @@ -1258,7 +1262,7 @@

                                                                                                                                                                                                                                                                        randomOrdering

                                                                                                                                                                                                                                                                        • randomOrdering

                                                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                                                          public int[] randomOrdering(int length,
                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                          public int[] randomOrdering(int length,
                                                                                                                                                                                                                                                                                                       int[] dest)
                                                                                                                                                                                                                                                                          Generates a random permutation of the range from 0 (inclusive) to length (exclusive) and stores it in the dest parameter, avoiding allocations. @@ -1280,7 +1284,7 @@

                                                                                                                                                                                                                                                                          randomOrdering

                                                                                                                                                                                                                                                                          • randomPortion

                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                            public <T> T[] randomPortion(T[] data,
                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                            public <T> T[] randomPortion(T[] data,
                                                                                                                                                                                                                                                                                                          T[] output)
                                                                                                                                                                                                                                                                            Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as it can, and then returns output. Will only use a given position in the given data at most once; does this by @@ -1307,7 +1311,7 @@

                                                                                                                                                                                                                                                                            randomPortion

                                                                                                                                                                                                                                                                            • randomPortion

                                                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                                                              public <T> List<T> randomPortion(List<T> data,
                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                              public <T> List<T> randomPortion(List<T> data,
                                                                                                                                                                                                                                                                                                                int count)
                                                                                                                                                                                                                                                                              Gets a random portion of a List and returns it as a new List. Will only use a given position in the given List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                              @@ -1328,7 +1332,7 @@

                                                                                                                                                                                                                                                                              randomPortion

                                                                                                                                                                                                                                                                              • randomRange

                                                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                                                public int[] randomRange(int start,
                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                public int[] randomRange(int start,
                                                                                                                                                                                                                                                                                                          int end,
                                                                                                                                                                                                                                                                                                          int count)
                                                                                                                                                                                                                                                                                Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements. @@ -1349,7 +1353,7 @@

                                                                                                                                                                                                                                                                                randomRange

                                                                                                                                                                                                                                                                                • nextGaussian

                                                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                                                  public double nextGaussian()
                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                  public double nextGaussian()
                                                                                                                                                                                                                                                                                  Returns:
                                                                                                                                                                                                                                                                                  a value from the gaussian distribution
                                                                                                                                                                                                                                                                                  @@ -1362,7 +1366,7 @@

                                                                                                                                                                                                                                                                                  nextGaussian

                                                                                                                                                                                                                                                                                  • nextDouble

                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                    public double nextDouble()
                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                    public double nextDouble()
                                                                                                                                                                                                                                                                                    This returns a maximum of 0.9999999999999999 because that is the largest Double value that is less than 1.0
                                                                                                                                                                                                                                                                                    @@ -1377,7 +1381,7 @@

                                                                                                                                                                                                                                                                                    nextDouble

                                                                                                                                                                                                                                                                                    • nextDouble

                                                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                                                      public double nextDouble(double max)
                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                      public double nextDouble(double max)
                                                                                                                                                                                                                                                                                      This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                      Returns:
                                                                                                                                                                                                                                                                                      @@ -1391,7 +1395,7 @@

                                                                                                                                                                                                                                                                                      nextDouble

                                                                                                                                                                                                                                                                                      • nextFloat

                                                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                                                        public float nextFloat()
                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                        public float nextFloat()
                                                                                                                                                                                                                                                                                        This returns a maximum of 0.99999994 because that is the largest Float value that is less than 1.0f
                                                                                                                                                                                                                                                                                        @@ -1406,7 +1410,7 @@

                                                                                                                                                                                                                                                                                        nextFloat

                                                                                                                                                                                                                                                                                        • nextBoolean

                                                                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                                                                          public boolean nextBoolean()
                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                          public boolean nextBoolean()
                                                                                                                                                                                                                                                                                          Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                                                                                                                                                          Returns:
                                                                                                                                                                                                                                                                                          @@ -1420,7 +1424,7 @@

                                                                                                                                                                                                                                                                                          nextBoolean

                                                                                                                                                                                                                                                                                          • nextLong

                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                            public long nextLong()
                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                            public long nextLong()
                                                                                                                                                                                                                                                                                            Get a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                            Returns:
                                                                                                                                                                                                                                                                                            @@ -1434,7 +1438,7 @@

                                                                                                                                                                                                                                                                                            nextLong

                                                                                                                                                                                                                                                                                            • nextLong

                                                                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                                                                              public long nextLong(long bound)
                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                              public long nextLong(long bound)
                                                                                                                                                                                                                                                                                              Returns a random long below the given bound, or 0 if the bound is 0 or negative.
                                                                                                                                                                                                                                                                                              @@ -1451,7 +1455,7 @@

                                                                                                                                                                                                                                                                                              nextLong

                                                                                                                                                                                                                                                                                              • nextInt

                                                                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                                                                public int nextInt(int bound)
                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                public int nextInt(int bound)
                                                                                                                                                                                                                                                                                                Returns a random non-negative integer below the given bound, or 0 if the bound is 0 or negative.
                                                                                                                                                                                                                                                                                                @@ -1468,7 +1472,7 @@

                                                                                                                                                                                                                                                                                                nextInt

                                                                                                                                                                                                                                                                                                • nextIntHasty

                                                                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                                                                  public int nextIntHasty(int bound)
                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                  public int nextIntHasty(int bound)
                                                                                                                                                                                                                                                                                                  Returns a random non-negative integer below the given bound, or 0 if the bound is 0. Uses an aggressively optimized technique that has some bias, but mostly for values of bound over 1 billion. This method is considered "hasty" since it should be faster than @@ -1491,7 +1495,7 @@

                                                                                                                                                                                                                                                                                                  nextIntHasty

                                                                                                                                                                                                                                                                                                  • nextBytes

                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                    public void nextBytes(byte[] bytes)
                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                    public void nextBytes(byte[] bytes)
                                                                                                                                                                                                                                                                                                    Generates random bytes and places them into the given byte array, modifying it in-place. The number of random bytes produced is equal to the length of the byte array. Unlike the method in java.util.Random, this generates 8 bytes at a time, which can be more efficient @@ -1513,7 +1517,7 @@

                                                                                                                                                                                                                                                                                                    nextBytes

                                                                                                                                                                                                                                                                                                    • nextCoord

                                                                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                                                                      public Coord nextCoord(int width,
                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                      public Coord nextCoord(int width,
                                                                                                                                                                                                                                                                                                                              int height)
                                                                                                                                                                                                                                                                                                      Gets a random Coord that has x between 0 (inclusive) and width (exclusive) and y between 0 (inclusive) and height (exclusive). This makes one call to randomLong to generate (more than) 31 random bits for @@ -1540,7 +1544,7 @@

                                                                                                                                                                                                                                                                                                      nextCoord

                                                                                                                                                                                                                                                                                                      • nextInt

                                                                                                                                                                                                                                                                                                        -
                                                                                                                                                                                                                                                                                                        public int nextInt()
                                                                                                                                                                                                                                                                                                        +
                                                                                                                                                                                                                                                                                                        public int nextInt()
                                                                                                                                                                                                                                                                                                        Get a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                        Returns:
                                                                                                                                                                                                                                                                                                        @@ -1554,7 +1558,7 @@

                                                                                                                                                                                                                                                                                                        nextInt

                                                                                                                                                                                                                                                                                                        • next

                                                                                                                                                                                                                                                                                                          -
                                                                                                                                                                                                                                                                                                          public int next(int bits)
                                                                                                                                                                                                                                                                                                          +
                                                                                                                                                                                                                                                                                                          public int next(int bits)
                                                                                                                                                                                                                                                                                                          Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                                                                                                                                                                          Parameters:
                                                                                                                                                                                                                                                                                                          @@ -1570,7 +1574,7 @@

                                                                                                                                                                                                                                                                                                          next

                                                                                                                                                                                                                                                                                                          @@ -1579,7 +1583,7 @@

                                                                                                                                                                                                                                                                                                          getRandomness

                                                                                                                                                                                                                                                                                                          @@ -1588,7 +1592,7 @@

                                                                                                                                                                                                                                                                                                          setRandomness

                                                                                                                                                                                                                                                                                                          • copy

                                                                                                                                                                                                                                                                                                            -
                                                                                                                                                                                                                                                                                                            public RNG copy()
                                                                                                                                                                                                                                                                                                            +
                                                                                                                                                                                                                                                                                                            public RNG copy()
                                                                                                                                                                                                                                                                                                            Creates a copy of this RNG; it will generate the same random numbers, given the same calls in order, as this RNG at the point copy() is called. The copy will not share references with this RNG.
                                                                                                                                                                                                                                                                                                            @@ -1603,7 +1607,7 @@

                                                                                                                                                                                                                                                                                                            copy

                                                                                                                                                                                                                                                                                                            • approximateBits

                                                                                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                                                                                              public long approximateBits(int bitCount)
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              public long approximateBits(int bitCount)
                                                                                                                                                                                                                                                                                                              Generates a random 64-bit long with a number of '1' bits (Hamming weight) approximately equal to bitCount. For example, calling this with a parameter of 32 will be equivalent to calling nextLong() on this object's RandomnessSource (it doesn't consider overridden nextLong() methods, where present, on subclasses of RNG). @@ -1632,7 +1636,7 @@

                                                                                                                                                                                                                                                                                                              approximateBits

                                                                                                                                                                                                                                                                                                              • randomInterleave

                                                                                                                                                                                                                                                                                                                -
                                                                                                                                                                                                                                                                                                                public long randomInterleave()
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                                public long randomInterleave()
                                                                                                                                                                                                                                                                                                                Gets a somewhat-random long with exactly 32 bits set; in each pair of bits starting at bit 0 and bit 1, then bit 2 and bit 3, up to bit 62 and bit 3, one bit will be 1 and one bit will be 0 in each pair.
                                                                                                                                                                                                                                                                                                                @@ -1647,7 +1651,7 @@

                                                                                                                                                                                                                                                                                                                randomInterleave

                                                                                                                                                                                                                                                                                                                • toString

                                                                                                                                                                                                                                                                                                                  -
                                                                                                                                                                                                                                                                                                                  public String toString()
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  public String toString()
                                                                                                                                                                                                                                                                                                                  Overrides:
                                                                                                                                                                                                                                                                                                                  toString in class Object
                                                                                                                                                                                                                                                                                                                  @@ -1660,7 +1664,7 @@

                                                                                                                                                                                                                                                                                                                  toString

                                                                                                                                                                                                                                                                                                                  • equals

                                                                                                                                                                                                                                                                                                                    -
                                                                                                                                                                                                                                                                                                                    public boolean equals(Object o)
                                                                                                                                                                                                                                                                                                                    +
                                                                                                                                                                                                                                                                                                                    public boolean equals(Object o)
                                                                                                                                                                                                                                                                                                                    Overrides:
                                                                                                                                                                                                                                                                                                                    equals in class Object
                                                                                                                                                                                                                                                                                                                    @@ -1673,7 +1677,7 @@

                                                                                                                                                                                                                                                                                                                    equals

                                                                                                                                                                                                                                                                                                                    • hashCode

                                                                                                                                                                                                                                                                                                                      -
                                                                                                                                                                                                                                                                                                                      public int hashCode()
                                                                                                                                                                                                                                                                                                                      +
                                                                                                                                                                                                                                                                                                                      public int hashCode()
                                                                                                                                                                                                                                                                                                                      Overrides:
                                                                                                                                                                                                                                                                                                                      hashCode in class Object
                                                                                                                                                                                                                                                                                                                      diff --git a/docs/squidlib-util/squidpony/squidmath/StatefulRNG.html b/docs/squidlib-util/squidpony/squidmath/StatefulRNG.html index 93d1d0109f..c7e6bff41f 100644 --- a/docs/squidlib-util/squidpony/squidmath/StatefulRNG.html +++ b/docs/squidlib-util/squidpony/squidmath/StatefulRNG.html @@ -184,19 +184,19 @@

                                                                                                                                                                                                                                                                                                                      Constructor Summary

                                                                                                                                                                                                                                                                                                                      StatefulRNG()  +StatefulRNG(CharSequence seedString) +
                                                                                                                                                                                                                                                                                                                      String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low + period (which rarely matters for games), and has good speed and tiny state size.
                                                                                                                                                                                                                                                                                                                      + + + StatefulRNG(long seed)
                                                                                                                                                                                                                                                                                                                      Seeded constructor uses LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size.
                                                                                                                                                                                                                                                                                                                      - -StatefulRNG(RandomnessSource random)  - -StatefulRNG(String seedString) -
                                                                                                                                                                                                                                                                                                                      String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low - period (which rarely matters for games), and has good speed and tiny state size.
                                                                                                                                                                                                                                                                                                                      - +StatefulRNG(RandomnessSource random) 
                                                                                                                                                                                                                                                                                                                    • @@ -299,13 +299,13 @@

                                                                                                                                                                                                                                                                                                                      StatefulRNG

                                                                                                                                                                                                                                                                                                                      and has good speed and tiny state size.
                                                                                                                                                                                                                                                                                                            - +
                                                                                                                                                                                                                                                                                                            • StatefulRNG

                                                                                                                                                                                                                                                                                                              -
                                                                                                                                                                                                                                                                                                              public StatefulRNG(String seedString)
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              public StatefulRNG(CharSequence seedString)
                                                                                                                                                                                                                                                                                                              String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed and tiny state size. diff --git a/docs/squidlib-util/squidpony/squidmath/class-use/CriticalRNG.html b/docs/squidlib-util/squidpony/squidmath/class-use/CriticalRNG.html new file mode 100644 index 0000000000..d71c9085f0 --- /dev/null +++ b/docs/squidlib-util/squidpony/squidmath/class-use/CriticalRNG.html @@ -0,0 +1,125 @@ + + + + + + +Uses of Class squidpony.squidmath.CriticalRNG (squidlib-util 3.0.0-SNAPSHOT) + + + + + + + + + + +
                                                                                                                                                                                                                                                                                                              +

                                                                                                                                                                                                                                                                                                              Uses of Class
                                                                                                                                                                                                                                                                                                              squidpony.squidmath.CriticalRNG

                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              No usage of squidpony.squidmath.CriticalRNG
                                                                                                                                                                                                                                                                                                              + + + + +

                                                                                                                                                                                                                                                                                                              Copyright © 2012–2017. All rights reserved.

                                                                                                                                                                                                                                                                                                              + + diff --git a/docs/squidlib-util/squidpony/squidmath/class-use/RNG.html b/docs/squidlib-util/squidpony/squidmath/class-use/RNG.html index cb398b01ab..c3f7e15a92 100644 --- a/docs/squidlib-util/squidpony/squidmath/class-use/RNG.html +++ b/docs/squidlib-util/squidpony/squidmath/class-use/RNG.html @@ -1007,23 +1007,29 @@

                                                                                                                                                                                                                                                                                                              Uses of class  +CriticalRNG +
                                                                                                                                                                                                                                                                                                              A type of RNG that can generate values larger or smaller than the normal maximum or minimum, based on a modifier.
                                                                                                                                                                                                                                                                                                              + + + +class  DeckRNG
                                                                                                                                                                                                                                                                                                              An RNG variant that has 16 possible grades of value it can produce and shuffles them like a deck of cards.
                                                                                                                                                                                                                                                                                                              - + class  DharmaRNG
                                                                                                                                                                                                                                                                                                              An alteration to a RandomnessSource that attempts to produce values that are perceived as fair to an imperfect user.
                                                                                                                                                                                                                                                                                                              - + class  EditRNG
                                                                                                                                                                                                                                                                                                              A subclass of StatefulRNG (and thus RNG) that allows customizing many parts of the random number generation.
                                                                                                                                                                                                                                                                                                              - + class  StatefulRNG
                                                                                                                                                                                                                                                                                                              A slight variant on RNG that always uses a stateful RandomessSource and so can have its state diff --git a/docs/squidlib-util/squidpony/squidmath/class-use/RandomnessSource.html b/docs/squidlib-util/squidpony/squidmath/class-use/RandomnessSource.html index 5a1b5abd0e..3783e57ba8 100644 --- a/docs/squidlib-util/squidpony/squidmath/class-use/RandomnessSource.html +++ b/docs/squidlib-util/squidpony/squidmath/class-use/RandomnessSource.html @@ -588,6 +588,17 @@

                                                                                                                                                                                                                                                                                                              Uses of +CriticalRNG(RandomnessSource random) +
                                                                                                                                                                                                                                                                                                              Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource.
                                                                                                                                                                                                                                                                                                              + + + +CriticalRNG(RandomnessSource random, + float luck) +
                                                                                                                                                                                                                                                                                                              Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource.
                                                                                                                                                                                                                                                                                                              + + + CustomRandom(RandomnessSource randomnessSource)
                                                                                                                                                                                                                                                                                                              Creates a new random number generator.
                                                                                                                                                                                                                                                                                                              diff --git a/docs/squidlib-util/squidpony/squidmath/class-use/ShortSet.html b/docs/squidlib-util/squidpony/squidmath/class-use/ShortSet.html index a19123fee5..2fa2c1a452 100644 --- a/docs/squidlib-util/squidpony/squidmath/class-use/ShortSet.html +++ b/docs/squidlib-util/squidpony/squidmath/class-use/ShortSet.html @@ -145,6 +145,10 @@

                                                                                                                                                                                                                                                                                                              Uses of Returns a random element from the provided ShortSet.

                                                                                                                                                                                                                                                                                                              + +short +CriticalRNG.getRandomElement(ShortSet set)  + diff --git a/docs/squidlib-util/squidpony/squidmath/package-frame.html b/docs/squidlib-util/squidpony/squidmath/package-frame.html index 37693e87d3..1624f47a0c 100644 --- a/docs/squidlib-util/squidpony/squidmath/package-frame.html +++ b/docs/squidlib-util/squidpony/squidmath/package-frame.html @@ -40,6 +40,7 @@

                                                                                                                                                                                                                                                                                                              Classes

                                                                                                                                                                                                                                                                                                            • CoordDouble
                                                                                                                                                                                                                                                                                                            • CoordPacker
                                                                                                                                                                                                                                                                                                            • CosmicNumbering
                                                                                                                                                                                                                                                                                                            • +
                                                                                                                                                                                                                                                                                                            • CriticalRNG
                                                                                                                                                                                                                                                                                                            • CrossHash
                                                                                                                                                                                                                                                                                                            • CrossHash.Falcon
                                                                                                                                                                                                                                                                                                            • CrossHash.Lightning
                                                                                                                                                                                                                                                                                                            • diff --git a/docs/squidlib-util/squidpony/squidmath/package-summary.html b/docs/squidlib-util/squidpony/squidmath/package-summary.html index 0b7463bdc5..22d094d6ea 100644 --- a/docs/squidlib-util/squidpony/squidmath/package-summary.html +++ b/docs/squidlib-util/squidpony/squidmath/package-summary.html @@ -244,12 +244,18 @@

                                                                                                                                                                                                                                                                                                              Package squidpony.squidmath

                                                                                                                                                                                                                                                                                                              + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - +
                                                                                                                                                                                                                                                                                                              CriticalRNG +
                                                                                                                                                                                                                                                                                                              A type of RNG that can generate values larger or smaller than the normal maximum or minimum, based on a modifier.
                                                                                                                                                                                                                                                                                                              +
                                                                                                                                                                                                                                                                                                              CrossHash
                                                                                                                                                                                                                                                                                                              Simple hashing functions that we can rely on staying the same cross-platform.
                                                                                                                                                                                                                                                                                                              CrossHash.Falcon
                                                                                                                                                                                                                                                                                                              An alternative hashing function that is slightly faster than CrossHash.Lightning, drastically @@ -259,179 +265,179 @@

                                                                                                                                                                                                                                                                                                              Package squidpony.squidmath

                                                                                                                                                                                                                                                                                                              in their input arrays, though the hash64 variants don't have this issue).
                                                                                                                                                                                                                                                                                                              CrossHash.Lightning
                                                                                                                                                                                                                                                                                                              A quick, simple hashing function that seems to have good results.
                                                                                                                                                                                                                                                                                                              CrossHash.Mist
                                                                                                                                                                                                                                                                                                              A whole cluster of Wisp-like hash functions that sacrifice a small degree of speed, but can be built with up to 128 bits of salt values that help to obscure what hashing function is actually being used.
                                                                                                                                                                                                                                                                                                              CrossHash.Sketch
                                                                                                                                                                                                                                                                                                              Currently experimental, this hashing algorithm is similar to Wisp and is almost as fast, but may have more reliable quality.
                                                                                                                                                                                                                                                                                                              CrossHash.Storm
                                                                                                                                                                                                                                                                                                              A whole cluster of Lightning-like hash functions that sacrifice a small degree of speed, but can be constructed with a salt value that helps obscure what hashing function is actually being used.
                                                                                                                                                                                                                                                                                                              CrossHash.Wisp
                                                                                                                                                                                                                                                                                                              The fastest hash in CrossHash, but no slouch on quality, either.
                                                                                                                                                                                                                                                                                                              DDALine
                                                                                                                                                                                                                                                                                                              A fixed-point line-drawing algorithm that should have good performance; may be useful for LOS.
                                                                                                                                                                                                                                                                                                              DeckRNG
                                                                                                                                                                                                                                                                                                              An RNG variant that has 16 possible grades of value it can produce and shuffles them like a deck of cards.
                                                                                                                                                                                                                                                                                                              DharmaRNG
                                                                                                                                                                                                                                                                                                              An alteration to a RandomnessSource that attempts to produce values that are perceived as fair to an imperfect user.
                                                                                                                                                                                                                                                                                                              Dice
                                                                                                                                                                                                                                                                                                              Class for emulating various traditional RPG-style dice rolls.
                                                                                                                                                                                                                                                                                                              EditRNG
                                                                                                                                                                                                                                                                                                              A subclass of StatefulRNG (and thus RNG) that allows customizing many parts of the random number generation.
                                                                                                                                                                                                                                                                                                              Elias
                                                                                                                                                                                                                                                                                                              Contains methods to draw antialiased lines based on floating point coordinates.
                                                                                                                                                                                                                                                                                                              EnumMapPlus<K extends Enum<K>,V>
                                                                                                                                                                                                                                                                                                              Mostly just a way to have an EnumMap-like class that can be serialized reasonably.
                                                                                                                                                                                                                                                                                                              FlapRNG
                                                                                                                                                                                                                                                                                                              Like PintRNG (uses 32-bit int math, good for older desktops and phones), but much faster at the expense of quality.
                                                                                                                                                                                                                                                                                                              GapShuffler<T>
                                                                                                                                                                                                                                                                                                              Meant to take a fixed-size set of items and produce a shuffled stream of them such that an element is never chosen in quick succession; that is, there should always be a gap between the same item's occurrences.
                                                                                                                                                                                                                                                                                                              GlitchNoise
                                                                                                                                                                                                                                                                                                              A noise generator for 1D, 2D, 3D, 4D, or 6D noise that should look "glitchy", with waves of changing values moving through triangular shapes.
                                                                                                                                                                                                                                                                                                              GreasedRegion
                                                                                                                                                                                                                                                                                                              Region encoding of on/off information about areas using bitsets; uncompressed (fatty), but fast (greased lightning).
                                                                                                                                                                                                                                                                                                              HashCommon
                                                                                                                                                                                                                                                                                                              Code used internally for hashing OrderedMap, OrderedSet, IntDoubleOrderedMap, Arrangement, and so on.
                                                                                                                                                                                                                                                                                                              Hashers
                                                                                                                                                                                                                                                                                                              Additional implementations of the CrossHash.IHasher interface for more specialized uses, like for use in an OrderedSet or OrderedMap with String keys that should use case-insensitive equality/hashing.
                                                                                                                                                                                                                                                                                                              HerdRNG
                                                                                                                                                                                                                                                                                                              A mix of fast 32-bit-friendly RNGs like FlapRNG with the larger state size of LongPeriodRNG, in the hopes of improving Flap's period without seriously reducing speed.
                                                                                                                                                                                                                                                                                                              HordeRNG
                                                                                                                                                                                                                                                                                                              A mix of something like the fast algorithm of LapRNG with the larger state size of LongPeriodRNG, in the hopes of improving Lap's period without seriously reducing speed.
                                                                                                                                                                                                                                                                                                              IntDoubleOrderedMap
                                                                                                                                                                                                                                                                                                              A type-specific linked hash map with with a fast, primitive-based implementation, originally from fastutil as Int2DoubleLinkedOpenHashMap.
                                                                                                                                                                                                                                                                                                              IntVLA
                                                                                                                                                                                                                                                                                                              A resizable, ordered or unordered variable-length int array.
                                                                                                                                                                                                                                                                                                              Isaac32RNG
                                                                                                                                                                                                                                                                                                              This is a port of the public domain Isaac (cryptographic) random number generator to Java, by Bob Jenkins.
                                                                                                                                                                                                                                                                                                              IsaacRNG
                                                                                                                                                                                                                                                                                                              This is a port of the public domain Isaac64 (cryptographic) random number generator to Java.
                                                                                                                                                                                                                                                                                                              JavaRNG
                                                                                                                                                                                                                                                                                                              This makes java.util.Random available for testing purposes.
                                                                                                                                                                                                                                                                                                              K2<A,B>
                                                                                                                                                                                                                                                                                                              An ordered bidirectional map-like data structure, with unique A keys and unique B keys updated together like a map that can be queried by A keys, B keys, or int indices.
                                                                                                                                                                                                                                                                                                              K2V1<A,B,Q>
                                                                                                                                                                                                                                                                                                              An ordered multi-directional map-like data structure with two sets of keys and one list of values.
                                                                                                                                                                                                                                                                                                              LapRNG
                                                                                                                                                                                                                                                                                                              Like FlapRNG, this sacrifices quality for speed, but it uses 64-bit math and as such has a larger period (FlapRNG @@ -439,206 +445,206 @@

                                                                                                                                                                                                                                                                                                              Package squidpony.squidmath

                                                                                                                                                                                                                                                                                                              many more, probably 2 to the 65).
                                                                                                                                                                                                                                                                                                              LFSR
                                                                                                                                                                                                                                                                                                              A Linear Feedback Shift Register that may be used like a StatefulRandomness but is not truly random.
                                                                                                                                                                                                                                                                                                              Light32RNG
                                                                                                                                                                                                                                                                                                              Based on the same SplitMix algorithm LightRNG uses, but a 32-bit variant, this RandomnessSource has 63 bits of state and should have a period of 2 to the 63.
                                                                                                                                                                                                                                                                                                              LightRNG
                                                                                                                                                                                                                                                                                                              This is a SplittableRandom-style generator, meant to have a tiny state that permits storing many different generators with low overhead.
                                                                                                                                                                                                                                                                                                              LongPeriodRNG
                                                                                                                                                                                                                                                                                                              An RNG that has a drastically longer period than the other generators in Sarong, other than IsaacRNG, without sacrificing speed or HTML target compatibility.
                                                                                                                                                                                                                                                                                                              MasonNoise
                                                                                                                                                                                                                                                                                                              Noise functions that try to conceal undesirable patterns, in 2D, 3D, 4D, and 6D, using 32-bit int math wherever possible and only yielding floats or doubles if requested.
                                                                                                                                                                                                                                                                                                              MathExtras
                                                                                                                                                                                                                                                                                                              Mathematical operations not provided by java.lang.Math.
                                                                                                                                                                                                                                                                                                              MeadNoise
                                                                                                                                                                                                                                                                                                              Experiments with noise functions.
                                                                                                                                                                                                                                                                                                              MerlinNoise
                                                                                                                                                                                                                                                                                                              Simple somewhat-continuous noise functions that use int coordinates instead of the traditional double (this approach works better on a grid).
                                                                                                                                                                                                                                                                                                              MersenneTwister Deprecated 
                                                                                                                                                                                                                                                                                                              MultiArrangement<K>
                                                                                                                                                                                                                                                                                                              A bi-directional mapping of non-unique objects to positions in an ordering (which this generates), and vice versa.
                                                                                                                                                                                                                                                                                                              MultiKey
                                                                                                                                                                                                                                                                                                              An ordered multi-directional "map" that keeps 1 or more keysets organized so you can look up one key given a key in another keyset, and do the same for the indices of keys.
                                                                                                                                                                                                                                                                                                              NeuralParticle
                                                                                                                                                                                                                                                                                                              Creates a field of particles that tend to form a neuron image type distribution.
                                                                                                                                                                                                                                                                                                              NLFSR
                                                                                                                                                                                                                                                                                                              A Non-Linear Feedback Shift Register that may be used like a StatefulRandomness but is not truly random.
                                                                                                                                                                                                                                                                                                              Noise
                                                                                                                                                                                                                                                                                                              Created by Tommy Ettinger on 3/17/2017.
                                                                                                                                                                                                                                                                                                              Noise.Layered1D  
                                                                                                                                                                                                                                                                                                              Noise.Layered2D  
                                                                                                                                                                                                                                                                                                              Noise.Layered3D  
                                                                                                                                                                                                                                                                                                              Noise.Layered4D  
                                                                                                                                                                                                                                                                                                              Noise.Layered6D  
                                                                                                                                                                                                                                                                                                              Noise.Ridged2D  
                                                                                                                                                                                                                                                                                                              Noise.Ridged3D  
                                                                                                                                                                                                                                                                                                              Noise.Ridged4D  
                                                                                                                                                                                                                                                                                                              Noise.Ridged6D  
                                                                                                                                                                                                                                                                                                              Noise.Scaled1D  
                                                                                                                                                                                                                                                                                                              Noise.Scaled2D  
                                                                                                                                                                                                                                                                                                              Noise.Scaled3D  
                                                                                                                                                                                                                                                                                                              Noise.Scaled4D  
                                                                                                                                                                                                                                                                                                              Noise.Scaled6D  
                                                                                                                                                                                                                                                                                                              Noise.Slick2D  
                                                                                                                                                                                                                                                                                                              Noise.Slick3D  
                                                                                                                                                                                                                                                                                                              Noise.Slick4D  
                                                                                                                                                                                                                                                                                                              Noise.Slick6D  
                                                                                                                                                                                                                                                                                                              Noise.Turbulent2D  
                                                                                                                                                                                                                                                                                                              Noise.Turbulent3D  
                                                                                                                                                                                                                                                                                                              Noise.Turbulent4D  
                                                                                                                                                                                                                                                                                                              Noise.Turbulent6D  
                                                                                                                                                                                                                                                                                                              Noise.Viny2D  
                                                                                                                                                                                                                                                                                                              Noise.Viny3D  
                                                                                                                                                                                                                                                                                                              Noise.Viny4D  
                                                                                                                                                                                                                                                                                                              Noise.Viny6D  
                                                                                                                                                                                                                                                                                                              NumberTools
                                                                                                                                                                                                                                                                                                              Various numeric functions that are important to performance but need alternate implementations on GWT to obtain it.
                                                                                                                                                                                                                                                                                                              OrderedMap<K,V>
                                                                                                                                                                                                                                                                                                              A generic linked hash map with with a fast implementation, originally from fastutil as Object2ObjectLinkedOpenHashMap @@ -646,7 +652,7 @@

                                                                                                                                                                                                                                                                                                              Package squidpony.squidmath

                                                                                                                                                                                                                                                                                                              array keys (which fastutil does differently).
                                                                                                                                                                                                                                                                                                              OrderedSet<K>
                                                                                                                                                                                                                                                                                                              A generic linked hash set with with a fast implementation, originally from fastutil as ObjectLinkedOpenHashSet but @@ -654,92 +660,92 @@

                                                                                                                                                                                                                                                                                                              Package squidpony.squidmath

                                                                                                                                                                                                                                                                                                              does differently).
                                                                                                                                                                                                                                                                                                              OrthoLine
                                                                                                                                                                                                                                                                                                              A simple line-drawing algorithm that only takes orthogonal steps; may be useful for LOS in games that use Manhattan distances for measurements.
                                                                                                                                                                                                                                                                                                              PerlinNoise
                                                                                                                                                                                                                                                                                                              This is Ken Perlin's third revision of his noise function.
                                                                                                                                                                                                                                                                                                              PermutationGenerator<T>
                                                                                                                                                                                                                                                                                                              Permutation generator for generating all permutations for all sets up to 20 elements in size.
                                                                                                                                                                                                                                                                                                              PermutedRNG
                                                                                                                                                                                                                                                                                                              This is a RandomnessSource in the PCG-Random family.
                                                                                                                                                                                                                                                                                                              PintRNG
                                                                                                                                                                                                                                                                                                              A different kind of RandomnessSource that operates internally on ints.
                                                                                                                                                                                                                                                                                                              PoissonDisk
                                                                                                                                                                                                                                                                                                              This provides a Uniform Poisson Disk Sampling technique that can be used to generate random points that have a uniform minimum distance between each other.
                                                                                                                                                                                                                                                                                                              ProbabilityTable<T>
                                                                                                                                                                                                                                                                                                              A generic method of holding a probability table to determine weighted random outcomes.
                                                                                                                                                                                                                                                                                                              RandomBias
                                                                                                                                                                                                                                                                                                              A class that wraps an RNG and allows different String keys to be associated with biases toward low or high results when a method is called that gets a number from the wrapped RNG.
                                                                                                                                                                                                                                                                                                              Region
                                                                                                                                                                                                                                                                                                              NOTE: You should consider GreasedRegion before using this class, unless you know Region does exactly what you want.
                                                                                                                                                                                                                                                                                                              RegionMap<V>
                                                                                                                                                                                                                                                                                                              A small extension of OrderedMap that specifically handles short[] regions as produced by CoordPacker.
                                                                                                                                                                                                                                                                                                              RNG
                                                                                                                                                                                                                                                                                                              A wrapper class for working with random number generators in a more friendly way.
                                                                                                                                                                                                                                                                                                              RNG.CustomRandom
                                                                                                                                                                                                                                                                                                              A subclass of java.util.Random that uses a RandomnessSource supplied by the user instead of the default.
                                                                                                                                                                                                                                                                                                              SaltyQRNG
                                                                                                                                                                                                                                                                                                              A different kind of quasi-random number generator (also called a sub-random sequence) that can be "salted" like some hashing functions can, to produce many distinct sub-random sequences without changing its performance qualities.
                                                                                                                                                                                                                                                                                                              SeededNoise
                                                                                                                                                                                                                                                                                                              More advanced noise functions, in 2D, 3D, 4D, and 6D, with the last two as options for generating seamlessly-tiling @@ -747,55 +753,55 @@

                                                                                                                                                                                                                                                                                                              Package squidpony.squidmath

                                                                                                                                                                                                                                                                                                              Noise.seamless3D(double[][][], int, int, Noise.Noise6D).
                                                                                                                                                                                                                                                                                                              ShortSet
                                                                                                                                                                                                                                                                                                              An unordered set that uses short keys.
                                                                                                                                                                                                                                                                                                              ShortSet.ShortSetIterator  
                                                                                                                                                                                                                                                                                                              ShortVLA
                                                                                                                                                                                                                                                                                                              A resizable, ordered or unordered short variable-length array.
                                                                                                                                                                                                                                                                                                              SlapRNG
                                                                                                                                                                                                                                                                                                              Like PintRNG (uses int math primarily, making it good with 32-bit desktops and phones) and FlapRNG, but with a longer period than either, plus this implements StatefulRandomness.
                                                                                                                                                                                                                                                                                                              SobolQRNG
                                                                                                                                                                                                                                                                                                              Implementation of a Sobol sequence as a Quasi-Random Number Generator.
                                                                                                                                                                                                                                                                                                              SquidID
                                                                                                                                                                                                                                                                                                              A UUID-like identifier; not compatible with Java's standard UUID but will work on GWT.
                                                                                                                                                                                                                                                                                                              StatefulRNG
                                                                                                                                                                                                                                                                                                              A slight variant on RNG that always uses a stateful RandomessSource and so can have its state set or retrieved using setState() or getState().
                                                                                                                                                                                                                                                                                                              TabbyNoise
                                                                                                                                                                                                                                                                                                              A different kind of noise that has spotted and striped areas, like a tabby cat.
                                                                                                                                                                                                                                                                                                              TableSet<C,R>
                                                                                                                                                                                                                                                                                                              A generic linked hash set with with a fast implementation, originally from fastutil as ObjectLinkedOpenHashSet but @@ -803,74 +809,74 @@

                                                                                                                                                                                                                                                                                                              Package squidpony.squidmath

                                                                                                                                                                                                                                                                                                              does differently).
                                                                                                                                                                                                                                                                                                              ThrustRNG
                                                                                                                                                                                                                                                                                                              A hybrid of the type of algorithm LightRNG uses with some of the specific steps of a linear congruential generator.
                                                                                                                                                                                                                                                                                                              ThunderRNG
                                                                                                                                                                                                                                                                                                              Like LightRNG, but shares a lot in common with one of CrossHash's hashing algorithms.
                                                                                                                                                                                                                                                                                                              TuringPattern
                                                                                                                                                                                                                                                                                                              A technique for producing organic-seeming patterns via iterative processing of random values (reaction-diffusion).
                                                                                                                                                                                                                                                                                                              ValueNoise
                                                                                                                                                                                                                                                                                                              Performance-oriented "white noise" generator for 1D, 2D, 3D, 4D, and 6D.
                                                                                                                                                                                                                                                                                                              VanDerCorputQRNG
                                                                                                                                                                                                                                                                                                              A quasi-random number generator that goes through one of many sub-random sequences found by J.G.
                                                                                                                                                                                                                                                                                                              WaveletNoise
                                                                                                                                                                                                                                                                                                              Wavelet Noise, a kind of multi-dimensional noise that is technically unrelated to classic Perlin or Simplex Noise, developed by Pixar to solve some difficult issues of 2D textures being displayed in 3D scenes.
                                                                                                                                                                                                                                                                                                              WhirlingNoise
                                                                                                                                                                                                                                                                                                              Another experimental noise class.
                                                                                                                                                                                                                                                                                                              WobblyLine
                                                                                                                                                                                                                                                                                                              A drunkard's-walk-like algorithm for line drawing "wobbly" paths.
                                                                                                                                                                                                                                                                                                              XkcdRNG
                                                                                                                                                                                                                                                                                                              This implements the random number function from the "Random Number" XKCD comic, with minor compatibility changes.
                                                                                                                                                                                                                                                                                                              XoRoRNG
                                                                                                                                                                                                                                                                                                              A port of Blackman and Vigna's xoroshiro 128+ generator; should be very fast and produce high-quality output.
                                                                                                                                                                                                                                                                                                              XorRNG
                                                                                                                                                                                                                                                                                                              A port of Sebastiano Vigna's XorShift 128+ generator.
                                                                                                                                                                                                                                                                                                              ZapRNG
                                                                                                                                                                                                                                                                                                              A variant on LapRNG that improves the quality at the expense of some speed.
                                                                                                                                                                                                                                                                                                              diff --git a/docs/squidlib-util/squidpony/squidmath/package-tree.html b/docs/squidlib-util/squidpony/squidmath/package-tree.html index 4134f47638..f0ba2ebbcf 100644 --- a/docs/squidlib-util/squidpony/squidmath/package-tree.html +++ b/docs/squidlib-util/squidpony/squidmath/package-tree.html @@ -225,6 +225,7 @@

                                                                                                                                                                                                                                                                                                              Class Hierarchy

                                                                                                                                                                                                                                                                                                            • squidpony.squidmath.RandomBias (implements java.io.Serializable)
                                                                                                                                                                                                                                                                                                            • squidpony.squidmath.RNG (implements java.io.Serializable)
                                                                                                                                                                                                                                                                                                                +
                                                                                                                                                                                                                                                                                                              • squidpony.squidmath.CriticalRNG
                                                                                                                                                                                                                                                                                                              • squidpony.squidmath.DharmaRNG (implements java.io.Serializable)
                                                                                                                                                                                                                                                                                                              • squidpony.squidmath.StatefulRNG
                                                                                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Alteration.html b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Alteration.html index ec9e555de4..9b8646dc36 100644 --- a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Alteration.html +++ b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Alteration.html @@ -2059,2201 +2059,2249 @@ 2051 */ 2052 public static final FakeLanguageGen ALIEN_O = alien_o().register(); 2053 -2054 /** -2055 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages -2056 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric -2057 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this -2058 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, -2059 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null -2060 * elements in its original state, so some code may rely on the items being usable and non-null. -2061 */ -2062 public static final FakeLanguageGen[] registered; -2063 -2064 static { -2065 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. -2066 registered = new FakeLanguageGen[registry.size()-1]; -2067 for (int i = 0; i < registered.length; i++) { -2068 registered[i] = registry.getAt(i+1); -2069 } -2070 } -2071 /** -2072 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . -2073 */ -2074 public FakeLanguageGen() { -2075 this( -2076 new String[]{ -2077 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2078 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2079 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2080 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2081 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", -2082 }, -2083 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, -2084 new String[]{ -2085 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", -2086 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", -2087 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", -2088 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", -2089 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", -2090 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", -2091 "b", "d", "f", "g", "h", "l", "m", "n", -2092 "p", "r", "s", "sh", "t", "th", -2093 "b", "d", "f", "g", "h", "l", "m", "n", -2094 "p", "r", "s", "sh", "t", "th", -2095 "r", "s", "t", "l", "n", -2096 "str", "spr", "spl", "wr", "kn", "kn", "gn", -2097 }, -2098 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", -2099 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", -2100 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" -2101 }, -2102 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", -2103 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", -2104 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", -2105 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", -2106 }, -2107 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2108 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2109 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2110 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", -2111 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2112 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2113 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", -2114 }, -2115 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); -2116 } -2117 -2118 /** -2119 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2120 * class, LOVECRAFT and GREEK_ROMANIZED. -2121 * -2122 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2123 * of a word or in the middle; elements may be repeated to make them more common -2124 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2125 * middle of the word; all openingVowels are automatically copied into this internally. -2126 * Elements may be repeated to make them more common -2127 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2128 * at the start of a word; elements may be repeated to make them more common -2129 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2130 * between vowels; all closingConsonants are automatically copied into this internally. -2131 * Elements may be repeated to make them more common -2132 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2133 * at the end of a word; elements may be repeated to make them more common -2134 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2135 * whatever the word should end in; elements may be repeated to make them more common -2136 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2137 * then "a-a" may be possible; elements may be repeated to make them more common -2138 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2139 * tied to syllableFrequencies -2140 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2141 * represents how often each syllable count should appear relative to other counts; there -2142 * is no need to restrict the numbers to add up to any other number -2143 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2144 * higher numbers yield more words starting with vowels -2145 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2146 * numbers yield more words ending in vowels -2147 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2148 * often a vowel will be split into two vowels separated by one of those splitters -2149 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2150 * closingSyllables is used instead of ending normally -2151 */ -2152 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2153 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2154 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2155 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { -2156 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, -2157 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, -2158 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); -2159 } -2160 -2161 /** -2162 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2163 * class, LOVECRAFT and GREEK_ROMANIZED. -2164 * -2165 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2166 * of a word or in the middle; elements may be repeated to make them more common -2167 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2168 * middle of the word; all openingVowels are automatically copied into this internally. -2169 * Elements may be repeated to make them more common -2170 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2171 * at the start of a word; elements may be repeated to make them more common -2172 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2173 * between vowels; all closingConsonants are automatically copied into this internally. +2054 // àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳ +2055 // çðþñýćĉċčďđĝğġģĥħĵķĺļľŀłńņňŋŕŗřśŝşšţťŵŷÿźżžșțẁẃẅ +2056 private static FakeLanguageGen alien_u(){ +2057 return new FakeLanguageGen( +2058 new String[]{ +2059 "a", "a", "a", "a", "ä", "i", "o", "o", "o", "ö", "u", "u", "u", "u", "u", "u", "ü", "ü" +2060 }, +2061 new String[]{}, +2062 new String[]{ +2063 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2064 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2065 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2066 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2067 }, +2068 new String[]{ +2069 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2070 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2071 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2072 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2073 }, +2074 new String[]{ +2075 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", +2076 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2077 "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2078 }, +2079 new String[]{"emb", "embrid", "embraŋ", "eŋ", "eŋul", "eŋov", "eẃul", "eẃuld", "eẃulb", +2080 "eviś", "evim", "ełurn", "ełav", "egiġ", "ergiġ", "elgiġ", "eŕu", "eŕup", "eŕulm", "eŕuv", +2081 "eħul", "eħid", "eħiŋ", "eyü", "eyür", "eyürl", "eyüld", "eyüns", "eqä", "eqäp", "eqäġ", +2082 "esu", "esumb", "esulg", "esurl", "eśo", "eśold", "eśolg", "eśu", "eśur", "eśuŋ", +2083 "eñu", "eñuns", "eñurn", "eño", "eñolb", "eñols" +2084 }, +2085 new String[]{"'"}, new int[]{1, 2, 3, 4, 5}, new double[]{3, 4, 7, 5, 2}, 0.4, 0.15, 0.06, 0.5, null, true); +2086 } +2087 +2088 /** +2089 * Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for +2090 * an alien species. This alien language is meant to have an abrupt change mid-word for many words, with the suffix +2091 * of roughly half of words using the letter "e", which is absent from the rest of the language; these suffixes can +2092 * also use consonant clusters, which are similarly absent elsewhere. The suffixes would make sense as a historical +2093 * relic or as a linguistic holdout from a historical merger. As the name would suggest, it strongly prefers +2094 * using the vowel "u", with it present in about half the groups, and can use the umlaut accent "ü" on some vowels. +2095 * The consonants completely avoid hard sounds like "t" and "k", and don't cluster; they often have special marks. +2096 * This should be relatively easy to pronounce for an alien language, though the words are rather long. +2097 * <br> +2098 * Üweħid vuŕeħid deẃul leŋul waloyeyür; äyovavü... +2099 */ +2100 public static final FakeLanguageGen ALIEN_U = alien_u().register(); +2101 +2102 /** +2103 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages +2104 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric +2105 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this +2106 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, +2107 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null +2108 * elements in its original state, so some code may rely on the items being usable and non-null. +2109 */ +2110 public static final FakeLanguageGen[] registered; +2111 +2112 static { +2113 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. +2114 registered = new FakeLanguageGen[registry.size()-1]; +2115 for (int i = 0; i < registered.length; i++) { +2116 registered[i] = registry.getAt(i+1); +2117 } +2118 } +2119 /** +2120 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . +2121 */ +2122 public FakeLanguageGen() { +2123 this( +2124 new String[]{ +2125 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2126 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2127 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2128 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2129 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", +2130 }, +2131 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, +2132 new String[]{ +2133 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", +2134 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", +2135 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", +2136 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", +2137 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", +2138 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", +2139 "b", "d", "f", "g", "h", "l", "m", "n", +2140 "p", "r", "s", "sh", "t", "th", +2141 "b", "d", "f", "g", "h", "l", "m", "n", +2142 "p", "r", "s", "sh", "t", "th", +2143 "r", "s", "t", "l", "n", +2144 "str", "spr", "spl", "wr", "kn", "kn", "gn", +2145 }, +2146 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", +2147 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", +2148 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" +2149 }, +2150 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", +2151 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", +2152 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", +2153 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", +2154 }, +2155 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2156 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2157 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2158 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", +2159 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2160 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2161 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", +2162 }, +2163 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); +2164 } +2165 +2166 /** +2167 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2168 * class, LOVECRAFT and GREEK_ROMANIZED. +2169 * +2170 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2171 * of a word or in the middle; elements may be repeated to make them more common +2172 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2173 * middle of the word; all openingVowels are automatically copied into this internally. 2174 * Elements may be repeated to make them more common -2175 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2176 * at the end of a word; elements may be repeated to make them more common -2177 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2178 * whatever the word should end in; elements may be repeated to make them more common -2179 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2180 * then "a-a" may be possible; elements may be repeated to make them more common -2181 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2182 * tied to syllableFrequencies -2183 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2184 * represents how often each syllable count should appear relative to other counts; there -2185 * is no need to restrict the numbers to add up to any other number -2186 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2187 * higher numbers yield more words starting with vowels -2188 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2189 * numbers yield more words ending in vowels -2190 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2191 * often a vowel will be split into two vowels separated by one of those splitters -2192 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2193 * closingSyllables is used instead of ending normally -2194 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many -2195 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets -2196 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a -2197 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly -2198 */ -2199 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2200 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2201 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2202 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, -2203 Pattern[] sane, boolean clean) { -2204 this.openingVowels = openingVowels; -2205 this.midVowels = new String[openingVowels.length + midVowels.length]; -2206 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); -2207 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); -2208 this.openingConsonants = openingConsonants; -2209 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; -2210 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); -2211 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); -2212 this.closingConsonants = closingConsonants; -2213 this.vowelSplitters = vowelSplitters; -2214 this.closingSyllables = closingSyllables; -2215 -2216 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); -2217 -2218 totalSyllableFrequency = this.syllableFrequencies.values().sum(); -2219 if (vowelStartFrequency > 1.0) -2220 this.vowelStartFrequency = 1.0 / vowelStartFrequency; -2221 else -2222 this.vowelStartFrequency = vowelStartFrequency; -2223 if (vowelEndFrequency > 1.0) -2224 this.vowelEndFrequency = 1.0 / vowelEndFrequency; -2225 else -2226 this.vowelEndFrequency = vowelEndFrequency; -2227 if (vowelSplitters.length == 0) -2228 this.vowelSplitFrequency = 0.0; -2229 else if (vowelSplitFrequency > 1.0) -2230 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; -2231 else -2232 this.vowelSplitFrequency = vowelSplitFrequency; -2233 if (closingSyllables.length == 0) -2234 this.syllableEndFrequency = 0.0; -2235 else if (syllableEndFrequency > 1.0) -2236 this.syllableEndFrequency = 1.0 / syllableEndFrequency; -2237 else -2238 this.syllableEndFrequency = syllableEndFrequency; -2239 this.clean = clean; -2240 sanityChecks = sane; -2241 modifiers = new ArrayList<>(16); -2242 } -2243 -2244 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2245 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, -2246 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, -2247 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, -2248 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, -2249 List<Modifier> modifiers) { -2250 this.openingVowels = copyStrings(openingVowels); -2251 this.midVowels = copyStrings(midVowels); -2252 this.openingConsonants = copyStrings(openingConsonants); -2253 this.midConsonants = copyStrings(midConsonants); -2254 this.closingConsonants = copyStrings(closingConsonants); -2255 this.closingSyllables = copyStrings(closingSyllables); -2256 this.vowelSplitters = copyStrings(vowelSplitters); -2257 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); -2258 this.vowelStartFrequency = vowelStartFrequency; -2259 this.vowelEndFrequency = vowelEndFrequency; -2260 this.vowelSplitFrequency = vowelSplitFrequency; -2261 this.syllableEndFrequency = syllableEndFrequency; -2262 for (Double freq : this.syllableFrequencies.values()) { -2263 totalSyllableFrequency += freq; -2264 } -2265 if (sanityChecks == null) -2266 this.sanityChecks = null; -2267 else { -2268 this.sanityChecks = new Pattern[sanityChecks.length]; -2269 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); -2270 } -2271 this.clean = clean; -2272 this.modifiers = new ArrayList<>(modifiers); -2273 } -2274 -2275 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, -2276 Set<String> forbidden, RNG rng, double repeatSingleChance, -2277 int preferredLimit) { -2278 int l, sz = parts.size(); -2279 List<String> working = new ArrayList<>(sz * 24); -2280 String pair; -2281 for (int e = 0; e < parts.size(); e++) { -2282 Map.Entry<String, String> sn = parts.entryAt(e); -2283 if (missingSounds.contains(sn.getKey())) -2284 continue; -2285 for (String t : sn.getValue().split(" ")) { -2286 if (forbidden.contains(t)) -2287 continue; -2288 l = t.length(); -2289 int num; -2290 char c; -2291 switch (l) { -2292 case 0: -2293 break; -2294 case 1: -2295 working.add(t); -2296 working.add(t); -2297 working.add(t); -2298 c = t.charAt(0); -2299 num = 0; -2300 boolean repeat = true; -2301 switch (c) { -2302 case 'w': -2303 num += 2; -2304 case 'y': -2305 case 'h': -2306 num += 4; -2307 case 'q': -2308 case 'x': -2309 num += 4; -2310 repeat = false; -2311 break; -2312 case 'i': -2313 case 'u': -2314 repeat = false; -2315 num = 13; -2316 break; -2317 case 'z': -2318 case 'v': -2319 num = 4; -2320 break; -2321 case 'j': -2322 num = 7; -2323 break; -2324 default: -2325 if (e >= preferredLimit) -2326 num = 6; -2327 else -2328 num = 13; -2329 } -2330 for (int i = 0; i < num * 3; i++) { -2331 if (rng.nextDouble() < 0.75) { -2332 working.add(t); -2333 } -2334 } -2335 -2336 if (repeat && rng.nextDouble() < repeatSingleChance) { -2337 pair = t + t; -2338 if (missingSounds.contains(pair)) -2339 continue; -2340 working.add(pair); -2341 working.add(pair); -2342 working.add(pair); -2343 if (rng.nextDouble() < 0.7) { -2344 working.add(pair); -2345 working.add(pair); -2346 } -2347 if (rng.nextDouble() < 0.7) { -2348 working.add(pair); -2349 } -2350 } -2351 -2352 break; -2353 case 2: -2354 if (rng.nextDouble() < 0.65) { -2355 c = t.charAt(1); -2356 num = 0; -2357 switch (c) { -2358 case 'z': -2359 num = 1; -2360 break; -2361 case 'w': -2362 num = 3; -2363 break; -2364 case 'n': -2365 num = 4; -2366 break; -2367 default: -2368 -2369 if (e >= preferredLimit) -2370 num = 2; -2371 else -2372 num = 7; -2373 } -2374 working.add(t); -2375 for (int i = 0; i < num; i++) { -2376 if (rng.nextDouble() < 0.25) { -2377 working.add(t); -2378 } -2379 } -2380 } -2381 break; -2382 case 3: -2383 if (rng.nextDouble() < 0.5) { -2384 c = t.charAt(0); -2385 switch (c) { -2386 case 'z': -2387 num = 1; -2388 break; -2389 case 'w': -2390 num = 3; -2391 break; -2392 case 'n': -2393 num = 4; -2394 break; -2395 default: -2396 if (e >= preferredLimit) -2397 num = 2; -2398 else -2399 num = 6; -2400 } -2401 working.add(t); -2402 for (int i = 0; i < num; i++) { -2403 if (rng.nextDouble() < 0.2) { -2404 working.add(t); -2405 } -2406 } -2407 } -2408 break; -2409 default: -2410 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { -2411 working.add(t); -2412 } -2413 break; -2414 } -2415 } -2416 } -2417 return working.toArray(new String[0]); -2418 } -2419 -2420 /*private static final String[][] openVowels = new String[][]{ -2421 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, -2422 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, -2423 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, -2424 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, -2425 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, -2426 }; -2427*/ -2428 -2429 public static FakeLanguageGen randomLanguage(RNG rng) { -2430 return randomLanguage(rng.nextLong()); -2431 } -2432 -2433 public static FakeLanguageGen randomLanguage(long seed) { -2434 StatefulRNG rng = new StatefulRNG(seed); -2435 int[] lengths = new int[rng.between(3, 5)]; -2436 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); -2437 double[] chances = new double[lengths.length]; -2438 System.arraycopy(new double[]{ -2439 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) -2440 }, 0, chances, 0, chances.length); -2441 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); -2442 int sz = openCons.size(); -2443 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); -2444 OrderedMap<String, String> -2445 parts0 = new OrderedMap<>(openVowels), -2446 parts1 = new OrderedMap<>(openCons), -2447 parts2 = new OrderedMap<>(midCons), -2448 parts3 = new OrderedMap<>(closeCons); -2449 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); -2450 parts1.reorder(reordering); -2451 parts2.reorder(reordering); -2452 parts3.reorder(reordering); -2453 parts0.reorder(vOrd); -2454 int n = 0; -2455 -2456 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; -2457 -2458 for (n = 0; n < mn; n++) { -2459 missingSounds.add(parts0.keyAt(0)); -2460 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); -2461 parts0.removeFirst(); -2462 } -2463 p0s = parts0.size(); -2464 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); -2465 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; -2466 int vowelAccent = rng.between(1, 7); -2467 for (int i = 0; i < sz0; i++) { -2468 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; -2469 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; -2470 } -2471 if (rng.nextDouble() < 0.8) { -2472 for (int i = 0; i < sz0; i++) { -2473 char ac = nextAccents[i], ua = unaccented[i]; -2474 String v = "", uas = String.valueOf(ua); -2475 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); -2476 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); -2477 for (int j = 0; j < p0s; j++) { -2478 String k = parts0.keyAt(j); -2479 if (uas.equals(k)) -2480 v = parts0.getAt(j); -2481 else { -2482 String current = parts0.getAt(j); -2483 String[] splits = current.split(" "); -2484 for (int s = 0; s < splits.length; s++) { -2485 if (forbidden.contains(uas) && splits[s].contains(uas)) -2486 forbidden.add(splits[s].replace(ua, ac)); -2487 } -2488 parts0.put(k, rep.replace(current)); -2489 } -2490 } -2491 parts0.put(String.valueOf(ac), repLess.replace(v)); -2492 } -2493 } -2494 -2495 n = 0; -2496 if (rng.nextDouble() < 0.75) { -2497 missingSounds.add("z"); -2498 Collections.addAll(forbidden, parts1.get("z").split(" ")); -2499 Collections.addAll(forbidden, parts2.get("z").split(" ")); -2500 Collections.addAll(forbidden, parts3.get("z").split(" ")); -2501 n++; -2502 } -2503 if (rng.nextDouble() < 0.82) { -2504 missingSounds.add("x"); -2505 Collections.addAll(forbidden, parts1.get("x").split(" ")); -2506 Collections.addAll(forbidden, parts2.get("x").split(" ")); -2507 Collections.addAll(forbidden, parts3.get("x").split(" ")); -2508 n++; -2509 } -2510 if (rng.nextDouble() < 0.92) { -2511 missingSounds.add("qu"); -2512 Collections.addAll(forbidden, parts1.get("qu").split(" ")); -2513 Collections.addAll(forbidden, parts2.get("qu").split(" ")); -2514 Collections.addAll(forbidden, parts3.get("qu").split(" ")); -2515 n++; -2516 } -2517 if (rng.nextDouble() < 0.96) { -2518 missingSounds.add("q"); -2519 Collections.addAll(forbidden, parts1.get("q").split(" ")); -2520 Collections.addAll(forbidden, parts2.get("q").split(" ")); -2521 Collections.addAll(forbidden, parts3.get("q").split(" ")); -2522 n++; -2523 } -2524 if (rng.nextDouble() < 0.97) { -2525 missingSounds.add("tl"); -2526 Collections.addAll(forbidden, parts1.get("tl").split(" ")); -2527 Collections.addAll(forbidden, parts2.get("tl").split(" ")); -2528 Collections.addAll(forbidden, parts3.get("tl").split(" ")); -2529 n++; -2530 } -2531 if (rng.nextDouble() < 0.86) { -2532 missingSounds.add("ph"); -2533 Collections.addAll(forbidden, parts1.get("ph").split(" ")); -2534 Collections.addAll(forbidden, parts2.get("ph").split(" ")); -2535 Collections.addAll(forbidden, parts3.get("ph").split(" ")); -2536 n++; -2537 } -2538 if (rng.nextDouble() < 0.94) { -2539 missingSounds.add("kh"); -2540 Collections.addAll(forbidden, parts1.get("kh").split(" ")); -2541 Collections.addAll(forbidden, parts2.get("kh").split(" ")); -2542 Collections.addAll(forbidden, parts3.get("kh").split(" ")); -2543 n++; -2544 } -2545 if (rng.nextDouble() < 0.96) { -2546 missingSounds.add("bh"); -2547 missingSounds.add("dh"); -2548 Collections.addAll(forbidden, parts1.get("bh").split(" ")); -2549 Collections.addAll(forbidden, parts2.get("bh").split(" ")); -2550 Collections.addAll(forbidden, parts3.get("bh").split(" ")); -2551 Collections.addAll(forbidden, parts1.get("dh").split(" ")); -2552 Collections.addAll(forbidden, parts2.get("dh").split(" ")); -2553 Collections.addAll(forbidden, parts3.get("dh").split(" ")); -2554 n++; -2555 n++; -2556 } -2557 -2558 for (; n < sz * removalRate; n++) { -2559 missingSounds.add(parts1.keyAt(n)); -2560 missingSounds.add(parts2.keyAt(n)); -2561 missingSounds.add(parts3.keyAt(n)); -2562 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); -2563 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); -2564 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); -2565 } -2566 -2567 return new FakeLanguageGen( -2568 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), -2569 new String[]{"y", "y"}, -2570 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), -2571 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), -2572 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), -2573 new String[]{}, -2574 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); -2575 } -2576 -2577 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { -2578 CharSequence fixed = removeAccents(testing); -2579 for (int i = 0; i < checks.length; i++) { -2580 if (checks[i].matcher(fixed).find()) -2581 return false; -2582 } -2583 return true; -2584 } -2585 -2586 /** -2587 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text -2588 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives -2589 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers -2590 * that could look like letters. -2591 * @param testing the text, as a CharSequence such as a String, to check -2592 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't -2593 */ -2594 public static boolean checkVulgarity(CharSequence testing) -2595 { -2596 CharSequence fixed = removeAccents(testing); -2597 for (int i = 0; i < vulgarChecks.length; i++) { -2598 if (vulgarChecks[i].matcher(fixed).find()) -2599 { -2600 System.out.println(vulgarChecks[i]); -2601 return true; -2602 } -2603 } -2604 return false; -2605 } -2606 -2607 /** -2608 * Generate a word from this FakeLanguageGen, using and changing the current seed. -2609 * -2610 * @param capitalize true if the word should start with a capital letter, false otherwise -2611 * @return a word in the fake language as a String -2612 */ -2613 public String word(boolean capitalize) { -2614 return word(srng, capitalize); -2615 } -2616 -2617 /** -2618 * Generate a word from this FakeLanguageGen using the specified RNG. -2619 * -2620 * @param rng the RNG to use for the randomized string building -2621 * @param capitalize true if the word should start with a capital letter, false otherwise -2622 * @return a word in the fake language as a String -2623 */ -2624 public String word(RNG rng, boolean capitalize) { -2625 while (true) { -2626 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2627 double syllableChance = rng.nextDouble(totalSyllableFrequency); -2628 int syllables = 1, i = 0; -2629 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { -2630 if (syllableChance < kv.getDoubleValue()) { -2631 syllables = kv.getIntKey(); -2632 break; -2633 } else -2634 syllableChance -= kv.getDoubleValue(); -2635 } -2636 if (rng.nextDouble() < vowelStartFrequency) { -2637 sb.append(rng.getRandomElement(openingVowels)); -2638 if (syllables == 1) -2639 sb.append(rng.getRandomElement(closingConsonants)); -2640 else -2641 sb.append(rng.getRandomElement(midConsonants)); -2642 i++; -2643 } else { -2644 sb.append(rng.getRandomElement(openingConsonants)); -2645 } -2646 String close = ""; -2647 boolean redouble = false; -2648 if (i < syllables) { -2649 if (rng.nextDouble() < syllableEndFrequency) { -2650 close = rng.getRandomElement(closingSyllables); -2651 if (close.contains("@") && (syllables & 1) == 0) { -2652 redouble = true; -2653 syllables = (syllables | 1) >> 1; +2175 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2176 * at the start of a word; elements may be repeated to make them more common +2177 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2178 * between vowels; all closingConsonants are automatically copied into this internally. +2179 * Elements may be repeated to make them more common +2180 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2181 * at the end of a word; elements may be repeated to make them more common +2182 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2183 * whatever the word should end in; elements may be repeated to make them more common +2184 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2185 * then "a-a" may be possible; elements may be repeated to make them more common +2186 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2187 * tied to syllableFrequencies +2188 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2189 * represents how often each syllable count should appear relative to other counts; there +2190 * is no need to restrict the numbers to add up to any other number +2191 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2192 * higher numbers yield more words starting with vowels +2193 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2194 * numbers yield more words ending in vowels +2195 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2196 * often a vowel will be split into two vowels separated by one of those splitters +2197 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2198 * closingSyllables is used instead of ending normally +2199 */ +2200 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2201 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2202 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2203 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { +2204 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, +2205 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, +2206 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); +2207 } +2208 +2209 /** +2210 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2211 * class, LOVECRAFT and GREEK_ROMANIZED. +2212 * +2213 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2214 * of a word or in the middle; elements may be repeated to make them more common +2215 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2216 * middle of the word; all openingVowels are automatically copied into this internally. +2217 * Elements may be repeated to make them more common +2218 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2219 * at the start of a word; elements may be repeated to make them more common +2220 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2221 * between vowels; all closingConsonants are automatically copied into this internally. +2222 * Elements may be repeated to make them more common +2223 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2224 * at the end of a word; elements may be repeated to make them more common +2225 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2226 * whatever the word should end in; elements may be repeated to make them more common +2227 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2228 * then "a-a" may be possible; elements may be repeated to make them more common +2229 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2230 * tied to syllableFrequencies +2231 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2232 * represents how often each syllable count should appear relative to other counts; there +2233 * is no need to restrict the numbers to add up to any other number +2234 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2235 * higher numbers yield more words starting with vowels +2236 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2237 * numbers yield more words ending in vowels +2238 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2239 * often a vowel will be split into two vowels separated by one of those splitters +2240 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2241 * closingSyllables is used instead of ending normally +2242 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many +2243 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets +2244 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a +2245 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly +2246 */ +2247 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2248 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2249 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2250 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, +2251 Pattern[] sane, boolean clean) { +2252 this.openingVowels = openingVowels; +2253 this.midVowels = new String[openingVowels.length + midVowels.length]; +2254 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); +2255 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); +2256 this.openingConsonants = openingConsonants; +2257 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; +2258 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); +2259 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); +2260 this.closingConsonants = closingConsonants; +2261 this.vowelSplitters = vowelSplitters; +2262 this.closingSyllables = closingSyllables; +2263 +2264 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); +2265 +2266 totalSyllableFrequency = this.syllableFrequencies.values().sum(); +2267 if (vowelStartFrequency > 1.0) +2268 this.vowelStartFrequency = 1.0 / vowelStartFrequency; +2269 else +2270 this.vowelStartFrequency = vowelStartFrequency; +2271 if (vowelEndFrequency > 1.0) +2272 this.vowelEndFrequency = 1.0 / vowelEndFrequency; +2273 else +2274 this.vowelEndFrequency = vowelEndFrequency; +2275 if (vowelSplitters.length == 0) +2276 this.vowelSplitFrequency = 0.0; +2277 else if (vowelSplitFrequency > 1.0) +2278 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; +2279 else +2280 this.vowelSplitFrequency = vowelSplitFrequency; +2281 if (closingSyllables.length == 0) +2282 this.syllableEndFrequency = 0.0; +2283 else if (syllableEndFrequency > 1.0) +2284 this.syllableEndFrequency = 1.0 / syllableEndFrequency; +2285 else +2286 this.syllableEndFrequency = syllableEndFrequency; +2287 this.clean = clean; +2288 sanityChecks = sane; +2289 modifiers = new ArrayList<>(16); +2290 } +2291 +2292 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2293 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, +2294 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, +2295 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, +2296 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, +2297 List<Modifier> modifiers) { +2298 this.openingVowels = copyStrings(openingVowels); +2299 this.midVowels = copyStrings(midVowels); +2300 this.openingConsonants = copyStrings(openingConsonants); +2301 this.midConsonants = copyStrings(midConsonants); +2302 this.closingConsonants = copyStrings(closingConsonants); +2303 this.closingSyllables = copyStrings(closingSyllables); +2304 this.vowelSplitters = copyStrings(vowelSplitters); +2305 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); +2306 this.vowelStartFrequency = vowelStartFrequency; +2307 this.vowelEndFrequency = vowelEndFrequency; +2308 this.vowelSplitFrequency = vowelSplitFrequency; +2309 this.syllableEndFrequency = syllableEndFrequency; +2310 for (Double freq : this.syllableFrequencies.values()) { +2311 totalSyllableFrequency += freq; +2312 } +2313 if (sanityChecks == null) +2314 this.sanityChecks = null; +2315 else { +2316 this.sanityChecks = new Pattern[sanityChecks.length]; +2317 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); +2318 } +2319 this.clean = clean; +2320 this.modifiers = new ArrayList<>(modifiers); +2321 } +2322 +2323 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, +2324 Set<String> forbidden, RNG rng, double repeatSingleChance, +2325 int preferredLimit) { +2326 int l, sz = parts.size(); +2327 List<String> working = new ArrayList<>(sz * 24); +2328 String pair; +2329 for (int e = 0; e < parts.size(); e++) { +2330 Map.Entry<String, String> sn = parts.entryAt(e); +2331 if (missingSounds.contains(sn.getKey())) +2332 continue; +2333 for (String t : sn.getValue().split(" ")) { +2334 if (forbidden.contains(t)) +2335 continue; +2336 l = t.length(); +2337 int num; +2338 char c; +2339 switch (l) { +2340 case 0: +2341 break; +2342 case 1: +2343 working.add(t); +2344 working.add(t); +2345 working.add(t); +2346 c = t.charAt(0); +2347 num = 0; +2348 boolean repeat = true; +2349 switch (c) { +2350 case 'w': +2351 num += 2; +2352 case 'y': +2353 case 'h': +2354 num += 4; +2355 case 'q': +2356 case 'x': +2357 num += 4; +2358 repeat = false; +2359 break; +2360 case 'i': +2361 case 'u': +2362 repeat = false; +2363 num = 13; +2364 break; +2365 case 'z': +2366 case 'v': +2367 num = 4; +2368 break; +2369 case 'j': +2370 num = 7; +2371 break; +2372 default: +2373 if (e >= preferredLimit) +2374 num = 6; +2375 else +2376 num = 13; +2377 } +2378 for (int i = 0; i < num * 3; i++) { +2379 if (rng.nextDouble() < 0.75) { +2380 working.add(t); +2381 } +2382 } +2383 +2384 if (repeat && rng.nextDouble() < repeatSingleChance) { +2385 pair = t + t; +2386 if (missingSounds.contains(pair)) +2387 continue; +2388 working.add(pair); +2389 working.add(pair); +2390 working.add(pair); +2391 if (rng.nextDouble() < 0.7) { +2392 working.add(pair); +2393 working.add(pair); +2394 } +2395 if (rng.nextDouble() < 0.7) { +2396 working.add(pair); +2397 } +2398 } +2399 +2400 break; +2401 case 2: +2402 if (rng.nextDouble() < 0.65) { +2403 c = t.charAt(1); +2404 num = 0; +2405 switch (c) { +2406 case 'z': +2407 num = 1; +2408 break; +2409 case 'w': +2410 num = 3; +2411 break; +2412 case 'n': +2413 num = 4; +2414 break; +2415 default: +2416 +2417 if (e >= preferredLimit) +2418 num = 2; +2419 else +2420 num = 7; +2421 } +2422 working.add(t); +2423 for (int i = 0; i < num; i++) { +2424 if (rng.nextDouble() < 0.25) { +2425 working.add(t); +2426 } +2427 } +2428 } +2429 break; +2430 case 3: +2431 if (rng.nextDouble() < 0.5) { +2432 c = t.charAt(0); +2433 switch (c) { +2434 case 'z': +2435 num = 1; +2436 break; +2437 case 'w': +2438 num = 3; +2439 break; +2440 case 'n': +2441 num = 4; +2442 break; +2443 default: +2444 if (e >= preferredLimit) +2445 num = 2; +2446 else +2447 num = 6; +2448 } +2449 working.add(t); +2450 for (int i = 0; i < num; i++) { +2451 if (rng.nextDouble() < 0.2) { +2452 working.add(t); +2453 } +2454 } +2455 } +2456 break; +2457 default: +2458 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { +2459 working.add(t); +2460 } +2461 break; +2462 } +2463 } +2464 } +2465 return working.toArray(new String[0]); +2466 } +2467 +2468 /*private static final String[][] openVowels = new String[][]{ +2469 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, +2470 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, +2471 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, +2472 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, +2473 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, +2474 }; +2475*/ +2476 +2477 public static FakeLanguageGen randomLanguage(RNG rng) { +2478 return randomLanguage(rng.nextLong()); +2479 } +2480 +2481 public static FakeLanguageGen randomLanguage(long seed) { +2482 StatefulRNG rng = new StatefulRNG(seed); +2483 int[] lengths = new int[rng.between(3, 5)]; +2484 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); +2485 double[] chances = new double[lengths.length]; +2486 System.arraycopy(new double[]{ +2487 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) +2488 }, 0, chances, 0, chances.length); +2489 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); +2490 int sz = openCons.size(); +2491 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); +2492 OrderedMap<String, String> +2493 parts0 = new OrderedMap<>(openVowels), +2494 parts1 = new OrderedMap<>(openCons), +2495 parts2 = new OrderedMap<>(midCons), +2496 parts3 = new OrderedMap<>(closeCons); +2497 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); +2498 parts1.reorder(reordering); +2499 parts2.reorder(reordering); +2500 parts3.reorder(reordering); +2501 parts0.reorder(vOrd); +2502 int n = 0; +2503 +2504 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; +2505 +2506 for (n = 0; n < mn; n++) { +2507 missingSounds.add(parts0.keyAt(0)); +2508 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); +2509 parts0.removeFirst(); +2510 } +2511 p0s = parts0.size(); +2512 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); +2513 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; +2514 int vowelAccent = rng.between(1, 7); +2515 for (int i = 0; i < sz0; i++) { +2516 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; +2517 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; +2518 } +2519 if (rng.nextDouble() < 0.8) { +2520 for (int i = 0; i < sz0; i++) { +2521 char ac = nextAccents[i], ua = unaccented[i]; +2522 String v = "", uas = String.valueOf(ua); +2523 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); +2524 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); +2525 for (int j = 0; j < p0s; j++) { +2526 String k = parts0.keyAt(j); +2527 if (uas.equals(k)) +2528 v = parts0.getAt(j); +2529 else { +2530 String current = parts0.getAt(j); +2531 String[] splits = current.split(" "); +2532 for (int s = 0; s < splits.length; s++) { +2533 if (forbidden.contains(uas) && splits[s].contains(uas)) +2534 forbidden.add(splits[s].replace(ua, ac)); +2535 } +2536 parts0.put(k, rep.replace(current)); +2537 } +2538 } +2539 parts0.put(String.valueOf(ac), repLess.replace(v)); +2540 } +2541 } +2542 +2543 n = 0; +2544 if (rng.nextDouble() < 0.75) { +2545 missingSounds.add("z"); +2546 Collections.addAll(forbidden, parts1.get("z").split(" ")); +2547 Collections.addAll(forbidden, parts2.get("z").split(" ")); +2548 Collections.addAll(forbidden, parts3.get("z").split(" ")); +2549 n++; +2550 } +2551 if (rng.nextDouble() < 0.82) { +2552 missingSounds.add("x"); +2553 Collections.addAll(forbidden, parts1.get("x").split(" ")); +2554 Collections.addAll(forbidden, parts2.get("x").split(" ")); +2555 Collections.addAll(forbidden, parts3.get("x").split(" ")); +2556 n++; +2557 } +2558 if (rng.nextDouble() < 0.92) { +2559 missingSounds.add("qu"); +2560 Collections.addAll(forbidden, parts1.get("qu").split(" ")); +2561 Collections.addAll(forbidden, parts2.get("qu").split(" ")); +2562 Collections.addAll(forbidden, parts3.get("qu").split(" ")); +2563 n++; +2564 } +2565 if (rng.nextDouble() < 0.96) { +2566 missingSounds.add("q"); +2567 Collections.addAll(forbidden, parts1.get("q").split(" ")); +2568 Collections.addAll(forbidden, parts2.get("q").split(" ")); +2569 Collections.addAll(forbidden, parts3.get("q").split(" ")); +2570 n++; +2571 } +2572 if (rng.nextDouble() < 0.97) { +2573 missingSounds.add("tl"); +2574 Collections.addAll(forbidden, parts1.get("tl").split(" ")); +2575 Collections.addAll(forbidden, parts2.get("tl").split(" ")); +2576 Collections.addAll(forbidden, parts3.get("tl").split(" ")); +2577 n++; +2578 } +2579 if (rng.nextDouble() < 0.86) { +2580 missingSounds.add("ph"); +2581 Collections.addAll(forbidden, parts1.get("ph").split(" ")); +2582 Collections.addAll(forbidden, parts2.get("ph").split(" ")); +2583 Collections.addAll(forbidden, parts3.get("ph").split(" ")); +2584 n++; +2585 } +2586 if (rng.nextDouble() < 0.94) { +2587 missingSounds.add("kh"); +2588 Collections.addAll(forbidden, parts1.get("kh").split(" ")); +2589 Collections.addAll(forbidden, parts2.get("kh").split(" ")); +2590 Collections.addAll(forbidden, parts3.get("kh").split(" ")); +2591 n++; +2592 } +2593 if (rng.nextDouble() < 0.96) { +2594 missingSounds.add("bh"); +2595 missingSounds.add("dh"); +2596 Collections.addAll(forbidden, parts1.get("bh").split(" ")); +2597 Collections.addAll(forbidden, parts2.get("bh").split(" ")); +2598 Collections.addAll(forbidden, parts3.get("bh").split(" ")); +2599 Collections.addAll(forbidden, parts1.get("dh").split(" ")); +2600 Collections.addAll(forbidden, parts2.get("dh").split(" ")); +2601 Collections.addAll(forbidden, parts3.get("dh").split(" ")); +2602 n++; +2603 n++; +2604 } +2605 +2606 for (; n < sz * removalRate; n++) { +2607 missingSounds.add(parts1.keyAt(n)); +2608 missingSounds.add(parts2.keyAt(n)); +2609 missingSounds.add(parts3.keyAt(n)); +2610 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); +2611 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); +2612 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); +2613 } +2614 +2615 return new FakeLanguageGen( +2616 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), +2617 new String[]{"y", "y"}, +2618 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), +2619 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), +2620 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), +2621 new String[]{}, +2622 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); +2623 } +2624 +2625 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { +2626 CharSequence fixed = removeAccents(testing); +2627 for (int i = 0; i < checks.length; i++) { +2628 if (checks[i].matcher(fixed).find()) +2629 return false; +2630 } +2631 return true; +2632 } +2633 +2634 /** +2635 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text +2636 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives +2637 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers +2638 * that could look like letters. +2639 * @param testing the text, as a CharSequence such as a String, to check +2640 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't +2641 */ +2642 public static boolean checkVulgarity(CharSequence testing) +2643 { +2644 CharSequence fixed = removeAccents(testing); +2645 for (int i = 0; i < vulgarChecks.length; i++) { +2646 if (vulgarChecks[i].matcher(fixed).find()) +2647 { +2648 System.out.println(vulgarChecks[i]); +2649 return true; +2650 } +2651 } +2652 return false; +2653 } 2654 -2655 //sb.append(close.replaceAll("@\\d", sb.toString())); -2656 } -2657 if (!close.contains("@")) -2658 ender.append(close); -2659 else if (rng.nextDouble() < vowelEndFrequency) { -2660 ender.append(rng.getRandomElement(midVowels)); -2661 if (rng.nextDouble() < vowelSplitFrequency) { -2662 ender.append(rng.getRandomElement(vowelSplitters)); -2663 ender.append(rng.getRandomElement(midVowels)); -2664 } -2665 } -2666 } else { -2667 ender.append(rng.getRandomElement(midVowels)); -2668 if (rng.nextDouble() < vowelSplitFrequency) { -2669 ender.append(rng.getRandomElement(vowelSplitters)); -2670 ender.append(rng.getRandomElement(midVowels)); -2671 } -2672 if (rng.nextDouble() >= vowelEndFrequency) { -2673 ender.append(rng.getRandomElement(closingConsonants)); -2674 if (rng.nextDouble() < syllableEndFrequency) { -2675 close = rng.getRandomElement(closingSyllables); -2676 if (close.contains("@") && (syllables & 1) == 0) { -2677 redouble = true; -2678 syllables = (syllables | 1) >> 1; -2679 -2680 //sb.append(close.replaceAll("@\\d", sb.toString())); -2681 } -2682 if (!close.contains("@")) -2683 ender.append(close); -2684 } -2685 } -2686 } -2687 i += vowelClusters.matcher(ender).findAll().count(); -2688 -2689 } -2690 -2691 for (; i < syllables; i++) { -2692 sb.append(rng.getRandomElement(midVowels)); -2693 if (rng.nextDouble() < vowelSplitFrequency) { -2694 sb.append(rng.getRandomElement(vowelSplitters)); -2695 sb.append(rng.getRandomElement(midVowels)); -2696 } -2697 sb.append(rng.getRandomElement(midConsonants)); -2698 } -2699 -2700 sb.append(ender); -2701 if (redouble && i <= syllables + 1) { -2702 sb.append(close.replaceAll("@", sb.toString())); -2703 } -2704 -2705 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2706 continue; -2707 -2708 for (Modifier mod : modifiers) { -2709 sb = mod.modify(rng, sb); -2710 } -2711 -2712 if (capitalize) -2713 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2714 -2715 if (clean && !checkAll(sb, vulgarChecks)) -2716 continue; -2717 return sb.toString(); -2718 } -2719 } -2720 -2721 /** -2722 * Generate a word from this FakeLanguageGen using the specified RNG. -2723 * -2724 * @param rng the RNG to use for the randomized string building -2725 * @param capitalize true if the word should start with a capital letter, false otherwise -2726 * @return a word in the fake language as a String -2727 */ -2728 public String word(RNG rng, boolean capitalize, int approxSyllables) { -2729 return word(rng, capitalize, approxSyllables, null); -2730 } -2731 -2732 /** -2733 * Generate a word from this FakeLanguageGen using the specified RNG. -2734 * -2735 * @param rng the RNG to use for the randomized string building -2736 * @param capitalize true if the word should start with a capital letter, false otherwise -2737 * @return a word in the fake language as a String -2738 */ -2739 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { -2740 if (approxSyllables <= 0) { -2741 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2742 for (Modifier mod : modifiers) { -2743 sb = mod.modify(rng, sb); -2744 } -2745 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2746 return sb.toString(); -2747 } -2748 while (true) { -2749 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2750 int i = 0; -2751 if (rng.nextDouble() < vowelStartFrequency) { -2752 sb.append(rng.getRandomElement(openingVowels)); -2753 if (approxSyllables == 1 && closingConsonants.length > 0) -2754 sb.append(rng.getRandomElement(closingConsonants)); -2755 else if (midConsonants.length > 0) -2756 sb.append(rng.getRandomElement(midConsonants)); -2757 i++; -2758 } else if (openingConsonants.length > 0) { -2759 sb.append(rng.getRandomElement(openingConsonants)); -2760 } -2761 String close = ""; -2762 boolean redouble = false; -2763 if (i < approxSyllables) { -2764 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { -2765 close = rng.getRandomElement(closingSyllables); -2766 if (close.contains("@") && (approxSyllables & 1) == 0) { -2767 redouble = true; -2768 approxSyllables = approxSyllables >> 1; -2769 -2770 //sb.append(close.replaceAll("@\\d", sb.toString())); -2771 } -2772 if (!close.contains("@")) -2773 ender.append(close); -2774 else if (redouble && rng.nextDouble() < vowelEndFrequency) { -2775 ender.append(rng.getRandomElement(midVowels)); -2776 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { -2777 ender.append(rng.getRandomElement(vowelSplitters)); -2778 ender.append(rng.getRandomElement(midVowels)); -2779 } -2780 } -2781 } else { -2782 ender.append(rng.getRandomElement(midVowels)); -2783 if (rng.nextDouble() < vowelSplitFrequency) { -2784 ender.append(rng.getRandomElement(vowelSplitters)); -2785 ender.append(rng.getRandomElement(midVowels)); -2786 } -2787 if (rng.nextDouble() >= vowelEndFrequency) { -2788 ender.append(rng.getRandomElement(closingConsonants)); -2789 if (rng.nextDouble() < syllableEndFrequency) { -2790 close = rng.getRandomElement(closingSyllables); -2791 if (close.contains("@") && (approxSyllables & 1) == 0) { -2792 redouble = true; -2793 approxSyllables = approxSyllables >> 1; -2794 -2795 //sb.append(close.replaceAll("@\\d", sb.toString())); -2796 } -2797 if (!close.contains("@")) -2798 ender.append(close); -2799 } -2800 } -2801 } -2802 i += vowelClusters.matcher(ender).findAll().count(); -2803 } -2804 -2805 for (; i < approxSyllables; i++) { -2806 sb.append(rng.getRandomElement(midVowels)); -2807 if (rng.nextDouble() < vowelSplitFrequency) { -2808 sb.append(rng.getRandomElement(vowelSplitters)); -2809 sb.append(rng.getRandomElement(midVowels)); -2810 } -2811 sb.append(rng.getRandomElement(midConsonants)); -2812 } -2813 -2814 sb.append(ender); -2815 if (redouble && i <= approxSyllables + 1) { -2816 sb.append(close.replaceAll("@", sb.toString())); -2817 } -2818 -2819 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2820 continue; -2821 -2822 for (Modifier mod : modifiers) { -2823 sb = mod.modify(rng, sb); -2824 } -2825 -2826 if (clean && !checkAll(sb, vulgarChecks)) -2827 continue; -2828 -2829 if (additionalChecks != null && !checkAll(sb, additionalChecks)) -2830 continue; -2831 -2832 if (capitalize) -2833 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2834 -2835 return sb.toString(); -2836 } -2837 } -2838 -2839 /** -2840 * Generate a word from this FakeLanguageGen using the specified RNG. -2841 * -2842 * @param rng the RNG to use for the randomized string building -2843 * @param capitalize true if the word should start with a capital letter, false otherwise -2844 * @return a word in the fake language as a String -2845 */ -2846 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { -2847 if (approxSyllables <= 0) { -2848 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2849 for (Modifier mod : modifiers) { -2850 sb = mod.modify(rng, sb); +2655 /** +2656 * Generate a word from this FakeLanguageGen, using and changing the current seed. +2657 * +2658 * @param capitalize true if the word should start with a capital letter, false otherwise +2659 * @return a word in the fake language as a String +2660 */ +2661 public String word(boolean capitalize) { +2662 return word(srng, capitalize); +2663 } +2664 +2665 /** +2666 * Generate a word from this FakeLanguageGen using the specified RNG. +2667 * +2668 * @param rng the RNG to use for the randomized string building +2669 * @param capitalize true if the word should start with a capital letter, false otherwise +2670 * @return a word in the fake language as a String +2671 */ +2672 public String word(RNG rng, boolean capitalize) { +2673 while (true) { +2674 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2675 double syllableChance = rng.nextDouble(totalSyllableFrequency); +2676 int syllables = 1, i = 0; +2677 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { +2678 if (syllableChance < kv.getDoubleValue()) { +2679 syllables = kv.getIntKey(); +2680 break; +2681 } else +2682 syllableChance -= kv.getDoubleValue(); +2683 } +2684 if (rng.nextDouble() < vowelStartFrequency) { +2685 sb.append(rng.getRandomElement(openingVowels)); +2686 if (syllables == 1) +2687 sb.append(rng.getRandomElement(closingConsonants)); +2688 else +2689 sb.append(rng.getRandomElement(midConsonants)); +2690 i++; +2691 } else { +2692 sb.append(rng.getRandomElement(openingConsonants)); +2693 } +2694 String close = ""; +2695 boolean redouble = false; +2696 if (i < syllables) { +2697 if (rng.nextDouble() < syllableEndFrequency) { +2698 close = rng.getRandomElement(closingSyllables); +2699 if (close.contains("@") && (syllables & 1) == 0) { +2700 redouble = true; +2701 syllables = (syllables | 1) >> 1; +2702 +2703 //sb.append(close.replaceAll("@\\d", sb.toString())); +2704 } +2705 if (!close.contains("@")) +2706 ender.append(close); +2707 else if (rng.nextDouble() < vowelEndFrequency) { +2708 ender.append(rng.getRandomElement(midVowels)); +2709 if (rng.nextDouble() < vowelSplitFrequency) { +2710 ender.append(rng.getRandomElement(vowelSplitters)); +2711 ender.append(rng.getRandomElement(midVowels)); +2712 } +2713 } +2714 } else { +2715 ender.append(rng.getRandomElement(midVowels)); +2716 if (rng.nextDouble() < vowelSplitFrequency) { +2717 ender.append(rng.getRandomElement(vowelSplitters)); +2718 ender.append(rng.getRandomElement(midVowels)); +2719 } +2720 if (rng.nextDouble() >= vowelEndFrequency) { +2721 ender.append(rng.getRandomElement(closingConsonants)); +2722 if (rng.nextDouble() < syllableEndFrequency) { +2723 close = rng.getRandomElement(closingSyllables); +2724 if (close.contains("@") && (syllables & 1) == 0) { +2725 redouble = true; +2726 syllables = (syllables | 1) >> 1; +2727 +2728 //sb.append(close.replaceAll("@\\d", sb.toString())); +2729 } +2730 if (!close.contains("@")) +2731 ender.append(close); +2732 } +2733 } +2734 } +2735 i += vowelClusters.matcher(ender).findAll().count(); +2736 +2737 } +2738 +2739 for (; i < syllables; i++) { +2740 sb.append(rng.getRandomElement(midVowels)); +2741 if (rng.nextDouble() < vowelSplitFrequency) { +2742 sb.append(rng.getRandomElement(vowelSplitters)); +2743 sb.append(rng.getRandomElement(midVowels)); +2744 } +2745 sb.append(rng.getRandomElement(midConsonants)); +2746 } +2747 +2748 sb.append(ender); +2749 if (redouble && i <= syllables + 1) { +2750 sb.append(close.replaceAll("@", sb.toString())); +2751 } +2752 +2753 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2754 continue; +2755 +2756 for (Modifier mod : modifiers) { +2757 sb = mod.modify(rng, sb); +2758 } +2759 +2760 if (capitalize) +2761 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2762 +2763 if (clean && !checkAll(sb, vulgarChecks)) +2764 continue; +2765 return sb.toString(); +2766 } +2767 } +2768 +2769 /** +2770 * Generate a word from this FakeLanguageGen using the specified RNG. +2771 * +2772 * @param rng the RNG to use for the randomized string building +2773 * @param capitalize true if the word should start with a capital letter, false otherwise +2774 * @return a word in the fake language as a String +2775 */ +2776 public String word(RNG rng, boolean capitalize, int approxSyllables) { +2777 return word(rng, capitalize, approxSyllables, null); +2778 } +2779 +2780 /** +2781 * Generate a word from this FakeLanguageGen using the specified RNG. +2782 * +2783 * @param rng the RNG to use for the randomized string building +2784 * @param capitalize true if the word should start with a capital letter, false otherwise +2785 * @return a word in the fake language as a String +2786 */ +2787 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { +2788 if (approxSyllables <= 0) { +2789 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2790 for (Modifier mod : modifiers) { +2791 sb = mod.modify(rng, sb); +2792 } +2793 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2794 return sb.toString(); +2795 } +2796 while (true) { +2797 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2798 int i = 0; +2799 if (rng.nextDouble() < vowelStartFrequency) { +2800 sb.append(rng.getRandomElement(openingVowels)); +2801 if (approxSyllables == 1 && closingConsonants.length > 0) +2802 sb.append(rng.getRandomElement(closingConsonants)); +2803 else if (midConsonants.length > 0) +2804 sb.append(rng.getRandomElement(midConsonants)); +2805 i++; +2806 } else if (openingConsonants.length > 0) { +2807 sb.append(rng.getRandomElement(openingConsonants)); +2808 } +2809 String close = ""; +2810 boolean redouble = false; +2811 if (i < approxSyllables) { +2812 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { +2813 close = rng.getRandomElement(closingSyllables); +2814 if (close.contains("@") && (approxSyllables & 1) == 0) { +2815 redouble = true; +2816 approxSyllables = approxSyllables >> 1; +2817 +2818 //sb.append(close.replaceAll("@\\d", sb.toString())); +2819 } +2820 if (!close.contains("@")) +2821 ender.append(close); +2822 else if (redouble && rng.nextDouble() < vowelEndFrequency) { +2823 ender.append(rng.getRandomElement(midVowels)); +2824 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { +2825 ender.append(rng.getRandomElement(vowelSplitters)); +2826 ender.append(rng.getRandomElement(midVowels)); +2827 } +2828 } +2829 } else { +2830 ender.append(rng.getRandomElement(midVowels)); +2831 if (rng.nextDouble() < vowelSplitFrequency) { +2832 ender.append(rng.getRandomElement(vowelSplitters)); +2833 ender.append(rng.getRandomElement(midVowels)); +2834 } +2835 if (rng.nextDouble() >= vowelEndFrequency) { +2836 ender.append(rng.getRandomElement(closingConsonants)); +2837 if (rng.nextDouble() < syllableEndFrequency) { +2838 close = rng.getRandomElement(closingSyllables); +2839 if (close.contains("@") && (approxSyllables & 1) == 0) { +2840 redouble = true; +2841 approxSyllables = approxSyllables >> 1; +2842 +2843 //sb.append(close.replaceAll("@\\d", sb.toString())); +2844 } +2845 if (!close.contains("@")) +2846 ender.append(close); +2847 } +2848 } +2849 } +2850 i += vowelClusters.matcher(ender).findAll().count(); 2851 } -2852 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2853 return sb.toString(); -2854 } -2855 int numSeeds, fraction = 1; -2856 if (reseeds != null) -2857 numSeeds = Math.min(reseeds.length, approxSyllables - 1); -2858 else numSeeds = 0; -2859 while (true) { -2860 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2861 int i = 0; -2862 if (rng.nextDouble() < vowelStartFrequency) { -2863 sb.append(rng.getRandomElement(openingVowels)); -2864 if (approxSyllables == 1) -2865 sb.append(rng.getRandomElement(closingConsonants)); -2866 else -2867 sb.append(rng.getRandomElement(midConsonants)); -2868 i++; -2869 } else { -2870 sb.append(rng.getRandomElement(openingConsonants)); -2871 } -2872 String close = ""; -2873 boolean redouble = false; -2874 if (i < approxSyllables) { -2875 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2876 rng.setState(reseeds[fraction++ - 1]); -2877 if (rng.nextDouble() < syllableEndFrequency) { -2878 close = rng.getRandomElement(closingSyllables); -2879 if (close.contains("@") && (approxSyllables & 1) == 0) { -2880 redouble = true; -2881 approxSyllables = approxSyllables >> 1; -2882 } -2883 if (!close.contains("@")) -2884 ender.append(close); -2885 else if (rng.nextDouble() < vowelEndFrequency) { -2886 ender.append(rng.getRandomElement(midVowels)); -2887 if (rng.nextDouble() < vowelSplitFrequency) { -2888 ender.append(rng.getRandomElement(vowelSplitters)); -2889 ender.append(rng.getRandomElement(midVowels)); -2890 } -2891 } -2892 } else { -2893 ender.append(rng.getRandomElement(midVowels)); -2894 if (rng.nextDouble() < vowelSplitFrequency) { -2895 ender.append(rng.getRandomElement(vowelSplitters)); -2896 ender.append(rng.getRandomElement(midVowels)); -2897 } -2898 if (rng.nextDouble() >= vowelEndFrequency) { -2899 ender.append(rng.getRandomElement(closingConsonants)); -2900 if (rng.nextDouble() < syllableEndFrequency) { -2901 close = rng.getRandomElement(closingSyllables); -2902 if (close.contains("@") && (approxSyllables & 1) == 0) { -2903 redouble = true; -2904 approxSyllables = approxSyllables >> 1; -2905 -2906 //sb.append(close.replaceAll("@\\d", sb.toString())); -2907 } -2908 if (!close.contains("@")) -2909 ender.append(close); -2910 } -2911 } -2912 } -2913 i += vowelClusters.matcher(ender).findAll().count(); -2914 } -2915 -2916 for (; i < approxSyllables; i++) { -2917 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2918 rng.setState(reseeds[fraction++ - 1]); -2919 sb.append(rng.getRandomElement(midVowels)); -2920 if (rng.nextDouble() < vowelSplitFrequency) { -2921 sb.append(rng.getRandomElement(vowelSplitters)); -2922 sb.append(rng.getRandomElement(midVowels)); -2923 } -2924 sb.append(rng.getRandomElement(midConsonants)); -2925 } -2926 -2927 sb.append(ender); -2928 if (redouble && i <= approxSyllables + 1) { -2929 sb.append(close.replaceAll("@", sb.toString())); -2930 } -2931 -2932 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2933 continue; -2934 -2935 for (Modifier mod : modifiers) { -2936 sb = mod.modify(rng, sb); -2937 } -2938 -2939 if (capitalize) -2940 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2941 -2942 if (clean && !checkAll(sb, vulgarChecks)) -2943 continue; -2944 return sb.toString(); -2945 } -2946 } -2947 -2948 /** -2949 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2950 * -2951 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2952 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2953 * @return a sentence in the gibberish language as a String -2954 */ -2955 public String sentence(int minWords, int maxWords) { -2956 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2957 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2958 } -2959 -2960 /** -2961 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2962 * -2963 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2964 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2965 * @return a sentence in the gibberish language as a String -2966 */ -2967 public String sentence(RNG rng, int minWords, int maxWords) { -2968 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2969 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2970 } -2971 -2972 /** -2973 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2974 * -2975 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2976 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2977 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2978 * space in the middle of a sentence -2979 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2980 * the very end of a sentence -2981 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -2982 * midPunctuation should be inserted before spaces -2983 * @return a sentence in the gibberish language as a String -2984 */ -2985 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -2986 double midPunctuationFrequency) { -2987 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -2988 } +2852 +2853 for (; i < approxSyllables; i++) { +2854 sb.append(rng.getRandomElement(midVowels)); +2855 if (rng.nextDouble() < vowelSplitFrequency) { +2856 sb.append(rng.getRandomElement(vowelSplitters)); +2857 sb.append(rng.getRandomElement(midVowels)); +2858 } +2859 sb.append(rng.getRandomElement(midConsonants)); +2860 } +2861 +2862 sb.append(ender); +2863 if (redouble && i <= approxSyllables + 1) { +2864 sb.append(close.replaceAll("@", sb.toString())); +2865 } +2866 +2867 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2868 continue; +2869 +2870 for (Modifier mod : modifiers) { +2871 sb = mod.modify(rng, sb); +2872 } +2873 +2874 if (clean && !checkAll(sb, vulgarChecks)) +2875 continue; +2876 +2877 if (additionalChecks != null && !checkAll(sb, additionalChecks)) +2878 continue; +2879 +2880 if (capitalize) +2881 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2882 +2883 return sb.toString(); +2884 } +2885 } +2886 +2887 /** +2888 * Generate a word from this FakeLanguageGen using the specified RNG. +2889 * +2890 * @param rng the RNG to use for the randomized string building +2891 * @param capitalize true if the word should start with a capital letter, false otherwise +2892 * @return a word in the fake language as a String +2893 */ +2894 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { +2895 if (approxSyllables <= 0) { +2896 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2897 for (Modifier mod : modifiers) { +2898 sb = mod.modify(rng, sb); +2899 } +2900 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2901 return sb.toString(); +2902 } +2903 int numSeeds, fraction = 1; +2904 if (reseeds != null) +2905 numSeeds = Math.min(reseeds.length, approxSyllables - 1); +2906 else numSeeds = 0; +2907 while (true) { +2908 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2909 int i = 0; +2910 if (rng.nextDouble() < vowelStartFrequency) { +2911 sb.append(rng.getRandomElement(openingVowels)); +2912 if (approxSyllables == 1) +2913 sb.append(rng.getRandomElement(closingConsonants)); +2914 else +2915 sb.append(rng.getRandomElement(midConsonants)); +2916 i++; +2917 } else { +2918 sb.append(rng.getRandomElement(openingConsonants)); +2919 } +2920 String close = ""; +2921 boolean redouble = false; +2922 if (i < approxSyllables) { +2923 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2924 rng.setState(reseeds[fraction++ - 1]); +2925 if (rng.nextDouble() < syllableEndFrequency) { +2926 close = rng.getRandomElement(closingSyllables); +2927 if (close.contains("@") && (approxSyllables & 1) == 0) { +2928 redouble = true; +2929 approxSyllables = approxSyllables >> 1; +2930 } +2931 if (!close.contains("@")) +2932 ender.append(close); +2933 else if (rng.nextDouble() < vowelEndFrequency) { +2934 ender.append(rng.getRandomElement(midVowels)); +2935 if (rng.nextDouble() < vowelSplitFrequency) { +2936 ender.append(rng.getRandomElement(vowelSplitters)); +2937 ender.append(rng.getRandomElement(midVowels)); +2938 } +2939 } +2940 } else { +2941 ender.append(rng.getRandomElement(midVowels)); +2942 if (rng.nextDouble() < vowelSplitFrequency) { +2943 ender.append(rng.getRandomElement(vowelSplitters)); +2944 ender.append(rng.getRandomElement(midVowels)); +2945 } +2946 if (rng.nextDouble() >= vowelEndFrequency) { +2947 ender.append(rng.getRandomElement(closingConsonants)); +2948 if (rng.nextDouble() < syllableEndFrequency) { +2949 close = rng.getRandomElement(closingSyllables); +2950 if (close.contains("@") && (approxSyllables & 1) == 0) { +2951 redouble = true; +2952 approxSyllables = approxSyllables >> 1; +2953 +2954 //sb.append(close.replaceAll("@\\d", sb.toString())); +2955 } +2956 if (!close.contains("@")) +2957 ender.append(close); +2958 } +2959 } +2960 } +2961 i += vowelClusters.matcher(ender).findAll().count(); +2962 } +2963 +2964 for (; i < approxSyllables; i++) { +2965 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2966 rng.setState(reseeds[fraction++ - 1]); +2967 sb.append(rng.getRandomElement(midVowels)); +2968 if (rng.nextDouble() < vowelSplitFrequency) { +2969 sb.append(rng.getRandomElement(vowelSplitters)); +2970 sb.append(rng.getRandomElement(midVowels)); +2971 } +2972 sb.append(rng.getRandomElement(midConsonants)); +2973 } +2974 +2975 sb.append(ender); +2976 if (redouble && i <= approxSyllables + 1) { +2977 sb.append(close.replaceAll("@", sb.toString())); +2978 } +2979 +2980 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2981 continue; +2982 +2983 for (Modifier mod : modifiers) { +2984 sb = mod.modify(rng, sb); +2985 } +2986 +2987 if (capitalize) +2988 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); 2989 -2990 /** -2991 * Generate a sentence from this FakeLanguageGen using the specific RNG. -2992 * -2993 * @param rng the RNG to use for the randomized string building -2994 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2995 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2996 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2997 * space in the middle of a sentence -2998 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2999 * the very end of a sentence -3000 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3001 * midPunctuation should be inserted before spaces -3002 * @return a sentence in the gibberish language as a String -3003 */ -3004 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3005 double midPunctuationFrequency) { -3006 if (minWords < 1) -3007 minWords = 1; -3008 if (minWords > maxWords) -3009 maxWords = minWords; -3010 if (midPunctuationFrequency > 1.0) { -3011 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3012 } -3013 StringBuilder sb = new StringBuilder(12 * maxWords); -3014 sb.append(word(rng, true)); -3015 for (int i = 1; i < minWords; i++) { -3016 if (rng.nextDouble() < midPunctuationFrequency) { -3017 sb.append(rng.getRandomElement(midPunctuation)); -3018 } -3019 sb.append(' '); -3020 sb.append(word(rng, false)); -3021 } -3022 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { -3023 if (rng.nextDouble() < midPunctuationFrequency) { -3024 sb.append(rng.getRandomElement(midPunctuation)); -3025 } -3026 sb.append(' '); -3027 sb.append(word(rng, false)); -3028 } -3029 if (endPunctuation != null && endPunctuation.length > 0) -3030 sb.append(rng.getRandomElement(endPunctuation)); -3031 return sb.toString(); -3032 } -3033 -3034 /** -3035 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. -3036 * -3037 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3038 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3039 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3040 * space in the middle of a sentence -3041 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3042 * the very end of a sentence -3043 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3044 * midPunctuation should be inserted before spaces -3045 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3046 * @return a sentence in the gibberish language as a String -3047 */ -3048 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3049 double midPunctuationFrequency, int maxChars) { -3050 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); -3051 } -3052 -3053 /** -3054 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. -3055 * -3056 * @param rng the RNG to use for the randomized string building -3057 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3058 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3059 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3060 * space in the middle of a sentence -3061 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3062 * the very end of a sentence -3063 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3064 * midPunctuation should be inserted before spaces -3065 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3066 * @return a sentence in the gibberish language as a String -3067 */ -3068 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3069 double midPunctuationFrequency, int maxChars) { -3070 if(maxChars < 0) -3071 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -3072 if (minWords < 1) -3073 minWords = 1; -3074 if (minWords > maxWords) -3075 maxWords = minWords; -3076 if (midPunctuationFrequency > 1.0) { -3077 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3078 } -3079 if (maxChars < 4) -3080 return "!"; -3081 if (maxChars <= 5 * minWords) { -3082 minWords = 1; -3083 maxWords = 1; -3084 } -3085 int frustration = 0; -3086 StringBuilder sb = new StringBuilder(maxChars); -3087 String next = word(rng, true); -3088 while (next.length() >= maxChars - 1 && frustration < 50) { -3089 next = word(rng, true); -3090 frustration++; -3091 } -3092 if (frustration >= 50) return "!"; -3093 sb.append(next); -3094 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { -3095 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3096 sb.append(rng.getRandomElement(midPunctuation)); -3097 } -3098 next = word(rng, false); -3099 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3100 next = word(rng, false); -3101 frustration++; -3102 } -3103 if (frustration >= 50) break; -3104 sb.append(' '); -3105 sb.append(next); -3106 } -3107 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { -3108 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3109 sb.append(rng.getRandomElement(midPunctuation)); -3110 } -3111 next = word(rng, false); -3112 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3113 next = word(rng, false); -3114 frustration++; -3115 } -3116 if (frustration >= 50) break; -3117 sb.append(' '); -3118 sb.append(next); -3119 } -3120 -3121 if (endPunctuation != null && endPunctuation.length > 0) { -3122 -3123 next = rng.getRandomElement(endPunctuation); -3124 if (sb.length() + next.length() >= maxChars) -3125 sb.append('.'); -3126 else -3127 sb.append(next); -3128 } -3129 -3130 if (sb.length() > maxChars) -3131 return "!"; -3132 return sb.toString(); -3133 } -3134 -3135 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { -3136 if (other.length <= 0 && me.length <= 0) -3137 return new String[]{}; -3138 String[] ret = new String[1000]; -3139 int otherCount = (int) (1000 * otherInfluence); -3140 int idx = 0; -3141 if (other.length > 0) { -3142 String[] tmp = new String[other.length]; -3143 rng.shuffle(other, tmp); -3144 for (idx = 0; idx < otherCount; idx++) { -3145 ret[idx] = tmp[idx % tmp.length]; -3146 } -3147 } -3148 if (me.length > 0) { -3149 String[] tmp = new String[me.length]; -3150 rng.shuffle(me, tmp); -3151 for (; idx < 1000; idx++) { -3152 ret[idx] = tmp[idx % tmp.length]; -3153 } -3154 } else { -3155 for (; idx < 1000; idx++) { -3156 ret[idx] = other[idx % other.length]; -3157 } -3158 } -3159 return ret; -3160 } -3161 -3162 -3163 protected String[] accentVowels(RNG rng, String[] me, double influence) { -3164 String[] ret = new String[1000]; -3165 int otherCount = (int) (1000 * influence); -3166 int idx = 0; -3167 Matcher matcher; -3168 if (me.length > 0) { -3169 String[] tmp = new String[me.length]; -3170 rng.shuffle(me, tmp); -3171 for (idx = 0; idx < otherCount; idx++) { -3172 ret[idx] = tmp[idx % tmp.length] -3173 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3174 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3175 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3176 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3177 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3178 matcher = repeats.matcher(ret[idx]); -3179 if (matcher.find()) { -3180 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3181 } -3182 } -3183 for (; idx < 1000; idx++) { -3184 ret[idx] = tmp[idx % tmp.length]; -3185 } -3186 } else -3187 return new String[]{}; -3188 return ret; -3189 } -3190 -3191 protected String[] accentConsonants(RNG rng, String[] me, double influence) { -3192 String[] ret = new String[1000]; -3193 int otherCount = (int) (1000 * influence); -3194 int idx = 0; -3195 Matcher matcher; +2990 if (clean && !checkAll(sb, vulgarChecks)) +2991 continue; +2992 return sb.toString(); +2993 } +2994 } +2995 +2996 /** +2997 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +2998 * +2999 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3000 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3001 * @return a sentence in the gibberish language as a String +3002 */ +3003 public String sentence(int minWords, int maxWords) { +3004 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3005 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3006 } +3007 +3008 /** +3009 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3010 * +3011 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3012 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3013 * @return a sentence in the gibberish language as a String +3014 */ +3015 public String sentence(RNG rng, int minWords, int maxWords) { +3016 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3017 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3018 } +3019 +3020 /** +3021 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3022 * +3023 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3024 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3025 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3026 * space in the middle of a sentence +3027 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3028 * the very end of a sentence +3029 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3030 * midPunctuation should be inserted before spaces +3031 * @return a sentence in the gibberish language as a String +3032 */ +3033 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3034 double midPunctuationFrequency) { +3035 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3036 } +3037 +3038 /** +3039 * Generate a sentence from this FakeLanguageGen using the specific RNG. +3040 * +3041 * @param rng the RNG to use for the randomized string building +3042 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3043 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3044 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3045 * space in the middle of a sentence +3046 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3047 * the very end of a sentence +3048 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3049 * midPunctuation should be inserted before spaces +3050 * @return a sentence in the gibberish language as a String +3051 */ +3052 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3053 double midPunctuationFrequency) { +3054 if (minWords < 1) +3055 minWords = 1; +3056 if (minWords > maxWords) +3057 maxWords = minWords; +3058 if (midPunctuationFrequency > 1.0) { +3059 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3060 } +3061 StringBuilder sb = new StringBuilder(12 * maxWords); +3062 sb.append(word(rng, true)); +3063 for (int i = 1; i < minWords; i++) { +3064 if (rng.nextDouble() < midPunctuationFrequency) { +3065 sb.append(rng.getRandomElement(midPunctuation)); +3066 } +3067 sb.append(' '); +3068 sb.append(word(rng, false)); +3069 } +3070 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { +3071 if (rng.nextDouble() < midPunctuationFrequency) { +3072 sb.append(rng.getRandomElement(midPunctuation)); +3073 } +3074 sb.append(' '); +3075 sb.append(word(rng, false)); +3076 } +3077 if (endPunctuation != null && endPunctuation.length > 0) +3078 sb.append(rng.getRandomElement(endPunctuation)); +3079 return sb.toString(); +3080 } +3081 +3082 /** +3083 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. +3084 * +3085 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3086 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3087 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3088 * space in the middle of a sentence +3089 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3090 * the very end of a sentence +3091 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3092 * midPunctuation should be inserted before spaces +3093 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3094 * @return a sentence in the gibberish language as a String +3095 */ +3096 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3097 double midPunctuationFrequency, int maxChars) { +3098 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); +3099 } +3100 +3101 /** +3102 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. +3103 * +3104 * @param rng the RNG to use for the randomized string building +3105 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3106 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3107 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3108 * space in the middle of a sentence +3109 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3110 * the very end of a sentence +3111 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3112 * midPunctuation should be inserted before spaces +3113 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3114 * @return a sentence in the gibberish language as a String +3115 */ +3116 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3117 double midPunctuationFrequency, int maxChars) { +3118 if(maxChars < 0) +3119 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3120 if (minWords < 1) +3121 minWords = 1; +3122 if (minWords > maxWords) +3123 maxWords = minWords; +3124 if (midPunctuationFrequency > 1.0) { +3125 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3126 } +3127 if (maxChars < 4) +3128 return "!"; +3129 if (maxChars <= 5 * minWords) { +3130 minWords = 1; +3131 maxWords = 1; +3132 } +3133 int frustration = 0; +3134 StringBuilder sb = new StringBuilder(maxChars); +3135 String next = word(rng, true); +3136 while (next.length() >= maxChars - 1 && frustration < 50) { +3137 next = word(rng, true); +3138 frustration++; +3139 } +3140 if (frustration >= 50) return "!"; +3141 sb.append(next); +3142 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { +3143 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3144 sb.append(rng.getRandomElement(midPunctuation)); +3145 } +3146 next = word(rng, false); +3147 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3148 next = word(rng, false); +3149 frustration++; +3150 } +3151 if (frustration >= 50) break; +3152 sb.append(' '); +3153 sb.append(next); +3154 } +3155 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { +3156 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3157 sb.append(rng.getRandomElement(midPunctuation)); +3158 } +3159 next = word(rng, false); +3160 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3161 next = word(rng, false); +3162 frustration++; +3163 } +3164 if (frustration >= 50) break; +3165 sb.append(' '); +3166 sb.append(next); +3167 } +3168 +3169 if (endPunctuation != null && endPunctuation.length > 0) { +3170 +3171 next = rng.getRandomElement(endPunctuation); +3172 if (sb.length() + next.length() >= maxChars) +3173 sb.append('.'); +3174 else +3175 sb.append(next); +3176 } +3177 +3178 if (sb.length() > maxChars) +3179 return "!"; +3180 return sb.toString(); +3181 } +3182 +3183 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { +3184 if (other.length <= 0 && me.length <= 0) +3185 return new String[]{}; +3186 String[] ret = new String[1000]; +3187 int otherCount = (int) (1000 * otherInfluence); +3188 int idx = 0; +3189 if (other.length > 0) { +3190 String[] tmp = new String[other.length]; +3191 rng.shuffle(other, tmp); +3192 for (idx = 0; idx < otherCount; idx++) { +3193 ret[idx] = tmp[idx % tmp.length]; +3194 } +3195 } 3196 if (me.length > 0) { 3197 String[] tmp = new String[me.length]; 3198 rng.shuffle(me, tmp); -3199 for (idx = 0; idx < otherCount; idx++) { -3200 ret[idx] = tmp[idx % tmp.length] -3201 //0 -3202 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3203 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3204 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3205 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3206 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3207 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3208 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3209 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3210 //9 -3211 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3212 //11 -3213 //12 -3214 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3215 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3216 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3217 //16 -3218 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3219 //18 -3220 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3221 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3222 -3223 matcher = repeats.matcher(ret[idx]); -3224 if (matcher.find()) { -3225 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3226 } -3227 } -3228 for (; idx < 1000; idx++) { -3229 ret[idx] = tmp[idx % tmp.length]; +3199 for (; idx < 1000; idx++) { +3200 ret[idx] = tmp[idx % tmp.length]; +3201 } +3202 } else { +3203 for (; idx < 1000; idx++) { +3204 ret[idx] = other[idx % other.length]; +3205 } +3206 } +3207 return ret; +3208 } +3209 +3210 +3211 protected String[] accentVowels(RNG rng, String[] me, double influence) { +3212 String[] ret = new String[1000]; +3213 int otherCount = (int) (1000 * influence); +3214 int idx = 0; +3215 Matcher matcher; +3216 if (me.length > 0) { +3217 String[] tmp = new String[me.length]; +3218 rng.shuffle(me, tmp); +3219 for (idx = 0; idx < otherCount; idx++) { +3220 ret[idx] = tmp[idx % tmp.length] +3221 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3222 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3223 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3224 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3225 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3226 matcher = repeats.matcher(ret[idx]); +3227 if (matcher.find()) { +3228 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3229 } 3230 } -3231 } else -3232 return new String[]{}; -3233 return ret; -3234 } -3235 -3236 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { -3237 String[] ret = new String[1000]; -3238 int idx = 0; -3239 Matcher matcher; -3240 if (me.length > 0) { -3241 String[] tmp = new String[me.length]; -3242 rng.shuffle(me, tmp); -3243 for (idx = 0; idx < 1000; idx++) { -3244 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; -3245 if (subVowel && subCon) { -3246 ret[idx] = tmp[idx % tmp.length] -3247 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3248 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3249 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3250 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3251 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) -3252 -3253 //0 -3254 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3255 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3256 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3257 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3258 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3259 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3260 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3261 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3262 //9 -3263 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3264 //11 -3265 //12 -3266 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3267 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3268 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3269 //16 -3270 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3271 //18 -3272 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3273 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3274 -3275 matcher = repeats.matcher(ret[idx]); -3276 if (matcher.find()) { -3277 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3278 } -3279 } else if (subVowel) { -3280 ret[idx] = tmp[idx % tmp.length] -3281 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3282 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3283 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3284 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3285 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3286 -3287 matcher = repeats.matcher(ret[idx]); -3288 if (matcher.find()) { -3289 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3290 } -3291 } else if (subCon) { -3292 ret[idx] = tmp[idx % tmp.length] -3293 //0 -3294 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3295 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3296 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3297 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3298 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3299 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3300 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3301 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3302 //9 -3303 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3304 //11 -3305 //12 -3306 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3307 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3308 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3309 //16 -3310 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3311 //18 -3312 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3313 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3314 -3315 matcher = repeats.matcher(ret[idx]); -3316 if (matcher.find()) { -3317 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3318 } -3319 } else ret[idx] = tmp[idx % tmp.length]; -3320 -3321 } -3322 } else -3323 return new String[]{}; -3324 return ret; -3325 } -3326 -3327 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { -3328 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); -3329 double myInfluence = 1.0 - otherInfluence; -3330 -3331 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) -3332 ^ NumberTools.doubleToLongBits(otherInfluence)); -3333 -3334 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), -3335 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), -3336 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * -3337 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), -3338 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), -3339 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * -3340 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), -3341 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * -3342 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), -3343 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); -3344 -3345 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); -3346 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { -3347 if (freqs.containsKey(kv.getIntKey())) -3348 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); -3349 else -3350 freqs.put(kv.getIntKey(), kv.getDoubleValue()); -3351 } -3352 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); -3353 mods.addAll(modifiers); -3354 mods.addAll(other.modifiers); -3355 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, -3356 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, -3357 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, -3358 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, -3359 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, -3360 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); -3361 } +3231 for (; idx < 1000; idx++) { +3232 ret[idx] = tmp[idx % tmp.length]; +3233 } +3234 } else +3235 return new String[]{}; +3236 return ret; +3237 } +3238 +3239 protected String[] accentConsonants(RNG rng, String[] me, double influence) { +3240 String[] ret = new String[1000]; +3241 int otherCount = (int) (1000 * influence); +3242 int idx = 0; +3243 Matcher matcher; +3244 if (me.length > 0) { +3245 String[] tmp = new String[me.length]; +3246 rng.shuffle(me, tmp); +3247 for (idx = 0; idx < otherCount; idx++) { +3248 ret[idx] = tmp[idx % tmp.length] +3249 //0 +3250 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3251 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3252 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3253 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3254 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3255 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3256 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3257 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3258 //9 +3259 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3260 //11 +3261 //12 +3262 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3263 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3264 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3265 //16 +3266 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3267 //18 +3268 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3269 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3270 +3271 matcher = repeats.matcher(ret[idx]); +3272 if (matcher.find()) { +3273 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3274 } +3275 } +3276 for (; idx < 1000; idx++) { +3277 ret[idx] = tmp[idx % tmp.length]; +3278 } +3279 } else +3280 return new String[]{}; +3281 return ret; +3282 } +3283 +3284 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { +3285 String[] ret = new String[1000]; +3286 int idx = 0; +3287 Matcher matcher; +3288 if (me.length > 0) { +3289 String[] tmp = new String[me.length]; +3290 rng.shuffle(me, tmp); +3291 for (idx = 0; idx < 1000; idx++) { +3292 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; +3293 if (subVowel && subCon) { +3294 ret[idx] = tmp[idx % tmp.length] +3295 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3296 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3297 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3298 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3299 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) +3300 +3301 //0 +3302 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3303 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3304 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3305 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3306 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3307 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3308 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3309 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3310 //9 +3311 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3312 //11 +3313 //12 +3314 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3315 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3316 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3317 //16 +3318 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3319 //18 +3320 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3321 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3322 +3323 matcher = repeats.matcher(ret[idx]); +3324 if (matcher.find()) { +3325 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3326 } +3327 } else if (subVowel) { +3328 ret[idx] = tmp[idx % tmp.length] +3329 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3330 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3331 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3332 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3333 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3334 +3335 matcher = repeats.matcher(ret[idx]); +3336 if (matcher.find()) { +3337 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3338 } +3339 } else if (subCon) { +3340 ret[idx] = tmp[idx % tmp.length] +3341 //0 +3342 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3343 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3344 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3345 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3346 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3347 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3348 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3349 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3350 //9 +3351 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3352 //11 +3353 //12 +3354 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3355 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3356 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3357 //16 +3358 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3359 //18 +3360 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3361 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); 3362 -3363 private static double readDouble(Object o) { -3364 if (o instanceof Double) return (Double) o; -3365 else if (o instanceof Float) return (Float) o; -3366 else if (o instanceof Long) return ((Long) o).doubleValue(); -3367 else if (o instanceof Integer) return (Integer) o; -3368 else if (o instanceof Short) return (Short) o; -3369 else if (o instanceof Byte) return (Byte) o; -3370 else if (o instanceof Character) return (Character) o; -3371 return 0.0; -3372 } -3373 -3374 /** -3375 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes -3376 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of -3377 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a -3378 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this -3379 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. -3380 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type -3381 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some -3382 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and -3383 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern -3384 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on -3385 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3386 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3387 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3388 * with 0.33 . -3389 * <br> -3390 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the -3391 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for -3392 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 -3393 * the bytes used in one not-quite-simple test). -3394 * -3395 * @param myWeight the weight to assign this FakeLanguageGen in the mix -3396 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} -3397 * @param weight1 the weight to assign other1 in the mix -3398 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements -3399 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights -3400 */ -3401 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { -3402 if (other1 == null || pairs == null) -3403 return copy(); -3404 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); -3405 FakeLanguageGen mixer = removeModifiers(); -3406 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; -3407 double[] weights = new double[languages.length]; -3408 String[] summaries = new String[languages.length]; -3409 boolean summarize = true; -3410 double total = 0.0, current, weight; -3411 languages[0] = mixer; -3412 total += weights[0] = myWeight; -3413 if ((summaries[0] = mixer.summary) == null) summarize = false; -3414 mods.addAll(other1.modifiers); -3415 languages[1] = other1.removeModifiers(); -3416 total += weights[1] = weight1; -3417 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; -3418 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { -3419 if (pairs[i] == null || pairs[i - 1] == null) -3420 continue; -3421 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); -3422 total += weights[p] = readDouble(pairs[i]); -3423 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; -3424 } -3425 if (total == 0) -3426 return copy(); -3427 current = myWeight / total; -3428 for (int i = 1; i < languages.length; i++) { -3429 if ((weight = weights[i]) > 0) -3430 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); -3431 } -3432 if (summarize) { -3433 StringBuilder brief = new StringBuilder(64); -3434 String c; -3435 int idx; -3436 for (int i = 0; i < summaries.length; i++) { -3437 c = summaries[i]; -3438 idx = c.indexOf('@'); -3439 if (idx >= 0) { -3440 brief.append(c.substring(0, idx + 1)).append(weights[i]); -3441 if (i < summaries.length - 1) -3442 brief.append('~'); -3443 } -3444 } -3445 for (int i = 0; i < mods.size(); i++) { -3446 brief.append('℗').append(mods.getAt(i).serializeToString()); -3447 } -3448 return mixer.addModifiers(mods).summarize(brief.toString()); -3449 } else -3450 return mixer.addModifiers(mods); -3451 } -3452 -3453 /** -3454 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. -3455 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the -3456 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double -3457 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then -3458 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them -3459 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one -3460 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on -3461 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3462 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3463 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3464 * with 0.33 . -3465 * <br> -3466 * Not intended for external use, but it could be useful. Used internally in the deserialization code. -3467 * -3468 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements -3469 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights -3470 */ -3471 public static FakeLanguageGen mixAll(Object... pairs) { -3472 int len; -3473 if (pairs == null || (len = pairs.length) <= 0) -3474 return ENGLISH.copy(); -3475 if (len < 4) -3476 return ((FakeLanguageGen) pairs[0]).copy(); -3477 Object[] pairs2 = new Object[len - 4]; -3478 if (len > 4) -3479 System.arraycopy(pairs, 4, pairs2, 0, len - 4); -3480 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); -3481 } -3482 -3483 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { -3484 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); -3485 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); -3486 -3487 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ -3488 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); -3489 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), -3490 mv = accentVowels(rng, midVowels, vowelInfluence), -3491 oc = accentConsonants(rng, openingConsonants, consonantInfluence), -3492 mc = accentConsonants(rng, midConsonants, consonantInfluence), -3493 cc = accentConsonants(rng, closingConsonants, consonantInfluence), -3494 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); -3495 -3496 -3497 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3498 vowelStartFrequency, -3499 vowelEndFrequency, -3500 vowelSplitFrequency, -3501 syllableEndFrequency, sanityChecks, clean, modifiers); -3502 } -3503 -3504 static String[] copyStrings(String[] start) { -3505 String[] next = new String[start.length]; -3506 System.arraycopy(start, 0, next, 0, start.length); -3507 return next; -3508 } -3509 -3510 public FakeLanguageGen removeAccents() { -3511 -3512 String[] ov = copyStrings(openingVowels), -3513 mv = copyStrings(midVowels), -3514 oc = copyStrings(openingConsonants), -3515 mc = copyStrings(midConsonants), -3516 cc = copyStrings(closingConsonants), -3517 cs = copyStrings(closingSyllables); -3518 for (int i = 0; i < ov.length; i++) { -3519 ov[i] = removeAccents(openingVowels[i]).toString(); -3520 } -3521 for (int i = 0; i < mv.length; i++) { -3522 mv[i] = removeAccents(midVowels[i]).toString(); -3523 } -3524 for (int i = 0; i < oc.length; i++) { -3525 oc[i] = removeAccents(openingConsonants[i]).toString(); -3526 } -3527 for (int i = 0; i < mc.length; i++) { -3528 mc[i] = removeAccents(midConsonants[i]).toString(); -3529 } -3530 for (int i = 0; i < cc.length; i++) { -3531 cc[i] = removeAccents(closingConsonants[i]).toString(); -3532 } -3533 for (int i = 0; i < cs.length; i++) { -3534 cs[i] = removeAccents(closingSyllables[i]).toString(); -3535 } -3536 -3537 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3538 vowelStartFrequency, -3539 vowelEndFrequency, -3540 vowelSplitFrequency, -3541 syllableEndFrequency, sanityChecks, clean, modifiers); -3542 } +3363 matcher = repeats.matcher(ret[idx]); +3364 if (matcher.find()) { +3365 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3366 } +3367 } else ret[idx] = tmp[idx % tmp.length]; +3368 +3369 } +3370 } else +3371 return new String[]{}; +3372 return ret; +3373 } +3374 +3375 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { +3376 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); +3377 double myInfluence = 1.0 - otherInfluence; +3378 +3379 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) +3380 ^ NumberTools.doubleToLongBits(otherInfluence)); +3381 +3382 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), +3383 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), +3384 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * +3385 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), +3386 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), +3387 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * +3388 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), +3389 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * +3390 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), +3391 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); +3392 +3393 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); +3394 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { +3395 if (freqs.containsKey(kv.getIntKey())) +3396 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); +3397 else +3398 freqs.put(kv.getIntKey(), kv.getDoubleValue()); +3399 } +3400 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); +3401 mods.addAll(modifiers); +3402 mods.addAll(other.modifiers); +3403 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, +3404 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, +3405 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, +3406 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, +3407 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, +3408 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); +3409 } +3410 +3411 private static double readDouble(Object o) { +3412 if (o instanceof Double) return (Double) o; +3413 else if (o instanceof Float) return (Float) o; +3414 else if (o instanceof Long) return ((Long) o).doubleValue(); +3415 else if (o instanceof Integer) return (Integer) o; +3416 else if (o instanceof Short) return (Short) o; +3417 else if (o instanceof Byte) return (Byte) o; +3418 else if (o instanceof Character) return (Character) o; +3419 return 0.0; +3420 } +3421 +3422 /** +3423 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes +3424 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of +3425 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a +3426 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this +3427 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. +3428 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type +3429 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some +3430 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and +3431 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern +3432 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on +3433 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3434 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3435 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3436 * with 0.33 . +3437 * <br> +3438 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the +3439 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for +3440 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 +3441 * the bytes used in one not-quite-simple test). +3442 * +3443 * @param myWeight the weight to assign this FakeLanguageGen in the mix +3444 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} +3445 * @param weight1 the weight to assign other1 in the mix +3446 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements +3447 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights +3448 */ +3449 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { +3450 if (other1 == null || pairs == null) +3451 return copy(); +3452 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); +3453 FakeLanguageGen mixer = removeModifiers(); +3454 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; +3455 double[] weights = new double[languages.length]; +3456 String[] summaries = new String[languages.length]; +3457 boolean summarize = true; +3458 double total = 0.0, current, weight; +3459 languages[0] = mixer; +3460 total += weights[0] = myWeight; +3461 if ((summaries[0] = mixer.summary) == null) summarize = false; +3462 mods.addAll(other1.modifiers); +3463 languages[1] = other1.removeModifiers(); +3464 total += weights[1] = weight1; +3465 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; +3466 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { +3467 if (pairs[i] == null || pairs[i - 1] == null) +3468 continue; +3469 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); +3470 total += weights[p] = readDouble(pairs[i]); +3471 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; +3472 } +3473 if (total == 0) +3474 return copy(); +3475 current = myWeight / total; +3476 for (int i = 1; i < languages.length; i++) { +3477 if ((weight = weights[i]) > 0) +3478 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); +3479 } +3480 if (summarize) { +3481 StringBuilder brief = new StringBuilder(64); +3482 String c; +3483 int idx; +3484 for (int i = 0; i < summaries.length; i++) { +3485 c = summaries[i]; +3486 idx = c.indexOf('@'); +3487 if (idx >= 0) { +3488 brief.append(c.substring(0, idx + 1)).append(weights[i]); +3489 if (i < summaries.length - 1) +3490 brief.append('~'); +3491 } +3492 } +3493 for (int i = 0; i < mods.size(); i++) { +3494 brief.append('℗').append(mods.getAt(i).serializeToString()); +3495 } +3496 return mixer.addModifiers(mods).summarize(brief.toString()); +3497 } else +3498 return mixer.addModifiers(mods); +3499 } +3500 +3501 /** +3502 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. +3503 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the +3504 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double +3505 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then +3506 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them +3507 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one +3508 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on +3509 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3510 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3511 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3512 * with 0.33 . +3513 * <br> +3514 * Not intended for external use, but it could be useful. Used internally in the deserialization code. +3515 * +3516 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements +3517 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights +3518 */ +3519 public static FakeLanguageGen mixAll(Object... pairs) { +3520 int len; +3521 if (pairs == null || (len = pairs.length) <= 0) +3522 return ENGLISH.copy(); +3523 if (len < 4) +3524 return ((FakeLanguageGen) pairs[0]).copy(); +3525 Object[] pairs2 = new Object[len - 4]; +3526 if (len > 4) +3527 System.arraycopy(pairs, 4, pairs2, 0, len - 4); +3528 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); +3529 } +3530 +3531 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { +3532 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); +3533 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); +3534 +3535 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ +3536 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); +3537 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), +3538 mv = accentVowels(rng, midVowels, vowelInfluence), +3539 oc = accentConsonants(rng, openingConsonants, consonantInfluence), +3540 mc = accentConsonants(rng, midConsonants, consonantInfluence), +3541 cc = accentConsonants(rng, closingConsonants, consonantInfluence), +3542 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); 3543 -3544 /** -3545 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. -3546 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3547 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3548 * -3549 * @param mods an array or vararg of Modifier objects -3550 * @return a copy of this with the Modifiers added -3551 */ -3552 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { -3553 FakeLanguageGen next = copy(); -3554 next.modifiers.addAll(mods); +3544 +3545 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3546 vowelStartFrequency, +3547 vowelEndFrequency, +3548 vowelSplitFrequency, +3549 syllableEndFrequency, sanityChecks, clean, modifiers); +3550 } +3551 +3552 static String[] copyStrings(String[] start) { +3553 String[] next = new String[start.length]; +3554 System.arraycopy(start, 0, next, 0, start.length); 3555 return next; 3556 } 3557 -3558 /** -3559 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. -3560 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3561 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3562 * -3563 * @param mods an array or vararg of Modifier objects -3564 * @return a copy of this with the Modifiers added -3565 */ -3566 public FakeLanguageGen addModifiers(Modifier... mods) { -3567 FakeLanguageGen next = copy(); -3568 Collections.addAll(next.modifiers, mods); -3569 return next; -3570 } -3571 -3572 /** -3573 * Creates a copy of this FakeLanguageGen with no modifiers. -3574 * -3575 * @return a copy of this FakeLanguageGen with modifiers removed. -3576 */ -3577 public FakeLanguageGen removeModifiers() { -3578 FakeLanguageGen next = copy(); -3579 next.modifiers.clear(); -3580 return next; -3581 } -3582 -3583 public static Modifier modifier(String pattern, String replacement) { -3584 return new Modifier(pattern, replacement); -3585 } -3586 -3587 public static Modifier modifier(String pattern, String replacement, double chance) { -3588 return new Modifier(pattern, replacement, chance); -3589 } -3590 -3591 @Override -3592 public boolean equals(Object o) { -3593 if (this == o) return true; -3594 if (o == null || getClass() != o.getClass()) return false; -3595 -3596 FakeLanguageGen that = (FakeLanguageGen) o; -3597 -3598 if (clean != that.clean) return false; -3599 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; -3600 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; -3601 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; -3602 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; -3603 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; -3604 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3605 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; -3606 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3607 if (!Arrays.equals(midVowels, that.midVowels)) return false; -3608 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3609 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; -3610 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3611 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; -3612 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3613 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; -3614 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3615 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; -3616 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3617 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; -3618 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; -3619 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3620 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; -3621 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; -3622 } -3623 -3624 @Override -3625 public int hashCode() { -3626 int result; -3627 long temp; -3628 result = CrossHash.Lightning.hash(openingVowels); -3629 result = 31 * result + CrossHash.Lightning.hash(midVowels); -3630 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); -3631 result = 31 * result + CrossHash.Lightning.hash(midConsonants); -3632 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); -3633 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); -3634 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); -3635 result = 31 * result + (clean ? 1 : 0); -3636 result = 31 * result + syllableFrequencies.hashCode(); -3637 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); -3638 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3639 temp = NumberTools.doubleToLongBits(vowelStartFrequency); -3640 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3641 temp = NumberTools.doubleToLongBits(vowelEndFrequency); -3642 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3643 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); -3644 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3645 temp = NumberTools.doubleToLongBits(syllableEndFrequency); -3646 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3647 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); -3648 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); -3649 return result; -3650 } -3651 -3652 @Override -3653 public String toString() { -3654 return "FakeLanguageGen{" + -3655 "openingVowels=" + Arrays.toString(openingVowels) + -3656 ", midVowels=" + Arrays.toString(midVowels) + -3657 ", openingConsonants=" + Arrays.toString(openingConsonants) + -3658 ", midConsonants=" + Arrays.toString(midConsonants) + -3659 ", closingConsonants=" + Arrays.toString(closingConsonants) + -3660 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + -3661 ", closingSyllables=" + Arrays.toString(closingSyllables) + -3662 ", clean=" + clean + -3663 ", syllableFrequencies=" + syllableFrequencies + -3664 ", totalSyllableFrequency=" + totalSyllableFrequency + -3665 ", vowelStartFrequency=" + vowelStartFrequency + -3666 ", vowelEndFrequency=" + vowelEndFrequency + -3667 ", vowelSplitFrequency=" + vowelSplitFrequency + -3668 ", syllableEndFrequency=" + syllableEndFrequency + -3669 ", sanityChecks=" + Arrays.toString(sanityChecks) + -3670 ", modifiers=" + modifiers + -3671 '}'; -3672 } -3673 -3674 public FakeLanguageGen copy() { -3675 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, -3676 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, -3677 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) -3678 .summarize(summary); -3679 } -3680 -3681 -3682 public String serializeToString() { -3683 return (summary == null) ? "" : summary; -3684 } -3685 -3686 public static FakeLanguageGen deserializeFromString(String data) { -3687 if (data == null || data.equals("")) -3688 return ENGLISH.copy(); -3689 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), -3690 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, -3691 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; -3692 if (tildeIndex < 0) -3693 tildeIndex = data.length(); -3694 -3695 if (snailIndex < 0) -3696 return ENGLISH.copy(); -3697 ArrayList<Object> pairs = new ArrayList<>(4); -3698 while (snailIndex >= 0) { -3699 if (poundIndex >= 0 && poundIndex < snailIndex) // random case -3700 { -3701 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); -3702 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3703 poundIndex = -1; -3704 } else { -3705 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); -3706 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3707 } -3708 snailIndex = data.indexOf('@', snailIndex + 1); -3709 if (snailIndex > breakIndex) -3710 break; -3711 prevTildeIndex = tildeIndex; -3712 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); -3713 if (tildeIndex < 0) -3714 tildeIndex = data.length(); -3715 } -3716 ArrayList<Modifier> mods = new ArrayList<>(8); -3717 if (breakIndex == tempBreak) { -3718 tildeIndex = breakIndex - 1; -3719 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { -3720 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); -3721 if (tildeIndex < 0) tildeIndex = data.length(); -3722 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); -3723 } -3724 } -3725 FakeLanguageGen flg = mixAll(pairs.toArray()); -3726 flg.modifiers.addAll(mods); -3727 return flg; -3728 } +3558 public FakeLanguageGen removeAccents() { +3559 +3560 String[] ov = copyStrings(openingVowels), +3561 mv = copyStrings(midVowels), +3562 oc = copyStrings(openingConsonants), +3563 mc = copyStrings(midConsonants), +3564 cc = copyStrings(closingConsonants), +3565 cs = copyStrings(closingSyllables); +3566 for (int i = 0; i < ov.length; i++) { +3567 ov[i] = removeAccents(openingVowels[i]).toString(); +3568 } +3569 for (int i = 0; i < mv.length; i++) { +3570 mv[i] = removeAccents(midVowels[i]).toString(); +3571 } +3572 for (int i = 0; i < oc.length; i++) { +3573 oc[i] = removeAccents(openingConsonants[i]).toString(); +3574 } +3575 for (int i = 0; i < mc.length; i++) { +3576 mc[i] = removeAccents(midConsonants[i]).toString(); +3577 } +3578 for (int i = 0; i < cc.length; i++) { +3579 cc[i] = removeAccents(closingConsonants[i]).toString(); +3580 } +3581 for (int i = 0; i < cs.length; i++) { +3582 cs[i] = removeAccents(closingSyllables[i]).toString(); +3583 } +3584 +3585 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3586 vowelStartFrequency, +3587 vowelEndFrequency, +3588 vowelSplitFrequency, +3589 syllableEndFrequency, sanityChecks, clean, modifiers); +3590 } +3591 +3592 /** +3593 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. +3594 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3595 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3596 * +3597 * @param mods an array or vararg of Modifier objects +3598 * @return a copy of this with the Modifiers added +3599 */ +3600 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { +3601 FakeLanguageGen next = copy(); +3602 next.modifiers.addAll(mods); +3603 return next; +3604 } +3605 +3606 /** +3607 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. +3608 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3609 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3610 * +3611 * @param mods an array or vararg of Modifier objects +3612 * @return a copy of this with the Modifiers added +3613 */ +3614 public FakeLanguageGen addModifiers(Modifier... mods) { +3615 FakeLanguageGen next = copy(); +3616 Collections.addAll(next.modifiers, mods); +3617 return next; +3618 } +3619 +3620 /** +3621 * Creates a copy of this FakeLanguageGen with no modifiers. +3622 * +3623 * @return a copy of this FakeLanguageGen with modifiers removed. +3624 */ +3625 public FakeLanguageGen removeModifiers() { +3626 FakeLanguageGen next = copy(); +3627 next.modifiers.clear(); +3628 return next; +3629 } +3630 +3631 public static Modifier modifier(String pattern, String replacement) { +3632 return new Modifier(pattern, replacement); +3633 } +3634 +3635 public static Modifier modifier(String pattern, String replacement, double chance) { +3636 return new Modifier(pattern, replacement, chance); +3637 } +3638 +3639 @Override +3640 public boolean equals(Object o) { +3641 if (this == o) return true; +3642 if (o == null || getClass() != o.getClass()) return false; +3643 +3644 FakeLanguageGen that = (FakeLanguageGen) o; +3645 +3646 if (clean != that.clean) return false; +3647 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; +3648 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; +3649 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; +3650 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; +3651 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; +3652 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3653 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; +3654 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3655 if (!Arrays.equals(midVowels, that.midVowels)) return false; +3656 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3657 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; +3658 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3659 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; +3660 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3661 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; +3662 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3663 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; +3664 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3665 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; +3666 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; +3667 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3668 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; +3669 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; +3670 } +3671 +3672 @Override +3673 public int hashCode() { +3674 int result; +3675 long temp; +3676 result = CrossHash.Lightning.hash(openingVowels); +3677 result = 31 * result + CrossHash.Lightning.hash(midVowels); +3678 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); +3679 result = 31 * result + CrossHash.Lightning.hash(midConsonants); +3680 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); +3681 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); +3682 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); +3683 result = 31 * result + (clean ? 1 : 0); +3684 result = 31 * result + syllableFrequencies.hashCode(); +3685 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); +3686 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3687 temp = NumberTools.doubleToLongBits(vowelStartFrequency); +3688 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3689 temp = NumberTools.doubleToLongBits(vowelEndFrequency); +3690 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3691 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); +3692 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3693 temp = NumberTools.doubleToLongBits(syllableEndFrequency); +3694 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3695 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); +3696 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); +3697 return result; +3698 } +3699 +3700 @Override +3701 public String toString() { +3702 return "FakeLanguageGen{" + +3703 "openingVowels=" + Arrays.toString(openingVowels) + +3704 ", midVowels=" + Arrays.toString(midVowels) + +3705 ", openingConsonants=" + Arrays.toString(openingConsonants) + +3706 ", midConsonants=" + Arrays.toString(midConsonants) + +3707 ", closingConsonants=" + Arrays.toString(closingConsonants) + +3708 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + +3709 ", closingSyllables=" + Arrays.toString(closingSyllables) + +3710 ", clean=" + clean + +3711 ", syllableFrequencies=" + syllableFrequencies + +3712 ", totalSyllableFrequency=" + totalSyllableFrequency + +3713 ", vowelStartFrequency=" + vowelStartFrequency + +3714 ", vowelEndFrequency=" + vowelEndFrequency + +3715 ", vowelSplitFrequency=" + vowelSplitFrequency + +3716 ", syllableEndFrequency=" + syllableEndFrequency + +3717 ", sanityChecks=" + Arrays.toString(sanityChecks) + +3718 ", modifiers=" + modifiers + +3719 '}'; +3720 } +3721 +3722 public FakeLanguageGen copy() { +3723 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, +3724 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, +3725 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) +3726 .summarize(summary); +3727 } +3728 3729 -3730 public static class Modifier implements Serializable { -3731 private static final long serialVersionUID = 1734863678490422371L; -3732 public final Alteration[] alterations; +3730 public String serializeToString() { +3731 return (summary == null) ? "" : summary; +3732 } 3733 -3734 public Modifier() { -3735 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -3736 } -3737 -3738 public Modifier(String pattern, String replacement) { -3739 alterations = new Alteration[]{new Alteration(pattern, replacement)}; -3740 } -3741 -3742 public Modifier(String pattern, String replacement, double chance) { -3743 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; -3744 } -3745 -3746 public Modifier(Alteration... alts) { -3747 alterations = (alts == null) ? new Alteration[0] : alts; -3748 } -3749 -3750 public StringBuilder modify(RNG rng, StringBuilder sb) { -3751 Matcher m; -3752 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); -3753 String tmp; -3754 boolean found; -3755 Alteration alt; -3756 for (int a = 0; a < alterations.length; a++) { -3757 alt = alterations[a]; -3758 tmp = working.toString(); -3759 tb = Replacer.wrap(new StringBuilder(tmp.length())); -3760 m = alt.replacer.getPattern().matcher(tmp); -3761 -3762 found = false; -3763 while (true) { -3764 if (rng.nextDouble() < alt.chance) { -3765 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) -3766 break; -3767 found = true; -3768 } else { -3769 if (!m.find()) -3770 break; -3771 found = true; -3772 m.getGroup(MatchResult.PREFIX, tb); -3773 m.getGroup(MatchResult.MATCH, tb); -3774 m.setTarget(m, MatchResult.SUFFIX); -3775 } -3776 } -3777 if (found) { -3778 m.getGroup(MatchResult.TARGET, tb); -3779 working = tb; -3780 } -3781 } -3782 return working.toStringBuilder(); -3783 } -3784 -3785 /** -3786 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. -3787 */ -3788 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3734 public static FakeLanguageGen deserializeFromString(String data) { +3735 if (data == null || data.equals("")) +3736 return ENGLISH.copy(); +3737 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), +3738 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, +3739 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; +3740 if (tildeIndex < 0) +3741 tildeIndex = data.length(); +3742 +3743 if (snailIndex < 0) +3744 return ENGLISH.copy(); +3745 ArrayList<Object> pairs = new ArrayList<>(4); +3746 while (snailIndex >= 0) { +3747 if (poundIndex >= 0 && poundIndex < snailIndex) // random case +3748 { +3749 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); +3750 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3751 poundIndex = -1; +3752 } else { +3753 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); +3754 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3755 } +3756 snailIndex = data.indexOf('@', snailIndex + 1); +3757 if (snailIndex > breakIndex) +3758 break; +3759 prevTildeIndex = tildeIndex; +3760 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); +3761 if (tildeIndex < 0) +3762 tildeIndex = data.length(); +3763 } +3764 ArrayList<Modifier> mods = new ArrayList<>(8); +3765 if (breakIndex == tempBreak) { +3766 tildeIndex = breakIndex - 1; +3767 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { +3768 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); +3769 if (tildeIndex < 0) tildeIndex = data.length(); +3770 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); +3771 } +3772 } +3773 FakeLanguageGen flg = mixAll(pairs.toArray()); +3774 flg.modifiers.addAll(mods); +3775 return flg; +3776 } +3777 +3778 public static class Modifier implements Serializable { +3779 private static final long serialVersionUID = 1734863678490422371L; +3780 public final Alteration[] alterations; +3781 +3782 public Modifier() { +3783 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3784 } +3785 +3786 public Modifier(String pattern, String replacement) { +3787 alterations = new Alteration[]{new Alteration(pattern, replacement)}; +3788 } 3789 -3790 /** -3791 * For a character who always lengthens 's' and 'z' sounds not starting a word. -3792 */ -3793 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); -3794 -3795 /** -3796 * For a character who has a 20% chance to repeat a starting consonant or vowel. -3797 */ -3798 public static final Modifier STUTTER = new Modifier( -3799 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), -3800 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); -3801 -3802 /** -3803 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them -3804 * like å or ö, but not merged letters like æ and œ). -3805 */ -3806 public static final Modifier DOUBLE_VOWELS = new Modifier( -3807 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" -3808 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" -3809 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); -3810 -3811 -3812 /** -3813 * For a language that has a 50% chance to repeat a single consonant. -3814 */ -3815 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + -3816 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + -3817 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); -3818 -3819 /** -3820 * For a language that never repeats the same letter twice in a row. -3821 */ -3822 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); -3823 -3824 /** -3825 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. -3826 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j -3827 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ -3828 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. -3829 */ -3830 public static final Modifier SIMPLIFY_NORSE = replacementTable( -3831 "á", "a", -3832 "é", "e", -3833 "í", "i", -3834 "ý", "y", -3835 "ó", "o", -3836 "ú", "u", -3837 "æ", "ae", -3838 "ö", "ou", -3839 "([^aeiou])jy", "$1yai", -3840 "([^aeiou])j(?:[aeiouy]+)", "$1yo", -3841 "s([ðþ])", "st", -3842 "\\bf[ðþ]", "fr", -3843 "[ðþ]", "th"); -3844 -3845 /** -3846 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". -3847 */ -3848 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); -3849 /** -3850 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate -3851 * for fixing a word that isn't pronounceable. -3852 */ -3853 public static final Modifier GENERAL_CLEANUP = replacementTable( -3854 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", -3855 "q([ùúûüũūŭůűųu])$", "q$1e", -3856 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", -3857 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", -3858 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", -3859 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", -3860 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", -3861 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", -3862 "qq", "q"); -3863 -3864 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy -3865 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3790 public Modifier(String pattern, String replacement, double chance) { +3791 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; +3792 } +3793 +3794 public Modifier(Alteration... alts) { +3795 alterations = (alts == null) ? new Alteration[0] : alts; +3796 } +3797 +3798 public StringBuilder modify(RNG rng, StringBuilder sb) { +3799 Matcher m; +3800 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); +3801 String tmp; +3802 boolean found; +3803 Alteration alt; +3804 for (int a = 0; a < alterations.length; a++) { +3805 alt = alterations[a]; +3806 tmp = working.toString(); +3807 tb = Replacer.wrap(new StringBuilder(tmp.length())); +3808 m = alt.replacer.getPattern().matcher(tmp); +3809 +3810 found = false; +3811 while (true) { +3812 if (rng.nextDouble() < alt.chance) { +3813 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) +3814 break; +3815 found = true; +3816 } else { +3817 if (!m.find()) +3818 break; +3819 found = true; +3820 m.getGroup(MatchResult.PREFIX, tb); +3821 m.getGroup(MatchResult.MATCH, tb); +3822 m.setTarget(m, MatchResult.SUFFIX); +3823 } +3824 } +3825 if (found) { +3826 m.getGroup(MatchResult.TARGET, tb); +3827 working = tb; +3828 } +3829 } +3830 return working.toStringBuilder(); +3831 } +3832 +3833 /** +3834 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. +3835 */ +3836 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3837 +3838 /** +3839 * For a character who always lengthens 's' and 'z' sounds not starting a word. +3840 */ +3841 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); +3842 +3843 /** +3844 * For a character who has a 20% chance to repeat a starting consonant or vowel. +3845 */ +3846 public static final Modifier STUTTER = new Modifier( +3847 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), +3848 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); +3849 +3850 /** +3851 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them +3852 * like å or ö, but not merged letters like æ and œ). +3853 */ +3854 public static final Modifier DOUBLE_VOWELS = new Modifier( +3855 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" +3856 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" +3857 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); +3858 +3859 +3860 /** +3861 * For a language that has a 50% chance to repeat a single consonant. +3862 */ +3863 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + +3864 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + +3865 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); 3866 3867 /** -3868 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and -3869 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the -3870 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3871 * -3872 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text -3873 * @param change a String containing characters that will replace occurrences of characters in initial -3874 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3875 */ -3876 public static Modifier charReplacementTable(String initial, String change) { -3877 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; -3878 for (int i = 0; i < alts.length; i++) { -3879 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, -3880 // which is slightly slower and has some odd escaping cases. -3881 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); -3882 } -3883 return new Modifier(alts); -3884 } -3885 -3886 /** -3887 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the -3888 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3889 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, -3890 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3891 * this example to replace the repeated section with only the first vowel. -3892 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced -3893 * first, possibly making the later key not match), or if an earlier replacement causes a later one to -3894 * become valid. -3895 * -3896 * @param map containing String keys to replace and String values to use instead; replacements happen in order -3897 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3898 */ -3899 public static Modifier replacementTable(OrderedMap<String, String> map) { -3900 if (map == null) -3901 return new Modifier(); -3902 Alteration[] alts = new Alteration[map.size()]; -3903 for (int i = 0; i < alts.length; i++) { -3904 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); -3905 } -3906 return new Modifier(alts); -3907 } -3908 -3909 /** -3910 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because -3911 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3912 * This overload of replacementTable allows full regex syntax for search and replacement Strings, -3913 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3914 * this example to replace the repeated section with only the first vowel. -3915 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced -3916 * first, possibly making the later search not match), or if an earlier replacement causes a later one to -3917 * become valid. -3918 * -3919 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order -3920 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3921 */ -3922 public static Modifier replacementTable(String... pairs) { -3923 int len; -3924 if (pairs == null || (len = pairs.length) <= 1) -3925 return new Modifier(); -3926 Alteration[] alts = new Alteration[len >> 1]; -3927 for (int i = 0; i < alts.length; i++) { -3928 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); -3929 } -3930 return new Modifier(alts); -3931 } -3932 -3933 /** -3934 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3935 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel -3936 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the -3937 * newly-inserted vowel to be likely to be present in every word of some sentences. -3938 * @param insertion the String to use as an additional vowel -3939 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less -3940 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3941 */ -3942 public static Modifier insertVowel(String insertion, double chance) -3943 { -3944 return new Modifier(anyVowelCluster, insertion, chance); -3945 } -3946 -3947 /** -3948 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3949 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had -3950 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you -3951 * want the newly-inserted consonant to be likely to be present in every word of some sentences. -3952 * @param insertion the String to use as an additional consonant -3953 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less -3954 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3955 */ -3956 public static Modifier insertConsonant(String insertion, double chance) -3957 { -3958 return new Modifier(anyConsonantCluster, insertion, chance); -3959 } -3960 -3961 /** -3962 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3963 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of -3964 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3965 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, -3966 * so this might not do anything. -3967 * @param insertion the String to use as an additional opening vowel -3968 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3969 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3970 */ -3971 public static Modifier insertOpeningVowel(String insertion, double chance) -3972 { -3973 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); -3974 } -3975 -3976 /** -3977 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3978 * that the language already uses; insertion will replace an existing consonant at the start of a word with a -3979 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -3980 * consonant to be likely to start every word of some sentences. Not all languages can start words with -3981 * consonants, or do that very rarely, so this might not do anything. -3982 * @param insertion the String to use as an additional opening consonant -3983 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3984 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3985 */ -3986 public static Modifier insertOpeningConsonant(String insertion, double chance) -3987 { -3988 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); -3989 } -3990 -3991 /** -3992 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3993 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of -3994 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3995 * to end every word of some sentences. Not all languages can end words with vowels, or do that very -3996 * rarely, so this might not do anything. -3997 * @param insertion the String to use as an additional closing vowel -3998 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less -3999 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4000 */ -4001 public static Modifier insertClosingVowel(String insertion, double chance) -4002 { -4003 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); -4004 } -4005 -4006 /** -4007 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -4008 * that the language already uses; insertion will replace an existing consonant at the end of a word with a -4009 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -4010 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, -4011 * or do that very rarely, so this might not do anything. -4012 * @param insertion the String to use as an additional closing consonant -4013 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less -4014 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4015 */ -4016 public static Modifier insertClosingConsonant(String insertion, double chance) -4017 { -4018 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); -4019 } -4020 -4021 /** -4022 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek -4023 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of -4024 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this -4025 * Modifier is a no-op. Its use is never needed any more. -4026 * @deprecated This Modifier doesn't do anything, and isn't needed. -4027 */ -4028 @Deprecated -4029 public static final Modifier SIMPLIFY_ARABIC = new Modifier( -4030 /* -4031 new Alteration("ţ", "th"), -4032 new Alteration("ĥ", "kh"), -4033 new Alteration("ħ", "khr"), -4034 new Alteration("đ", "dh"), -4035 new Alteration("ď", "dt"), -4036 new Alteration("š", "sh"), -4037 new Alteration("ş", "shw"), -4038 new Alteration("ť", "ch"), -4039 new Alteration("ż", "zh"), -4040 new Alteration("ξ", "khm"), -4041 new Alteration("δ", "gh"), -4042 new Alteration("ā", "aa"), -4043 new Alteration("ū", "uu"), -4044 new Alteration("ī", "ii")*/); -4045 -4046 @Override -4047 public boolean equals(Object o) { -4048 if (this == o) return true; -4049 if (o == null || getClass() != o.getClass()) return false; -4050 -4051 Modifier modifier = (Modifier) o; -4052 -4053 // Probably incorrect - comparing Object[] arrays with Arrays.equals -4054 return Arrays.equals(alterations, modifier.alterations); -4055 } -4056 -4057 @Override -4058 public int hashCode() { -4059 return CrossHash.Lightning.hash(alterations); -4060 } -4061 -4062 @Override -4063 public String toString() { -4064 return "Modifier{" + -4065 "alterations=" + Arrays.toString(alterations) + -4066 '}'; +3868 * For a language that never repeats the same letter twice in a row. +3869 */ +3870 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); +3871 +3872 /** +3873 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. +3874 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j +3875 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ +3876 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. +3877 */ +3878 public static final Modifier SIMPLIFY_NORSE = replacementTable( +3879 "á", "a", +3880 "é", "e", +3881 "í", "i", +3882 "ý", "y", +3883 "ó", "o", +3884 "ú", "u", +3885 "æ", "ae", +3886 "ö", "ou", +3887 "([^aeiou])jy", "$1yai", +3888 "([^aeiou])j(?:[aeiouy]+)", "$1yo", +3889 "s([ðþ])", "st", +3890 "\\bf[ðþ]", "fr", +3891 "[ðþ]", "th"); +3892 +3893 /** +3894 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". +3895 */ +3896 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); +3897 /** +3898 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate +3899 * for fixing a word that isn't pronounceable. +3900 */ +3901 public static final Modifier GENERAL_CLEANUP = replacementTable( +3902 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", +3903 "q([ùúûüũūŭůűųu])$", "q$1e", +3904 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", +3905 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", +3906 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", +3907 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", +3908 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", +3909 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", +3910 "qq", "q"); +3911 +3912 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy +3913 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3914 +3915 /** +3916 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and +3917 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the +3918 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3919 * +3920 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text +3921 * @param change a String containing characters that will replace occurrences of characters in initial +3922 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3923 */ +3924 public static Modifier charReplacementTable(String initial, String change) { +3925 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; +3926 for (int i = 0; i < alts.length; i++) { +3927 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, +3928 // which is slightly slower and has some odd escaping cases. +3929 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); +3930 } +3931 return new Modifier(alts); +3932 } +3933 +3934 /** +3935 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the +3936 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3937 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, +3938 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3939 * this example to replace the repeated section with only the first vowel. +3940 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced +3941 * first, possibly making the later key not match), or if an earlier replacement causes a later one to +3942 * become valid. +3943 * +3944 * @param map containing String keys to replace and String values to use instead; replacements happen in order +3945 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3946 */ +3947 public static Modifier replacementTable(OrderedMap<String, String> map) { +3948 if (map == null) +3949 return new Modifier(); +3950 Alteration[] alts = new Alteration[map.size()]; +3951 for (int i = 0; i < alts.length; i++) { +3952 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); +3953 } +3954 return new Modifier(alts); +3955 } +3956 +3957 /** +3958 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because +3959 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3960 * This overload of replacementTable allows full regex syntax for search and replacement Strings, +3961 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3962 * this example to replace the repeated section with only the first vowel. +3963 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced +3964 * first, possibly making the later search not match), or if an earlier replacement causes a later one to +3965 * become valid. +3966 * +3967 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order +3968 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3969 */ +3970 public static Modifier replacementTable(String... pairs) { +3971 int len; +3972 if (pairs == null || (len = pairs.length) <= 1) +3973 return new Modifier(); +3974 Alteration[] alts = new Alteration[len >> 1]; +3975 for (int i = 0; i < alts.length; i++) { +3976 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); +3977 } +3978 return new Modifier(alts); +3979 } +3980 +3981 /** +3982 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +3983 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel +3984 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the +3985 * newly-inserted vowel to be likely to be present in every word of some sentences. +3986 * @param insertion the String to use as an additional vowel +3987 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less +3988 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3989 */ +3990 public static Modifier insertVowel(String insertion, double chance) +3991 { +3992 return new Modifier(anyVowelCluster, insertion, chance); +3993 } +3994 +3995 /** +3996 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +3997 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had +3998 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you +3999 * want the newly-inserted consonant to be likely to be present in every word of some sentences. +4000 * @param insertion the String to use as an additional consonant +4001 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less +4002 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4003 */ +4004 public static Modifier insertConsonant(String insertion, double chance) +4005 { +4006 return new Modifier(anyConsonantCluster, insertion, chance); +4007 } +4008 +4009 /** +4010 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4011 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of +4012 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4013 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, +4014 * so this might not do anything. +4015 * @param insertion the String to use as an additional opening vowel +4016 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4017 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4018 */ +4019 public static Modifier insertOpeningVowel(String insertion, double chance) +4020 { +4021 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); +4022 } +4023 +4024 /** +4025 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4026 * that the language already uses; insertion will replace an existing consonant at the start of a word with a +4027 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4028 * consonant to be likely to start every word of some sentences. Not all languages can start words with +4029 * consonants, or do that very rarely, so this might not do anything. +4030 * @param insertion the String to use as an additional opening consonant +4031 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4032 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4033 */ +4034 public static Modifier insertOpeningConsonant(String insertion, double chance) +4035 { +4036 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); +4037 } +4038 +4039 /** +4040 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4041 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of +4042 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4043 * to end every word of some sentences. Not all languages can end words with vowels, or do that very +4044 * rarely, so this might not do anything. +4045 * @param insertion the String to use as an additional closing vowel +4046 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4047 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4048 */ +4049 public static Modifier insertClosingVowel(String insertion, double chance) +4050 { +4051 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); +4052 } +4053 +4054 /** +4055 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4056 * that the language already uses; insertion will replace an existing consonant at the end of a word with a +4057 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4058 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, +4059 * or do that very rarely, so this might not do anything. +4060 * @param insertion the String to use as an additional closing consonant +4061 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4062 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4063 */ +4064 public static Modifier insertClosingConsonant(String insertion, double chance) +4065 { +4066 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); 4067 } 4068 -4069 public String serializeToString() { -4070 if (alterations == null || alterations.length == 0) return "\6"; -4071 StringBuilder sb = new StringBuilder(32).append('\6'); -4072 for (int i = 0; i < alterations.length; i++) -4073 sb.append(alterations[i].serializeToString()).append('\6'); -4074 return sb.toString(); -4075 } -4076 -4077 public static Modifier deserializeFromString(String data) { -4078 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; -4079 while (currIdx >= 0) { -4080 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) -4081 break; -4082 matches++; -4083 } -4084 Alteration[] alts = new Alteration[matches]; -4085 for (int i = 0; i < matches; i++) { -4086 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); -4087 } -4088 return new Modifier(alts); -4089 } -4090 } -4091 -4092 public static class Alteration implements Serializable { -4093 private static final long serialVersionUID = -2138854697837563188L; -4094 public Replacer replacer; -4095 public String replacement; -4096 public double chance; -4097 -4098 public Alteration() { -4099 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -4100 } -4101 -4102 public Alteration(String pattern, String replacement) { -4103 this.replacement = replacement; -4104 replacer = Pattern.compile(pattern).replacer(replacement); -4105 chance = 1.0; -4106 } -4107 -4108 public Alteration(String pattern, String replacement, double chance) { -4109 this.replacement = replacement; -4110 replacer = Pattern.compile(pattern).replacer(replacement); -4111 this.chance = chance; -4112 } -4113 -4114 public Alteration(Pattern pattern, String replacement, double chance) { -4115 this.replacement = replacement; -4116 replacer = pattern.replacer(replacement); -4117 this.chance = chance; -4118 } -4119 -4120 @Override -4121 public boolean equals(Object o) { -4122 if (this == o) return true; -4123 if (o == null || getClass() != o.getClass()) return false; +4069 /** +4070 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek +4071 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of +4072 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this +4073 * Modifier is a no-op. Its use is never needed any more. +4074 * @deprecated This Modifier doesn't do anything, and isn't needed. +4075 */ +4076 @Deprecated +4077 public static final Modifier SIMPLIFY_ARABIC = new Modifier( +4078 /* +4079 new Alteration("ţ", "th"), +4080 new Alteration("ĥ", "kh"), +4081 new Alteration("ħ", "khr"), +4082 new Alteration("đ", "dh"), +4083 new Alteration("ď", "dt"), +4084 new Alteration("š", "sh"), +4085 new Alteration("ş", "shw"), +4086 new Alteration("ť", "ch"), +4087 new Alteration("ż", "zh"), +4088 new Alteration("ξ", "khm"), +4089 new Alteration("δ", "gh"), +4090 new Alteration("ā", "aa"), +4091 new Alteration("ū", "uu"), +4092 new Alteration("ī", "ii")*/); +4093 +4094 @Override +4095 public boolean equals(Object o) { +4096 if (this == o) return true; +4097 if (o == null || getClass() != o.getClass()) return false; +4098 +4099 Modifier modifier = (Modifier) o; +4100 +4101 // Probably incorrect - comparing Object[] arrays with Arrays.equals +4102 return Arrays.equals(alterations, modifier.alterations); +4103 } +4104 +4105 @Override +4106 public int hashCode() { +4107 return CrossHash.Lightning.hash(alterations); +4108 } +4109 +4110 @Override +4111 public String toString() { +4112 return "Modifier{" + +4113 "alterations=" + Arrays.toString(alterations) + +4114 '}'; +4115 } +4116 +4117 public String serializeToString() { +4118 if (alterations == null || alterations.length == 0) return "\6"; +4119 StringBuilder sb = new StringBuilder(32).append('\6'); +4120 for (int i = 0; i < alterations.length; i++) +4121 sb.append(alterations[i].serializeToString()).append('\6'); +4122 return sb.toString(); +4123 } 4124 -4125 Alteration that = (Alteration) o; -4126 -4127 if (Double.compare(that.chance, chance) != 0) return false; -4128 return replacer.equals(that.replacer); -4129 -4130 } -4131 -4132 @Override -4133 public int hashCode() { -4134 int result; -4135 long temp; -4136 result = replacer.hashCode(); -4137 temp = NumberTools.doubleToLongBits(chance); -4138 result = 31 * result + (int) (temp ^ (temp >>> 32)); -4139 return result; -4140 } -4141 -4142 @Override -4143 public String toString() { -4144 return "Alteration{" + -4145 "replacer=" + replacer + -4146 ", chance=" + chance + -4147 '}'; +4125 public static Modifier deserializeFromString(String data) { +4126 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; +4127 while (currIdx >= 0) { +4128 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) +4129 break; +4130 matches++; +4131 } +4132 Alteration[] alts = new Alteration[matches]; +4133 for (int i = 0; i < matches; i++) { +4134 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); +4135 } +4136 return new Modifier(alts); +4137 } +4138 } +4139 +4140 public static class Alteration implements Serializable { +4141 private static final long serialVersionUID = -2138854697837563188L; +4142 public Replacer replacer; +4143 public String replacement; +4144 public double chance; +4145 +4146 public Alteration() { +4147 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); 4148 } 4149 -4150 public String serializeToString() { -4151 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; -4152 } -4153 -4154 public static Alteration deserializeFromString(String data) { -4155 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); -4156 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), -4157 data.substring(split2 + 1, split4), -4158 Double.parseDouble(data.substring(split4 + 1))); -4159 } -4160 } +4150 public Alteration(String pattern, String replacement) { +4151 this.replacement = replacement; +4152 replacer = Pattern.compile(pattern).replacer(replacement); +4153 chance = 1.0; +4154 } +4155 +4156 public Alteration(String pattern, String replacement, double chance) { +4157 this.replacement = replacement; +4158 replacer = Pattern.compile(pattern).replacer(replacement); +4159 this.chance = chance; +4160 } 4161 -4162 /** -4163 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling -4164 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. -4165 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given -4166 * at construction. The parameters to -4167 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of -4168 * the same name, and all fields in this class are public and modifiable. -4169 */ -4170 public static class SentenceForm implements Serializable -4171 { -4172 private static final long serialVersionUID = 1246527948419533147L; -4173 public StatefulRNG rng; -4174 public int minWords, maxWords, maxChars; -4175 public String[] midPunctuation, endPunctuation; -4176 public double midPunctuationFrequency; -4177 public FakeLanguageGen language; -4178 public SentenceForm() -4179 { -4180 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, -4181 new String[]{",", ",", ",", ";", ";"}, -4182 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); -4183 } -4184 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) -4185 { -4186 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, -4187 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4162 public Alteration(Pattern pattern, String replacement, double chance) { +4163 this.replacement = replacement; +4164 replacer = pattern.replacer(replacement); +4165 this.chance = chance; +4166 } +4167 +4168 @Override +4169 public boolean equals(Object o) { +4170 if (this == o) return true; +4171 if (o == null || getClass() != o.getClass()) return false; +4172 +4173 Alteration that = (Alteration) o; +4174 +4175 if (Double.compare(that.chance, chance) != 0) return false; +4176 return replacer.equals(that.replacer); +4177 +4178 } +4179 +4180 @Override +4181 public int hashCode() { +4182 int result; +4183 long temp; +4184 result = replacer.hashCode(); +4185 temp = NumberTools.doubleToLongBits(chance); +4186 result = 31 * result + (int) (temp ^ (temp >>> 32)); +4187 return result; 4188 } -4189 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4190 String[] endPunctuation, double midPunctuationFrequency) -4191 { -4192 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4193 midPunctuationFrequency, -1); -4194 } -4195 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4196 String[] endPunctuation, double midPunctuationFrequency, int maxChars) -4197 { -4198 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4199 midPunctuationFrequency, maxChars); +4189 +4190 @Override +4191 public String toString() { +4192 return "Alteration{" + +4193 "replacer=" + replacer + +4194 ", chance=" + chance + +4195 '}'; +4196 } +4197 +4198 public String serializeToString() { +4199 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; 4200 } 4201 -4202 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, -4203 String[] midPunctuation, String[] endPunctuation, -4204 double midPunctuationFrequency, int maxChars) -4205 { -4206 this.language = language; -4207 this.rng = new StatefulRNG(rng.getState()); -4208 this.minWords = minWords; -4209 this.maxWords = maxWords; -4210 this.midPunctuation = midPunctuation; -4211 this.endPunctuation = endPunctuation; -4212 this.midPunctuationFrequency = midPunctuationFrequency; -4213 this.maxChars = maxChars; -4214 } -4215 public String sentence() -4216 { -4217 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, -4218 midPunctuationFrequency, maxChars); -4219 } -4220 -4221 public String serializeToString() { -4222 return language.serializeToString() + '℘' + -4223 rng.getState() + '℘' + -4224 minWords + '℘' + -4225 maxWords + '℘' + -4226 StringKit.join("ℙ", midPunctuation) + '℘' + -4227 StringKit.join("ℙ", endPunctuation) + '℘' + -4228 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + -4229 maxChars; -4230 } -4231 public static SentenceForm deserializeFromString(String ser) -4232 { -4233 int gap = ser.indexOf('℘'); -4234 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); -4235 StatefulRNG rng = new StatefulRNG( -4236 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4237 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4238 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4239 String[] midPunctuation = -4240 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4241 String[] endPunctuation = -4242 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4243 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4244 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); -4245 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); -4246 } -4247 } -4248} +4202 public static Alteration deserializeFromString(String data) { +4203 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); +4204 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), +4205 data.substring(split2 + 1, split4), +4206 Double.parseDouble(data.substring(split4 + 1))); +4207 } +4208 } +4209 +4210 /** +4211 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling +4212 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. +4213 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given +4214 * at construction. The parameters to +4215 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of +4216 * the same name, and all fields in this class are public and modifiable. +4217 */ +4218 public static class SentenceForm implements Serializable +4219 { +4220 private static final long serialVersionUID = 1246527948419533147L; +4221 public StatefulRNG rng; +4222 public int minWords, maxWords, maxChars; +4223 public String[] midPunctuation, endPunctuation; +4224 public double midPunctuationFrequency; +4225 public FakeLanguageGen language; +4226 public SentenceForm() +4227 { +4228 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, +4229 new String[]{",", ",", ",", ";", ";"}, +4230 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4231 } +4232 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) +4233 { +4234 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, +4235 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4236 } +4237 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4238 String[] endPunctuation, double midPunctuationFrequency) +4239 { +4240 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4241 midPunctuationFrequency, -1); +4242 } +4243 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4244 String[] endPunctuation, double midPunctuationFrequency, int maxChars) +4245 { +4246 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4247 midPunctuationFrequency, maxChars); +4248 } +4249 +4250 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, +4251 String[] midPunctuation, String[] endPunctuation, +4252 double midPunctuationFrequency, int maxChars) +4253 { +4254 this.language = language; +4255 this.rng = new StatefulRNG(rng.getState()); +4256 this.minWords = minWords; +4257 this.maxWords = maxWords; +4258 this.midPunctuation = midPunctuation; +4259 this.endPunctuation = endPunctuation; +4260 this.midPunctuationFrequency = midPunctuationFrequency; +4261 this.maxChars = maxChars; +4262 } +4263 public String sentence() +4264 { +4265 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, +4266 midPunctuationFrequency, maxChars); +4267 } +4268 +4269 public String serializeToString() { +4270 return language.serializeToString() + '℘' + +4271 rng.getState() + '℘' + +4272 minWords + '℘' + +4273 maxWords + '℘' + +4274 StringKit.join("ℙ", midPunctuation) + '℘' + +4275 StringKit.join("ℙ", endPunctuation) + '℘' + +4276 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + +4277 maxChars; +4278 } +4279 public static SentenceForm deserializeFromString(String ser) +4280 { +4281 int gap = ser.indexOf('℘'); +4282 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); +4283 StatefulRNG rng = new StatefulRNG( +4284 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4285 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4286 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4287 String[] midPunctuation = +4288 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4289 String[] endPunctuation = +4290 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4291 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4292 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); +4293 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); +4294 } +4295 } +4296} diff --git a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Modifier.html b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Modifier.html index ec9e555de4..9b8646dc36 100644 --- a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Modifier.html +++ b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.Modifier.html @@ -2059,2201 +2059,2249 @@ 2051 */ 2052 public static final FakeLanguageGen ALIEN_O = alien_o().register(); 2053 -2054 /** -2055 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages -2056 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric -2057 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this -2058 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, -2059 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null -2060 * elements in its original state, so some code may rely on the items being usable and non-null. -2061 */ -2062 public static final FakeLanguageGen[] registered; -2063 -2064 static { -2065 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. -2066 registered = new FakeLanguageGen[registry.size()-1]; -2067 for (int i = 0; i < registered.length; i++) { -2068 registered[i] = registry.getAt(i+1); -2069 } -2070 } -2071 /** -2072 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . -2073 */ -2074 public FakeLanguageGen() { -2075 this( -2076 new String[]{ -2077 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2078 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2079 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2080 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2081 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", -2082 }, -2083 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, -2084 new String[]{ -2085 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", -2086 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", -2087 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", -2088 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", -2089 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", -2090 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", -2091 "b", "d", "f", "g", "h", "l", "m", "n", -2092 "p", "r", "s", "sh", "t", "th", -2093 "b", "d", "f", "g", "h", "l", "m", "n", -2094 "p", "r", "s", "sh", "t", "th", -2095 "r", "s", "t", "l", "n", -2096 "str", "spr", "spl", "wr", "kn", "kn", "gn", -2097 }, -2098 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", -2099 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", -2100 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" -2101 }, -2102 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", -2103 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", -2104 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", -2105 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", -2106 }, -2107 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2108 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2109 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2110 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", -2111 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2112 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2113 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", -2114 }, -2115 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); -2116 } -2117 -2118 /** -2119 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2120 * class, LOVECRAFT and GREEK_ROMANIZED. -2121 * -2122 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2123 * of a word or in the middle; elements may be repeated to make them more common -2124 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2125 * middle of the word; all openingVowels are automatically copied into this internally. -2126 * Elements may be repeated to make them more common -2127 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2128 * at the start of a word; elements may be repeated to make them more common -2129 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2130 * between vowels; all closingConsonants are automatically copied into this internally. -2131 * Elements may be repeated to make them more common -2132 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2133 * at the end of a word; elements may be repeated to make them more common -2134 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2135 * whatever the word should end in; elements may be repeated to make them more common -2136 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2137 * then "a-a" may be possible; elements may be repeated to make them more common -2138 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2139 * tied to syllableFrequencies -2140 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2141 * represents how often each syllable count should appear relative to other counts; there -2142 * is no need to restrict the numbers to add up to any other number -2143 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2144 * higher numbers yield more words starting with vowels -2145 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2146 * numbers yield more words ending in vowels -2147 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2148 * often a vowel will be split into two vowels separated by one of those splitters -2149 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2150 * closingSyllables is used instead of ending normally -2151 */ -2152 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2153 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2154 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2155 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { -2156 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, -2157 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, -2158 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); -2159 } -2160 -2161 /** -2162 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2163 * class, LOVECRAFT and GREEK_ROMANIZED. -2164 * -2165 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2166 * of a word or in the middle; elements may be repeated to make them more common -2167 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2168 * middle of the word; all openingVowels are automatically copied into this internally. -2169 * Elements may be repeated to make them more common -2170 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2171 * at the start of a word; elements may be repeated to make them more common -2172 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2173 * between vowels; all closingConsonants are automatically copied into this internally. +2054 // àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳ +2055 // çðþñýćĉċčďđĝğġģĥħĵķĺļľŀłńņňŋŕŗřśŝşšţťŵŷÿźżžșțẁẃẅ +2056 private static FakeLanguageGen alien_u(){ +2057 return new FakeLanguageGen( +2058 new String[]{ +2059 "a", "a", "a", "a", "ä", "i", "o", "o", "o", "ö", "u", "u", "u", "u", "u", "u", "ü", "ü" +2060 }, +2061 new String[]{}, +2062 new String[]{ +2063 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2064 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2065 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2066 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2067 }, +2068 new String[]{ +2069 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2070 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2071 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2072 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2073 }, +2074 new String[]{ +2075 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", +2076 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2077 "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2078 }, +2079 new String[]{"emb", "embrid", "embraŋ", "eŋ", "eŋul", "eŋov", "eẃul", "eẃuld", "eẃulb", +2080 "eviś", "evim", "ełurn", "ełav", "egiġ", "ergiġ", "elgiġ", "eŕu", "eŕup", "eŕulm", "eŕuv", +2081 "eħul", "eħid", "eħiŋ", "eyü", "eyür", "eyürl", "eyüld", "eyüns", "eqä", "eqäp", "eqäġ", +2082 "esu", "esumb", "esulg", "esurl", "eśo", "eśold", "eśolg", "eśu", "eśur", "eśuŋ", +2083 "eñu", "eñuns", "eñurn", "eño", "eñolb", "eñols" +2084 }, +2085 new String[]{"'"}, new int[]{1, 2, 3, 4, 5}, new double[]{3, 4, 7, 5, 2}, 0.4, 0.15, 0.06, 0.5, null, true); +2086 } +2087 +2088 /** +2089 * Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for +2090 * an alien species. This alien language is meant to have an abrupt change mid-word for many words, with the suffix +2091 * of roughly half of words using the letter "e", which is absent from the rest of the language; these suffixes can +2092 * also use consonant clusters, which are similarly absent elsewhere. The suffixes would make sense as a historical +2093 * relic or as a linguistic holdout from a historical merger. As the name would suggest, it strongly prefers +2094 * using the vowel "u", with it present in about half the groups, and can use the umlaut accent "ü" on some vowels. +2095 * The consonants completely avoid hard sounds like "t" and "k", and don't cluster; they often have special marks. +2096 * This should be relatively easy to pronounce for an alien language, though the words are rather long. +2097 * <br> +2098 * Üweħid vuŕeħid deẃul leŋul waloyeyür; äyovavü... +2099 */ +2100 public static final FakeLanguageGen ALIEN_U = alien_u().register(); +2101 +2102 /** +2103 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages +2104 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric +2105 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this +2106 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, +2107 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null +2108 * elements in its original state, so some code may rely on the items being usable and non-null. +2109 */ +2110 public static final FakeLanguageGen[] registered; +2111 +2112 static { +2113 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. +2114 registered = new FakeLanguageGen[registry.size()-1]; +2115 for (int i = 0; i < registered.length; i++) { +2116 registered[i] = registry.getAt(i+1); +2117 } +2118 } +2119 /** +2120 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . +2121 */ +2122 public FakeLanguageGen() { +2123 this( +2124 new String[]{ +2125 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2126 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2127 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2128 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2129 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", +2130 }, +2131 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, +2132 new String[]{ +2133 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", +2134 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", +2135 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", +2136 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", +2137 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", +2138 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", +2139 "b", "d", "f", "g", "h", "l", "m", "n", +2140 "p", "r", "s", "sh", "t", "th", +2141 "b", "d", "f", "g", "h", "l", "m", "n", +2142 "p", "r", "s", "sh", "t", "th", +2143 "r", "s", "t", "l", "n", +2144 "str", "spr", "spl", "wr", "kn", "kn", "gn", +2145 }, +2146 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", +2147 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", +2148 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" +2149 }, +2150 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", +2151 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", +2152 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", +2153 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", +2154 }, +2155 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2156 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2157 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2158 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", +2159 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2160 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2161 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", +2162 }, +2163 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); +2164 } +2165 +2166 /** +2167 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2168 * class, LOVECRAFT and GREEK_ROMANIZED. +2169 * +2170 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2171 * of a word or in the middle; elements may be repeated to make them more common +2172 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2173 * middle of the word; all openingVowels are automatically copied into this internally. 2174 * Elements may be repeated to make them more common -2175 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2176 * at the end of a word; elements may be repeated to make them more common -2177 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2178 * whatever the word should end in; elements may be repeated to make them more common -2179 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2180 * then "a-a" may be possible; elements may be repeated to make them more common -2181 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2182 * tied to syllableFrequencies -2183 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2184 * represents how often each syllable count should appear relative to other counts; there -2185 * is no need to restrict the numbers to add up to any other number -2186 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2187 * higher numbers yield more words starting with vowels -2188 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2189 * numbers yield more words ending in vowels -2190 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2191 * often a vowel will be split into two vowels separated by one of those splitters -2192 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2193 * closingSyllables is used instead of ending normally -2194 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many -2195 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets -2196 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a -2197 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly -2198 */ -2199 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2200 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2201 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2202 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, -2203 Pattern[] sane, boolean clean) { -2204 this.openingVowels = openingVowels; -2205 this.midVowels = new String[openingVowels.length + midVowels.length]; -2206 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); -2207 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); -2208 this.openingConsonants = openingConsonants; -2209 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; -2210 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); -2211 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); -2212 this.closingConsonants = closingConsonants; -2213 this.vowelSplitters = vowelSplitters; -2214 this.closingSyllables = closingSyllables; -2215 -2216 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); -2217 -2218 totalSyllableFrequency = this.syllableFrequencies.values().sum(); -2219 if (vowelStartFrequency > 1.0) -2220 this.vowelStartFrequency = 1.0 / vowelStartFrequency; -2221 else -2222 this.vowelStartFrequency = vowelStartFrequency; -2223 if (vowelEndFrequency > 1.0) -2224 this.vowelEndFrequency = 1.0 / vowelEndFrequency; -2225 else -2226 this.vowelEndFrequency = vowelEndFrequency; -2227 if (vowelSplitters.length == 0) -2228 this.vowelSplitFrequency = 0.0; -2229 else if (vowelSplitFrequency > 1.0) -2230 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; -2231 else -2232 this.vowelSplitFrequency = vowelSplitFrequency; -2233 if (closingSyllables.length == 0) -2234 this.syllableEndFrequency = 0.0; -2235 else if (syllableEndFrequency > 1.0) -2236 this.syllableEndFrequency = 1.0 / syllableEndFrequency; -2237 else -2238 this.syllableEndFrequency = syllableEndFrequency; -2239 this.clean = clean; -2240 sanityChecks = sane; -2241 modifiers = new ArrayList<>(16); -2242 } -2243 -2244 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2245 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, -2246 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, -2247 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, -2248 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, -2249 List<Modifier> modifiers) { -2250 this.openingVowels = copyStrings(openingVowels); -2251 this.midVowels = copyStrings(midVowels); -2252 this.openingConsonants = copyStrings(openingConsonants); -2253 this.midConsonants = copyStrings(midConsonants); -2254 this.closingConsonants = copyStrings(closingConsonants); -2255 this.closingSyllables = copyStrings(closingSyllables); -2256 this.vowelSplitters = copyStrings(vowelSplitters); -2257 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); -2258 this.vowelStartFrequency = vowelStartFrequency; -2259 this.vowelEndFrequency = vowelEndFrequency; -2260 this.vowelSplitFrequency = vowelSplitFrequency; -2261 this.syllableEndFrequency = syllableEndFrequency; -2262 for (Double freq : this.syllableFrequencies.values()) { -2263 totalSyllableFrequency += freq; -2264 } -2265 if (sanityChecks == null) -2266 this.sanityChecks = null; -2267 else { -2268 this.sanityChecks = new Pattern[sanityChecks.length]; -2269 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); -2270 } -2271 this.clean = clean; -2272 this.modifiers = new ArrayList<>(modifiers); -2273 } -2274 -2275 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, -2276 Set<String> forbidden, RNG rng, double repeatSingleChance, -2277 int preferredLimit) { -2278 int l, sz = parts.size(); -2279 List<String> working = new ArrayList<>(sz * 24); -2280 String pair; -2281 for (int e = 0; e < parts.size(); e++) { -2282 Map.Entry<String, String> sn = parts.entryAt(e); -2283 if (missingSounds.contains(sn.getKey())) -2284 continue; -2285 for (String t : sn.getValue().split(" ")) { -2286 if (forbidden.contains(t)) -2287 continue; -2288 l = t.length(); -2289 int num; -2290 char c; -2291 switch (l) { -2292 case 0: -2293 break; -2294 case 1: -2295 working.add(t); -2296 working.add(t); -2297 working.add(t); -2298 c = t.charAt(0); -2299 num = 0; -2300 boolean repeat = true; -2301 switch (c) { -2302 case 'w': -2303 num += 2; -2304 case 'y': -2305 case 'h': -2306 num += 4; -2307 case 'q': -2308 case 'x': -2309 num += 4; -2310 repeat = false; -2311 break; -2312 case 'i': -2313 case 'u': -2314 repeat = false; -2315 num = 13; -2316 break; -2317 case 'z': -2318 case 'v': -2319 num = 4; -2320 break; -2321 case 'j': -2322 num = 7; -2323 break; -2324 default: -2325 if (e >= preferredLimit) -2326 num = 6; -2327 else -2328 num = 13; -2329 } -2330 for (int i = 0; i < num * 3; i++) { -2331 if (rng.nextDouble() < 0.75) { -2332 working.add(t); -2333 } -2334 } -2335 -2336 if (repeat && rng.nextDouble() < repeatSingleChance) { -2337 pair = t + t; -2338 if (missingSounds.contains(pair)) -2339 continue; -2340 working.add(pair); -2341 working.add(pair); -2342 working.add(pair); -2343 if (rng.nextDouble() < 0.7) { -2344 working.add(pair); -2345 working.add(pair); -2346 } -2347 if (rng.nextDouble() < 0.7) { -2348 working.add(pair); -2349 } -2350 } -2351 -2352 break; -2353 case 2: -2354 if (rng.nextDouble() < 0.65) { -2355 c = t.charAt(1); -2356 num = 0; -2357 switch (c) { -2358 case 'z': -2359 num = 1; -2360 break; -2361 case 'w': -2362 num = 3; -2363 break; -2364 case 'n': -2365 num = 4; -2366 break; -2367 default: -2368 -2369 if (e >= preferredLimit) -2370 num = 2; -2371 else -2372 num = 7; -2373 } -2374 working.add(t); -2375 for (int i = 0; i < num; i++) { -2376 if (rng.nextDouble() < 0.25) { -2377 working.add(t); -2378 } -2379 } -2380 } -2381 break; -2382 case 3: -2383 if (rng.nextDouble() < 0.5) { -2384 c = t.charAt(0); -2385 switch (c) { -2386 case 'z': -2387 num = 1; -2388 break; -2389 case 'w': -2390 num = 3; -2391 break; -2392 case 'n': -2393 num = 4; -2394 break; -2395 default: -2396 if (e >= preferredLimit) -2397 num = 2; -2398 else -2399 num = 6; -2400 } -2401 working.add(t); -2402 for (int i = 0; i < num; i++) { -2403 if (rng.nextDouble() < 0.2) { -2404 working.add(t); -2405 } -2406 } -2407 } -2408 break; -2409 default: -2410 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { -2411 working.add(t); -2412 } -2413 break; -2414 } -2415 } -2416 } -2417 return working.toArray(new String[0]); -2418 } -2419 -2420 /*private static final String[][] openVowels = new String[][]{ -2421 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, -2422 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, -2423 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, -2424 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, -2425 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, -2426 }; -2427*/ -2428 -2429 public static FakeLanguageGen randomLanguage(RNG rng) { -2430 return randomLanguage(rng.nextLong()); -2431 } -2432 -2433 public static FakeLanguageGen randomLanguage(long seed) { -2434 StatefulRNG rng = new StatefulRNG(seed); -2435 int[] lengths = new int[rng.between(3, 5)]; -2436 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); -2437 double[] chances = new double[lengths.length]; -2438 System.arraycopy(new double[]{ -2439 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) -2440 }, 0, chances, 0, chances.length); -2441 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); -2442 int sz = openCons.size(); -2443 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); -2444 OrderedMap<String, String> -2445 parts0 = new OrderedMap<>(openVowels), -2446 parts1 = new OrderedMap<>(openCons), -2447 parts2 = new OrderedMap<>(midCons), -2448 parts3 = new OrderedMap<>(closeCons); -2449 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); -2450 parts1.reorder(reordering); -2451 parts2.reorder(reordering); -2452 parts3.reorder(reordering); -2453 parts0.reorder(vOrd); -2454 int n = 0; -2455 -2456 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; -2457 -2458 for (n = 0; n < mn; n++) { -2459 missingSounds.add(parts0.keyAt(0)); -2460 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); -2461 parts0.removeFirst(); -2462 } -2463 p0s = parts0.size(); -2464 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); -2465 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; -2466 int vowelAccent = rng.between(1, 7); -2467 for (int i = 0; i < sz0; i++) { -2468 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; -2469 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; -2470 } -2471 if (rng.nextDouble() < 0.8) { -2472 for (int i = 0; i < sz0; i++) { -2473 char ac = nextAccents[i], ua = unaccented[i]; -2474 String v = "", uas = String.valueOf(ua); -2475 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); -2476 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); -2477 for (int j = 0; j < p0s; j++) { -2478 String k = parts0.keyAt(j); -2479 if (uas.equals(k)) -2480 v = parts0.getAt(j); -2481 else { -2482 String current = parts0.getAt(j); -2483 String[] splits = current.split(" "); -2484 for (int s = 0; s < splits.length; s++) { -2485 if (forbidden.contains(uas) && splits[s].contains(uas)) -2486 forbidden.add(splits[s].replace(ua, ac)); -2487 } -2488 parts0.put(k, rep.replace(current)); -2489 } -2490 } -2491 parts0.put(String.valueOf(ac), repLess.replace(v)); -2492 } -2493 } -2494 -2495 n = 0; -2496 if (rng.nextDouble() < 0.75) { -2497 missingSounds.add("z"); -2498 Collections.addAll(forbidden, parts1.get("z").split(" ")); -2499 Collections.addAll(forbidden, parts2.get("z").split(" ")); -2500 Collections.addAll(forbidden, parts3.get("z").split(" ")); -2501 n++; -2502 } -2503 if (rng.nextDouble() < 0.82) { -2504 missingSounds.add("x"); -2505 Collections.addAll(forbidden, parts1.get("x").split(" ")); -2506 Collections.addAll(forbidden, parts2.get("x").split(" ")); -2507 Collections.addAll(forbidden, parts3.get("x").split(" ")); -2508 n++; -2509 } -2510 if (rng.nextDouble() < 0.92) { -2511 missingSounds.add("qu"); -2512 Collections.addAll(forbidden, parts1.get("qu").split(" ")); -2513 Collections.addAll(forbidden, parts2.get("qu").split(" ")); -2514 Collections.addAll(forbidden, parts3.get("qu").split(" ")); -2515 n++; -2516 } -2517 if (rng.nextDouble() < 0.96) { -2518 missingSounds.add("q"); -2519 Collections.addAll(forbidden, parts1.get("q").split(" ")); -2520 Collections.addAll(forbidden, parts2.get("q").split(" ")); -2521 Collections.addAll(forbidden, parts3.get("q").split(" ")); -2522 n++; -2523 } -2524 if (rng.nextDouble() < 0.97) { -2525 missingSounds.add("tl"); -2526 Collections.addAll(forbidden, parts1.get("tl").split(" ")); -2527 Collections.addAll(forbidden, parts2.get("tl").split(" ")); -2528 Collections.addAll(forbidden, parts3.get("tl").split(" ")); -2529 n++; -2530 } -2531 if (rng.nextDouble() < 0.86) { -2532 missingSounds.add("ph"); -2533 Collections.addAll(forbidden, parts1.get("ph").split(" ")); -2534 Collections.addAll(forbidden, parts2.get("ph").split(" ")); -2535 Collections.addAll(forbidden, parts3.get("ph").split(" ")); -2536 n++; -2537 } -2538 if (rng.nextDouble() < 0.94) { -2539 missingSounds.add("kh"); -2540 Collections.addAll(forbidden, parts1.get("kh").split(" ")); -2541 Collections.addAll(forbidden, parts2.get("kh").split(" ")); -2542 Collections.addAll(forbidden, parts3.get("kh").split(" ")); -2543 n++; -2544 } -2545 if (rng.nextDouble() < 0.96) { -2546 missingSounds.add("bh"); -2547 missingSounds.add("dh"); -2548 Collections.addAll(forbidden, parts1.get("bh").split(" ")); -2549 Collections.addAll(forbidden, parts2.get("bh").split(" ")); -2550 Collections.addAll(forbidden, parts3.get("bh").split(" ")); -2551 Collections.addAll(forbidden, parts1.get("dh").split(" ")); -2552 Collections.addAll(forbidden, parts2.get("dh").split(" ")); -2553 Collections.addAll(forbidden, parts3.get("dh").split(" ")); -2554 n++; -2555 n++; -2556 } -2557 -2558 for (; n < sz * removalRate; n++) { -2559 missingSounds.add(parts1.keyAt(n)); -2560 missingSounds.add(parts2.keyAt(n)); -2561 missingSounds.add(parts3.keyAt(n)); -2562 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); -2563 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); -2564 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); -2565 } -2566 -2567 return new FakeLanguageGen( -2568 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), -2569 new String[]{"y", "y"}, -2570 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), -2571 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), -2572 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), -2573 new String[]{}, -2574 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); -2575 } -2576 -2577 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { -2578 CharSequence fixed = removeAccents(testing); -2579 for (int i = 0; i < checks.length; i++) { -2580 if (checks[i].matcher(fixed).find()) -2581 return false; -2582 } -2583 return true; -2584 } -2585 -2586 /** -2587 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text -2588 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives -2589 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers -2590 * that could look like letters. -2591 * @param testing the text, as a CharSequence such as a String, to check -2592 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't -2593 */ -2594 public static boolean checkVulgarity(CharSequence testing) -2595 { -2596 CharSequence fixed = removeAccents(testing); -2597 for (int i = 0; i < vulgarChecks.length; i++) { -2598 if (vulgarChecks[i].matcher(fixed).find()) -2599 { -2600 System.out.println(vulgarChecks[i]); -2601 return true; -2602 } -2603 } -2604 return false; -2605 } -2606 -2607 /** -2608 * Generate a word from this FakeLanguageGen, using and changing the current seed. -2609 * -2610 * @param capitalize true if the word should start with a capital letter, false otherwise -2611 * @return a word in the fake language as a String -2612 */ -2613 public String word(boolean capitalize) { -2614 return word(srng, capitalize); -2615 } -2616 -2617 /** -2618 * Generate a word from this FakeLanguageGen using the specified RNG. -2619 * -2620 * @param rng the RNG to use for the randomized string building -2621 * @param capitalize true if the word should start with a capital letter, false otherwise -2622 * @return a word in the fake language as a String -2623 */ -2624 public String word(RNG rng, boolean capitalize) { -2625 while (true) { -2626 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2627 double syllableChance = rng.nextDouble(totalSyllableFrequency); -2628 int syllables = 1, i = 0; -2629 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { -2630 if (syllableChance < kv.getDoubleValue()) { -2631 syllables = kv.getIntKey(); -2632 break; -2633 } else -2634 syllableChance -= kv.getDoubleValue(); -2635 } -2636 if (rng.nextDouble() < vowelStartFrequency) { -2637 sb.append(rng.getRandomElement(openingVowels)); -2638 if (syllables == 1) -2639 sb.append(rng.getRandomElement(closingConsonants)); -2640 else -2641 sb.append(rng.getRandomElement(midConsonants)); -2642 i++; -2643 } else { -2644 sb.append(rng.getRandomElement(openingConsonants)); -2645 } -2646 String close = ""; -2647 boolean redouble = false; -2648 if (i < syllables) { -2649 if (rng.nextDouble() < syllableEndFrequency) { -2650 close = rng.getRandomElement(closingSyllables); -2651 if (close.contains("@") && (syllables & 1) == 0) { -2652 redouble = true; -2653 syllables = (syllables | 1) >> 1; +2175 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2176 * at the start of a word; elements may be repeated to make them more common +2177 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2178 * between vowels; all closingConsonants are automatically copied into this internally. +2179 * Elements may be repeated to make them more common +2180 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2181 * at the end of a word; elements may be repeated to make them more common +2182 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2183 * whatever the word should end in; elements may be repeated to make them more common +2184 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2185 * then "a-a" may be possible; elements may be repeated to make them more common +2186 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2187 * tied to syllableFrequencies +2188 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2189 * represents how often each syllable count should appear relative to other counts; there +2190 * is no need to restrict the numbers to add up to any other number +2191 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2192 * higher numbers yield more words starting with vowels +2193 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2194 * numbers yield more words ending in vowels +2195 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2196 * often a vowel will be split into two vowels separated by one of those splitters +2197 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2198 * closingSyllables is used instead of ending normally +2199 */ +2200 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2201 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2202 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2203 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { +2204 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, +2205 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, +2206 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); +2207 } +2208 +2209 /** +2210 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2211 * class, LOVECRAFT and GREEK_ROMANIZED. +2212 * +2213 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2214 * of a word or in the middle; elements may be repeated to make them more common +2215 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2216 * middle of the word; all openingVowels are automatically copied into this internally. +2217 * Elements may be repeated to make them more common +2218 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2219 * at the start of a word; elements may be repeated to make them more common +2220 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2221 * between vowels; all closingConsonants are automatically copied into this internally. +2222 * Elements may be repeated to make them more common +2223 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2224 * at the end of a word; elements may be repeated to make them more common +2225 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2226 * whatever the word should end in; elements may be repeated to make them more common +2227 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2228 * then "a-a" may be possible; elements may be repeated to make them more common +2229 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2230 * tied to syllableFrequencies +2231 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2232 * represents how often each syllable count should appear relative to other counts; there +2233 * is no need to restrict the numbers to add up to any other number +2234 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2235 * higher numbers yield more words starting with vowels +2236 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2237 * numbers yield more words ending in vowels +2238 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2239 * often a vowel will be split into two vowels separated by one of those splitters +2240 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2241 * closingSyllables is used instead of ending normally +2242 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many +2243 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets +2244 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a +2245 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly +2246 */ +2247 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2248 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2249 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2250 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, +2251 Pattern[] sane, boolean clean) { +2252 this.openingVowels = openingVowels; +2253 this.midVowels = new String[openingVowels.length + midVowels.length]; +2254 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); +2255 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); +2256 this.openingConsonants = openingConsonants; +2257 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; +2258 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); +2259 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); +2260 this.closingConsonants = closingConsonants; +2261 this.vowelSplitters = vowelSplitters; +2262 this.closingSyllables = closingSyllables; +2263 +2264 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); +2265 +2266 totalSyllableFrequency = this.syllableFrequencies.values().sum(); +2267 if (vowelStartFrequency > 1.0) +2268 this.vowelStartFrequency = 1.0 / vowelStartFrequency; +2269 else +2270 this.vowelStartFrequency = vowelStartFrequency; +2271 if (vowelEndFrequency > 1.0) +2272 this.vowelEndFrequency = 1.0 / vowelEndFrequency; +2273 else +2274 this.vowelEndFrequency = vowelEndFrequency; +2275 if (vowelSplitters.length == 0) +2276 this.vowelSplitFrequency = 0.0; +2277 else if (vowelSplitFrequency > 1.0) +2278 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; +2279 else +2280 this.vowelSplitFrequency = vowelSplitFrequency; +2281 if (closingSyllables.length == 0) +2282 this.syllableEndFrequency = 0.0; +2283 else if (syllableEndFrequency > 1.0) +2284 this.syllableEndFrequency = 1.0 / syllableEndFrequency; +2285 else +2286 this.syllableEndFrequency = syllableEndFrequency; +2287 this.clean = clean; +2288 sanityChecks = sane; +2289 modifiers = new ArrayList<>(16); +2290 } +2291 +2292 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2293 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, +2294 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, +2295 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, +2296 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, +2297 List<Modifier> modifiers) { +2298 this.openingVowels = copyStrings(openingVowels); +2299 this.midVowels = copyStrings(midVowels); +2300 this.openingConsonants = copyStrings(openingConsonants); +2301 this.midConsonants = copyStrings(midConsonants); +2302 this.closingConsonants = copyStrings(closingConsonants); +2303 this.closingSyllables = copyStrings(closingSyllables); +2304 this.vowelSplitters = copyStrings(vowelSplitters); +2305 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); +2306 this.vowelStartFrequency = vowelStartFrequency; +2307 this.vowelEndFrequency = vowelEndFrequency; +2308 this.vowelSplitFrequency = vowelSplitFrequency; +2309 this.syllableEndFrequency = syllableEndFrequency; +2310 for (Double freq : this.syllableFrequencies.values()) { +2311 totalSyllableFrequency += freq; +2312 } +2313 if (sanityChecks == null) +2314 this.sanityChecks = null; +2315 else { +2316 this.sanityChecks = new Pattern[sanityChecks.length]; +2317 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); +2318 } +2319 this.clean = clean; +2320 this.modifiers = new ArrayList<>(modifiers); +2321 } +2322 +2323 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, +2324 Set<String> forbidden, RNG rng, double repeatSingleChance, +2325 int preferredLimit) { +2326 int l, sz = parts.size(); +2327 List<String> working = new ArrayList<>(sz * 24); +2328 String pair; +2329 for (int e = 0; e < parts.size(); e++) { +2330 Map.Entry<String, String> sn = parts.entryAt(e); +2331 if (missingSounds.contains(sn.getKey())) +2332 continue; +2333 for (String t : sn.getValue().split(" ")) { +2334 if (forbidden.contains(t)) +2335 continue; +2336 l = t.length(); +2337 int num; +2338 char c; +2339 switch (l) { +2340 case 0: +2341 break; +2342 case 1: +2343 working.add(t); +2344 working.add(t); +2345 working.add(t); +2346 c = t.charAt(0); +2347 num = 0; +2348 boolean repeat = true; +2349 switch (c) { +2350 case 'w': +2351 num += 2; +2352 case 'y': +2353 case 'h': +2354 num += 4; +2355 case 'q': +2356 case 'x': +2357 num += 4; +2358 repeat = false; +2359 break; +2360 case 'i': +2361 case 'u': +2362 repeat = false; +2363 num = 13; +2364 break; +2365 case 'z': +2366 case 'v': +2367 num = 4; +2368 break; +2369 case 'j': +2370 num = 7; +2371 break; +2372 default: +2373 if (e >= preferredLimit) +2374 num = 6; +2375 else +2376 num = 13; +2377 } +2378 for (int i = 0; i < num * 3; i++) { +2379 if (rng.nextDouble() < 0.75) { +2380 working.add(t); +2381 } +2382 } +2383 +2384 if (repeat && rng.nextDouble() < repeatSingleChance) { +2385 pair = t + t; +2386 if (missingSounds.contains(pair)) +2387 continue; +2388 working.add(pair); +2389 working.add(pair); +2390 working.add(pair); +2391 if (rng.nextDouble() < 0.7) { +2392 working.add(pair); +2393 working.add(pair); +2394 } +2395 if (rng.nextDouble() < 0.7) { +2396 working.add(pair); +2397 } +2398 } +2399 +2400 break; +2401 case 2: +2402 if (rng.nextDouble() < 0.65) { +2403 c = t.charAt(1); +2404 num = 0; +2405 switch (c) { +2406 case 'z': +2407 num = 1; +2408 break; +2409 case 'w': +2410 num = 3; +2411 break; +2412 case 'n': +2413 num = 4; +2414 break; +2415 default: +2416 +2417 if (e >= preferredLimit) +2418 num = 2; +2419 else +2420 num = 7; +2421 } +2422 working.add(t); +2423 for (int i = 0; i < num; i++) { +2424 if (rng.nextDouble() < 0.25) { +2425 working.add(t); +2426 } +2427 } +2428 } +2429 break; +2430 case 3: +2431 if (rng.nextDouble() < 0.5) { +2432 c = t.charAt(0); +2433 switch (c) { +2434 case 'z': +2435 num = 1; +2436 break; +2437 case 'w': +2438 num = 3; +2439 break; +2440 case 'n': +2441 num = 4; +2442 break; +2443 default: +2444 if (e >= preferredLimit) +2445 num = 2; +2446 else +2447 num = 6; +2448 } +2449 working.add(t); +2450 for (int i = 0; i < num; i++) { +2451 if (rng.nextDouble() < 0.2) { +2452 working.add(t); +2453 } +2454 } +2455 } +2456 break; +2457 default: +2458 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { +2459 working.add(t); +2460 } +2461 break; +2462 } +2463 } +2464 } +2465 return working.toArray(new String[0]); +2466 } +2467 +2468 /*private static final String[][] openVowels = new String[][]{ +2469 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, +2470 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, +2471 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, +2472 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, +2473 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, +2474 }; +2475*/ +2476 +2477 public static FakeLanguageGen randomLanguage(RNG rng) { +2478 return randomLanguage(rng.nextLong()); +2479 } +2480 +2481 public static FakeLanguageGen randomLanguage(long seed) { +2482 StatefulRNG rng = new StatefulRNG(seed); +2483 int[] lengths = new int[rng.between(3, 5)]; +2484 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); +2485 double[] chances = new double[lengths.length]; +2486 System.arraycopy(new double[]{ +2487 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) +2488 }, 0, chances, 0, chances.length); +2489 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); +2490 int sz = openCons.size(); +2491 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); +2492 OrderedMap<String, String> +2493 parts0 = new OrderedMap<>(openVowels), +2494 parts1 = new OrderedMap<>(openCons), +2495 parts2 = new OrderedMap<>(midCons), +2496 parts3 = new OrderedMap<>(closeCons); +2497 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); +2498 parts1.reorder(reordering); +2499 parts2.reorder(reordering); +2500 parts3.reorder(reordering); +2501 parts0.reorder(vOrd); +2502 int n = 0; +2503 +2504 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; +2505 +2506 for (n = 0; n < mn; n++) { +2507 missingSounds.add(parts0.keyAt(0)); +2508 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); +2509 parts0.removeFirst(); +2510 } +2511 p0s = parts0.size(); +2512 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); +2513 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; +2514 int vowelAccent = rng.between(1, 7); +2515 for (int i = 0; i < sz0; i++) { +2516 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; +2517 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; +2518 } +2519 if (rng.nextDouble() < 0.8) { +2520 for (int i = 0; i < sz0; i++) { +2521 char ac = nextAccents[i], ua = unaccented[i]; +2522 String v = "", uas = String.valueOf(ua); +2523 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); +2524 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); +2525 for (int j = 0; j < p0s; j++) { +2526 String k = parts0.keyAt(j); +2527 if (uas.equals(k)) +2528 v = parts0.getAt(j); +2529 else { +2530 String current = parts0.getAt(j); +2531 String[] splits = current.split(" "); +2532 for (int s = 0; s < splits.length; s++) { +2533 if (forbidden.contains(uas) && splits[s].contains(uas)) +2534 forbidden.add(splits[s].replace(ua, ac)); +2535 } +2536 parts0.put(k, rep.replace(current)); +2537 } +2538 } +2539 parts0.put(String.valueOf(ac), repLess.replace(v)); +2540 } +2541 } +2542 +2543 n = 0; +2544 if (rng.nextDouble() < 0.75) { +2545 missingSounds.add("z"); +2546 Collections.addAll(forbidden, parts1.get("z").split(" ")); +2547 Collections.addAll(forbidden, parts2.get("z").split(" ")); +2548 Collections.addAll(forbidden, parts3.get("z").split(" ")); +2549 n++; +2550 } +2551 if (rng.nextDouble() < 0.82) { +2552 missingSounds.add("x"); +2553 Collections.addAll(forbidden, parts1.get("x").split(" ")); +2554 Collections.addAll(forbidden, parts2.get("x").split(" ")); +2555 Collections.addAll(forbidden, parts3.get("x").split(" ")); +2556 n++; +2557 } +2558 if (rng.nextDouble() < 0.92) { +2559 missingSounds.add("qu"); +2560 Collections.addAll(forbidden, parts1.get("qu").split(" ")); +2561 Collections.addAll(forbidden, parts2.get("qu").split(" ")); +2562 Collections.addAll(forbidden, parts3.get("qu").split(" ")); +2563 n++; +2564 } +2565 if (rng.nextDouble() < 0.96) { +2566 missingSounds.add("q"); +2567 Collections.addAll(forbidden, parts1.get("q").split(" ")); +2568 Collections.addAll(forbidden, parts2.get("q").split(" ")); +2569 Collections.addAll(forbidden, parts3.get("q").split(" ")); +2570 n++; +2571 } +2572 if (rng.nextDouble() < 0.97) { +2573 missingSounds.add("tl"); +2574 Collections.addAll(forbidden, parts1.get("tl").split(" ")); +2575 Collections.addAll(forbidden, parts2.get("tl").split(" ")); +2576 Collections.addAll(forbidden, parts3.get("tl").split(" ")); +2577 n++; +2578 } +2579 if (rng.nextDouble() < 0.86) { +2580 missingSounds.add("ph"); +2581 Collections.addAll(forbidden, parts1.get("ph").split(" ")); +2582 Collections.addAll(forbidden, parts2.get("ph").split(" ")); +2583 Collections.addAll(forbidden, parts3.get("ph").split(" ")); +2584 n++; +2585 } +2586 if (rng.nextDouble() < 0.94) { +2587 missingSounds.add("kh"); +2588 Collections.addAll(forbidden, parts1.get("kh").split(" ")); +2589 Collections.addAll(forbidden, parts2.get("kh").split(" ")); +2590 Collections.addAll(forbidden, parts3.get("kh").split(" ")); +2591 n++; +2592 } +2593 if (rng.nextDouble() < 0.96) { +2594 missingSounds.add("bh"); +2595 missingSounds.add("dh"); +2596 Collections.addAll(forbidden, parts1.get("bh").split(" ")); +2597 Collections.addAll(forbidden, parts2.get("bh").split(" ")); +2598 Collections.addAll(forbidden, parts3.get("bh").split(" ")); +2599 Collections.addAll(forbidden, parts1.get("dh").split(" ")); +2600 Collections.addAll(forbidden, parts2.get("dh").split(" ")); +2601 Collections.addAll(forbidden, parts3.get("dh").split(" ")); +2602 n++; +2603 n++; +2604 } +2605 +2606 for (; n < sz * removalRate; n++) { +2607 missingSounds.add(parts1.keyAt(n)); +2608 missingSounds.add(parts2.keyAt(n)); +2609 missingSounds.add(parts3.keyAt(n)); +2610 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); +2611 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); +2612 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); +2613 } +2614 +2615 return new FakeLanguageGen( +2616 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), +2617 new String[]{"y", "y"}, +2618 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), +2619 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), +2620 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), +2621 new String[]{}, +2622 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); +2623 } +2624 +2625 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { +2626 CharSequence fixed = removeAccents(testing); +2627 for (int i = 0; i < checks.length; i++) { +2628 if (checks[i].matcher(fixed).find()) +2629 return false; +2630 } +2631 return true; +2632 } +2633 +2634 /** +2635 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text +2636 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives +2637 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers +2638 * that could look like letters. +2639 * @param testing the text, as a CharSequence such as a String, to check +2640 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't +2641 */ +2642 public static boolean checkVulgarity(CharSequence testing) +2643 { +2644 CharSequence fixed = removeAccents(testing); +2645 for (int i = 0; i < vulgarChecks.length; i++) { +2646 if (vulgarChecks[i].matcher(fixed).find()) +2647 { +2648 System.out.println(vulgarChecks[i]); +2649 return true; +2650 } +2651 } +2652 return false; +2653 } 2654 -2655 //sb.append(close.replaceAll("@\\d", sb.toString())); -2656 } -2657 if (!close.contains("@")) -2658 ender.append(close); -2659 else if (rng.nextDouble() < vowelEndFrequency) { -2660 ender.append(rng.getRandomElement(midVowels)); -2661 if (rng.nextDouble() < vowelSplitFrequency) { -2662 ender.append(rng.getRandomElement(vowelSplitters)); -2663 ender.append(rng.getRandomElement(midVowels)); -2664 } -2665 } -2666 } else { -2667 ender.append(rng.getRandomElement(midVowels)); -2668 if (rng.nextDouble() < vowelSplitFrequency) { -2669 ender.append(rng.getRandomElement(vowelSplitters)); -2670 ender.append(rng.getRandomElement(midVowels)); -2671 } -2672 if (rng.nextDouble() >= vowelEndFrequency) { -2673 ender.append(rng.getRandomElement(closingConsonants)); -2674 if (rng.nextDouble() < syllableEndFrequency) { -2675 close = rng.getRandomElement(closingSyllables); -2676 if (close.contains("@") && (syllables & 1) == 0) { -2677 redouble = true; -2678 syllables = (syllables | 1) >> 1; -2679 -2680 //sb.append(close.replaceAll("@\\d", sb.toString())); -2681 } -2682 if (!close.contains("@")) -2683 ender.append(close); -2684 } -2685 } -2686 } -2687 i += vowelClusters.matcher(ender).findAll().count(); -2688 -2689 } -2690 -2691 for (; i < syllables; i++) { -2692 sb.append(rng.getRandomElement(midVowels)); -2693 if (rng.nextDouble() < vowelSplitFrequency) { -2694 sb.append(rng.getRandomElement(vowelSplitters)); -2695 sb.append(rng.getRandomElement(midVowels)); -2696 } -2697 sb.append(rng.getRandomElement(midConsonants)); -2698 } -2699 -2700 sb.append(ender); -2701 if (redouble && i <= syllables + 1) { -2702 sb.append(close.replaceAll("@", sb.toString())); -2703 } -2704 -2705 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2706 continue; -2707 -2708 for (Modifier mod : modifiers) { -2709 sb = mod.modify(rng, sb); -2710 } -2711 -2712 if (capitalize) -2713 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2714 -2715 if (clean && !checkAll(sb, vulgarChecks)) -2716 continue; -2717 return sb.toString(); -2718 } -2719 } -2720 -2721 /** -2722 * Generate a word from this FakeLanguageGen using the specified RNG. -2723 * -2724 * @param rng the RNG to use for the randomized string building -2725 * @param capitalize true if the word should start with a capital letter, false otherwise -2726 * @return a word in the fake language as a String -2727 */ -2728 public String word(RNG rng, boolean capitalize, int approxSyllables) { -2729 return word(rng, capitalize, approxSyllables, null); -2730 } -2731 -2732 /** -2733 * Generate a word from this FakeLanguageGen using the specified RNG. -2734 * -2735 * @param rng the RNG to use for the randomized string building -2736 * @param capitalize true if the word should start with a capital letter, false otherwise -2737 * @return a word in the fake language as a String -2738 */ -2739 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { -2740 if (approxSyllables <= 0) { -2741 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2742 for (Modifier mod : modifiers) { -2743 sb = mod.modify(rng, sb); -2744 } -2745 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2746 return sb.toString(); -2747 } -2748 while (true) { -2749 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2750 int i = 0; -2751 if (rng.nextDouble() < vowelStartFrequency) { -2752 sb.append(rng.getRandomElement(openingVowels)); -2753 if (approxSyllables == 1 && closingConsonants.length > 0) -2754 sb.append(rng.getRandomElement(closingConsonants)); -2755 else if (midConsonants.length > 0) -2756 sb.append(rng.getRandomElement(midConsonants)); -2757 i++; -2758 } else if (openingConsonants.length > 0) { -2759 sb.append(rng.getRandomElement(openingConsonants)); -2760 } -2761 String close = ""; -2762 boolean redouble = false; -2763 if (i < approxSyllables) { -2764 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { -2765 close = rng.getRandomElement(closingSyllables); -2766 if (close.contains("@") && (approxSyllables & 1) == 0) { -2767 redouble = true; -2768 approxSyllables = approxSyllables >> 1; -2769 -2770 //sb.append(close.replaceAll("@\\d", sb.toString())); -2771 } -2772 if (!close.contains("@")) -2773 ender.append(close); -2774 else if (redouble && rng.nextDouble() < vowelEndFrequency) { -2775 ender.append(rng.getRandomElement(midVowels)); -2776 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { -2777 ender.append(rng.getRandomElement(vowelSplitters)); -2778 ender.append(rng.getRandomElement(midVowels)); -2779 } -2780 } -2781 } else { -2782 ender.append(rng.getRandomElement(midVowels)); -2783 if (rng.nextDouble() < vowelSplitFrequency) { -2784 ender.append(rng.getRandomElement(vowelSplitters)); -2785 ender.append(rng.getRandomElement(midVowels)); -2786 } -2787 if (rng.nextDouble() >= vowelEndFrequency) { -2788 ender.append(rng.getRandomElement(closingConsonants)); -2789 if (rng.nextDouble() < syllableEndFrequency) { -2790 close = rng.getRandomElement(closingSyllables); -2791 if (close.contains("@") && (approxSyllables & 1) == 0) { -2792 redouble = true; -2793 approxSyllables = approxSyllables >> 1; -2794 -2795 //sb.append(close.replaceAll("@\\d", sb.toString())); -2796 } -2797 if (!close.contains("@")) -2798 ender.append(close); -2799 } -2800 } -2801 } -2802 i += vowelClusters.matcher(ender).findAll().count(); -2803 } -2804 -2805 for (; i < approxSyllables; i++) { -2806 sb.append(rng.getRandomElement(midVowels)); -2807 if (rng.nextDouble() < vowelSplitFrequency) { -2808 sb.append(rng.getRandomElement(vowelSplitters)); -2809 sb.append(rng.getRandomElement(midVowels)); -2810 } -2811 sb.append(rng.getRandomElement(midConsonants)); -2812 } -2813 -2814 sb.append(ender); -2815 if (redouble && i <= approxSyllables + 1) { -2816 sb.append(close.replaceAll("@", sb.toString())); -2817 } -2818 -2819 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2820 continue; -2821 -2822 for (Modifier mod : modifiers) { -2823 sb = mod.modify(rng, sb); -2824 } -2825 -2826 if (clean && !checkAll(sb, vulgarChecks)) -2827 continue; -2828 -2829 if (additionalChecks != null && !checkAll(sb, additionalChecks)) -2830 continue; -2831 -2832 if (capitalize) -2833 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2834 -2835 return sb.toString(); -2836 } -2837 } -2838 -2839 /** -2840 * Generate a word from this FakeLanguageGen using the specified RNG. -2841 * -2842 * @param rng the RNG to use for the randomized string building -2843 * @param capitalize true if the word should start with a capital letter, false otherwise -2844 * @return a word in the fake language as a String -2845 */ -2846 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { -2847 if (approxSyllables <= 0) { -2848 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2849 for (Modifier mod : modifiers) { -2850 sb = mod.modify(rng, sb); +2655 /** +2656 * Generate a word from this FakeLanguageGen, using and changing the current seed. +2657 * +2658 * @param capitalize true if the word should start with a capital letter, false otherwise +2659 * @return a word in the fake language as a String +2660 */ +2661 public String word(boolean capitalize) { +2662 return word(srng, capitalize); +2663 } +2664 +2665 /** +2666 * Generate a word from this FakeLanguageGen using the specified RNG. +2667 * +2668 * @param rng the RNG to use for the randomized string building +2669 * @param capitalize true if the word should start with a capital letter, false otherwise +2670 * @return a word in the fake language as a String +2671 */ +2672 public String word(RNG rng, boolean capitalize) { +2673 while (true) { +2674 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2675 double syllableChance = rng.nextDouble(totalSyllableFrequency); +2676 int syllables = 1, i = 0; +2677 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { +2678 if (syllableChance < kv.getDoubleValue()) { +2679 syllables = kv.getIntKey(); +2680 break; +2681 } else +2682 syllableChance -= kv.getDoubleValue(); +2683 } +2684 if (rng.nextDouble() < vowelStartFrequency) { +2685 sb.append(rng.getRandomElement(openingVowels)); +2686 if (syllables == 1) +2687 sb.append(rng.getRandomElement(closingConsonants)); +2688 else +2689 sb.append(rng.getRandomElement(midConsonants)); +2690 i++; +2691 } else { +2692 sb.append(rng.getRandomElement(openingConsonants)); +2693 } +2694 String close = ""; +2695 boolean redouble = false; +2696 if (i < syllables) { +2697 if (rng.nextDouble() < syllableEndFrequency) { +2698 close = rng.getRandomElement(closingSyllables); +2699 if (close.contains("@") && (syllables & 1) == 0) { +2700 redouble = true; +2701 syllables = (syllables | 1) >> 1; +2702 +2703 //sb.append(close.replaceAll("@\\d", sb.toString())); +2704 } +2705 if (!close.contains("@")) +2706 ender.append(close); +2707 else if (rng.nextDouble() < vowelEndFrequency) { +2708 ender.append(rng.getRandomElement(midVowels)); +2709 if (rng.nextDouble() < vowelSplitFrequency) { +2710 ender.append(rng.getRandomElement(vowelSplitters)); +2711 ender.append(rng.getRandomElement(midVowels)); +2712 } +2713 } +2714 } else { +2715 ender.append(rng.getRandomElement(midVowels)); +2716 if (rng.nextDouble() < vowelSplitFrequency) { +2717 ender.append(rng.getRandomElement(vowelSplitters)); +2718 ender.append(rng.getRandomElement(midVowels)); +2719 } +2720 if (rng.nextDouble() >= vowelEndFrequency) { +2721 ender.append(rng.getRandomElement(closingConsonants)); +2722 if (rng.nextDouble() < syllableEndFrequency) { +2723 close = rng.getRandomElement(closingSyllables); +2724 if (close.contains("@") && (syllables & 1) == 0) { +2725 redouble = true; +2726 syllables = (syllables | 1) >> 1; +2727 +2728 //sb.append(close.replaceAll("@\\d", sb.toString())); +2729 } +2730 if (!close.contains("@")) +2731 ender.append(close); +2732 } +2733 } +2734 } +2735 i += vowelClusters.matcher(ender).findAll().count(); +2736 +2737 } +2738 +2739 for (; i < syllables; i++) { +2740 sb.append(rng.getRandomElement(midVowels)); +2741 if (rng.nextDouble() < vowelSplitFrequency) { +2742 sb.append(rng.getRandomElement(vowelSplitters)); +2743 sb.append(rng.getRandomElement(midVowels)); +2744 } +2745 sb.append(rng.getRandomElement(midConsonants)); +2746 } +2747 +2748 sb.append(ender); +2749 if (redouble && i <= syllables + 1) { +2750 sb.append(close.replaceAll("@", sb.toString())); +2751 } +2752 +2753 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2754 continue; +2755 +2756 for (Modifier mod : modifiers) { +2757 sb = mod.modify(rng, sb); +2758 } +2759 +2760 if (capitalize) +2761 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2762 +2763 if (clean && !checkAll(sb, vulgarChecks)) +2764 continue; +2765 return sb.toString(); +2766 } +2767 } +2768 +2769 /** +2770 * Generate a word from this FakeLanguageGen using the specified RNG. +2771 * +2772 * @param rng the RNG to use for the randomized string building +2773 * @param capitalize true if the word should start with a capital letter, false otherwise +2774 * @return a word in the fake language as a String +2775 */ +2776 public String word(RNG rng, boolean capitalize, int approxSyllables) { +2777 return word(rng, capitalize, approxSyllables, null); +2778 } +2779 +2780 /** +2781 * Generate a word from this FakeLanguageGen using the specified RNG. +2782 * +2783 * @param rng the RNG to use for the randomized string building +2784 * @param capitalize true if the word should start with a capital letter, false otherwise +2785 * @return a word in the fake language as a String +2786 */ +2787 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { +2788 if (approxSyllables <= 0) { +2789 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2790 for (Modifier mod : modifiers) { +2791 sb = mod.modify(rng, sb); +2792 } +2793 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2794 return sb.toString(); +2795 } +2796 while (true) { +2797 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2798 int i = 0; +2799 if (rng.nextDouble() < vowelStartFrequency) { +2800 sb.append(rng.getRandomElement(openingVowels)); +2801 if (approxSyllables == 1 && closingConsonants.length > 0) +2802 sb.append(rng.getRandomElement(closingConsonants)); +2803 else if (midConsonants.length > 0) +2804 sb.append(rng.getRandomElement(midConsonants)); +2805 i++; +2806 } else if (openingConsonants.length > 0) { +2807 sb.append(rng.getRandomElement(openingConsonants)); +2808 } +2809 String close = ""; +2810 boolean redouble = false; +2811 if (i < approxSyllables) { +2812 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { +2813 close = rng.getRandomElement(closingSyllables); +2814 if (close.contains("@") && (approxSyllables & 1) == 0) { +2815 redouble = true; +2816 approxSyllables = approxSyllables >> 1; +2817 +2818 //sb.append(close.replaceAll("@\\d", sb.toString())); +2819 } +2820 if (!close.contains("@")) +2821 ender.append(close); +2822 else if (redouble && rng.nextDouble() < vowelEndFrequency) { +2823 ender.append(rng.getRandomElement(midVowels)); +2824 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { +2825 ender.append(rng.getRandomElement(vowelSplitters)); +2826 ender.append(rng.getRandomElement(midVowels)); +2827 } +2828 } +2829 } else { +2830 ender.append(rng.getRandomElement(midVowels)); +2831 if (rng.nextDouble() < vowelSplitFrequency) { +2832 ender.append(rng.getRandomElement(vowelSplitters)); +2833 ender.append(rng.getRandomElement(midVowels)); +2834 } +2835 if (rng.nextDouble() >= vowelEndFrequency) { +2836 ender.append(rng.getRandomElement(closingConsonants)); +2837 if (rng.nextDouble() < syllableEndFrequency) { +2838 close = rng.getRandomElement(closingSyllables); +2839 if (close.contains("@") && (approxSyllables & 1) == 0) { +2840 redouble = true; +2841 approxSyllables = approxSyllables >> 1; +2842 +2843 //sb.append(close.replaceAll("@\\d", sb.toString())); +2844 } +2845 if (!close.contains("@")) +2846 ender.append(close); +2847 } +2848 } +2849 } +2850 i += vowelClusters.matcher(ender).findAll().count(); 2851 } -2852 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2853 return sb.toString(); -2854 } -2855 int numSeeds, fraction = 1; -2856 if (reseeds != null) -2857 numSeeds = Math.min(reseeds.length, approxSyllables - 1); -2858 else numSeeds = 0; -2859 while (true) { -2860 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2861 int i = 0; -2862 if (rng.nextDouble() < vowelStartFrequency) { -2863 sb.append(rng.getRandomElement(openingVowels)); -2864 if (approxSyllables == 1) -2865 sb.append(rng.getRandomElement(closingConsonants)); -2866 else -2867 sb.append(rng.getRandomElement(midConsonants)); -2868 i++; -2869 } else { -2870 sb.append(rng.getRandomElement(openingConsonants)); -2871 } -2872 String close = ""; -2873 boolean redouble = false; -2874 if (i < approxSyllables) { -2875 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2876 rng.setState(reseeds[fraction++ - 1]); -2877 if (rng.nextDouble() < syllableEndFrequency) { -2878 close = rng.getRandomElement(closingSyllables); -2879 if (close.contains("@") && (approxSyllables & 1) == 0) { -2880 redouble = true; -2881 approxSyllables = approxSyllables >> 1; -2882 } -2883 if (!close.contains("@")) -2884 ender.append(close); -2885 else if (rng.nextDouble() < vowelEndFrequency) { -2886 ender.append(rng.getRandomElement(midVowels)); -2887 if (rng.nextDouble() < vowelSplitFrequency) { -2888 ender.append(rng.getRandomElement(vowelSplitters)); -2889 ender.append(rng.getRandomElement(midVowels)); -2890 } -2891 } -2892 } else { -2893 ender.append(rng.getRandomElement(midVowels)); -2894 if (rng.nextDouble() < vowelSplitFrequency) { -2895 ender.append(rng.getRandomElement(vowelSplitters)); -2896 ender.append(rng.getRandomElement(midVowels)); -2897 } -2898 if (rng.nextDouble() >= vowelEndFrequency) { -2899 ender.append(rng.getRandomElement(closingConsonants)); -2900 if (rng.nextDouble() < syllableEndFrequency) { -2901 close = rng.getRandomElement(closingSyllables); -2902 if (close.contains("@") && (approxSyllables & 1) == 0) { -2903 redouble = true; -2904 approxSyllables = approxSyllables >> 1; -2905 -2906 //sb.append(close.replaceAll("@\\d", sb.toString())); -2907 } -2908 if (!close.contains("@")) -2909 ender.append(close); -2910 } -2911 } -2912 } -2913 i += vowelClusters.matcher(ender).findAll().count(); -2914 } -2915 -2916 for (; i < approxSyllables; i++) { -2917 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2918 rng.setState(reseeds[fraction++ - 1]); -2919 sb.append(rng.getRandomElement(midVowels)); -2920 if (rng.nextDouble() < vowelSplitFrequency) { -2921 sb.append(rng.getRandomElement(vowelSplitters)); -2922 sb.append(rng.getRandomElement(midVowels)); -2923 } -2924 sb.append(rng.getRandomElement(midConsonants)); -2925 } -2926 -2927 sb.append(ender); -2928 if (redouble && i <= approxSyllables + 1) { -2929 sb.append(close.replaceAll("@", sb.toString())); -2930 } -2931 -2932 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2933 continue; -2934 -2935 for (Modifier mod : modifiers) { -2936 sb = mod.modify(rng, sb); -2937 } -2938 -2939 if (capitalize) -2940 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2941 -2942 if (clean && !checkAll(sb, vulgarChecks)) -2943 continue; -2944 return sb.toString(); -2945 } -2946 } -2947 -2948 /** -2949 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2950 * -2951 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2952 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2953 * @return a sentence in the gibberish language as a String -2954 */ -2955 public String sentence(int minWords, int maxWords) { -2956 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2957 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2958 } -2959 -2960 /** -2961 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2962 * -2963 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2964 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2965 * @return a sentence in the gibberish language as a String -2966 */ -2967 public String sentence(RNG rng, int minWords, int maxWords) { -2968 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2969 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2970 } -2971 -2972 /** -2973 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2974 * -2975 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2976 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2977 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2978 * space in the middle of a sentence -2979 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2980 * the very end of a sentence -2981 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -2982 * midPunctuation should be inserted before spaces -2983 * @return a sentence in the gibberish language as a String -2984 */ -2985 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -2986 double midPunctuationFrequency) { -2987 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -2988 } +2852 +2853 for (; i < approxSyllables; i++) { +2854 sb.append(rng.getRandomElement(midVowels)); +2855 if (rng.nextDouble() < vowelSplitFrequency) { +2856 sb.append(rng.getRandomElement(vowelSplitters)); +2857 sb.append(rng.getRandomElement(midVowels)); +2858 } +2859 sb.append(rng.getRandomElement(midConsonants)); +2860 } +2861 +2862 sb.append(ender); +2863 if (redouble && i <= approxSyllables + 1) { +2864 sb.append(close.replaceAll("@", sb.toString())); +2865 } +2866 +2867 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2868 continue; +2869 +2870 for (Modifier mod : modifiers) { +2871 sb = mod.modify(rng, sb); +2872 } +2873 +2874 if (clean && !checkAll(sb, vulgarChecks)) +2875 continue; +2876 +2877 if (additionalChecks != null && !checkAll(sb, additionalChecks)) +2878 continue; +2879 +2880 if (capitalize) +2881 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2882 +2883 return sb.toString(); +2884 } +2885 } +2886 +2887 /** +2888 * Generate a word from this FakeLanguageGen using the specified RNG. +2889 * +2890 * @param rng the RNG to use for the randomized string building +2891 * @param capitalize true if the word should start with a capital letter, false otherwise +2892 * @return a word in the fake language as a String +2893 */ +2894 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { +2895 if (approxSyllables <= 0) { +2896 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2897 for (Modifier mod : modifiers) { +2898 sb = mod.modify(rng, sb); +2899 } +2900 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2901 return sb.toString(); +2902 } +2903 int numSeeds, fraction = 1; +2904 if (reseeds != null) +2905 numSeeds = Math.min(reseeds.length, approxSyllables - 1); +2906 else numSeeds = 0; +2907 while (true) { +2908 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2909 int i = 0; +2910 if (rng.nextDouble() < vowelStartFrequency) { +2911 sb.append(rng.getRandomElement(openingVowels)); +2912 if (approxSyllables == 1) +2913 sb.append(rng.getRandomElement(closingConsonants)); +2914 else +2915 sb.append(rng.getRandomElement(midConsonants)); +2916 i++; +2917 } else { +2918 sb.append(rng.getRandomElement(openingConsonants)); +2919 } +2920 String close = ""; +2921 boolean redouble = false; +2922 if (i < approxSyllables) { +2923 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2924 rng.setState(reseeds[fraction++ - 1]); +2925 if (rng.nextDouble() < syllableEndFrequency) { +2926 close = rng.getRandomElement(closingSyllables); +2927 if (close.contains("@") && (approxSyllables & 1) == 0) { +2928 redouble = true; +2929 approxSyllables = approxSyllables >> 1; +2930 } +2931 if (!close.contains("@")) +2932 ender.append(close); +2933 else if (rng.nextDouble() < vowelEndFrequency) { +2934 ender.append(rng.getRandomElement(midVowels)); +2935 if (rng.nextDouble() < vowelSplitFrequency) { +2936 ender.append(rng.getRandomElement(vowelSplitters)); +2937 ender.append(rng.getRandomElement(midVowels)); +2938 } +2939 } +2940 } else { +2941 ender.append(rng.getRandomElement(midVowels)); +2942 if (rng.nextDouble() < vowelSplitFrequency) { +2943 ender.append(rng.getRandomElement(vowelSplitters)); +2944 ender.append(rng.getRandomElement(midVowels)); +2945 } +2946 if (rng.nextDouble() >= vowelEndFrequency) { +2947 ender.append(rng.getRandomElement(closingConsonants)); +2948 if (rng.nextDouble() < syllableEndFrequency) { +2949 close = rng.getRandomElement(closingSyllables); +2950 if (close.contains("@") && (approxSyllables & 1) == 0) { +2951 redouble = true; +2952 approxSyllables = approxSyllables >> 1; +2953 +2954 //sb.append(close.replaceAll("@\\d", sb.toString())); +2955 } +2956 if (!close.contains("@")) +2957 ender.append(close); +2958 } +2959 } +2960 } +2961 i += vowelClusters.matcher(ender).findAll().count(); +2962 } +2963 +2964 for (; i < approxSyllables; i++) { +2965 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2966 rng.setState(reseeds[fraction++ - 1]); +2967 sb.append(rng.getRandomElement(midVowels)); +2968 if (rng.nextDouble() < vowelSplitFrequency) { +2969 sb.append(rng.getRandomElement(vowelSplitters)); +2970 sb.append(rng.getRandomElement(midVowels)); +2971 } +2972 sb.append(rng.getRandomElement(midConsonants)); +2973 } +2974 +2975 sb.append(ender); +2976 if (redouble && i <= approxSyllables + 1) { +2977 sb.append(close.replaceAll("@", sb.toString())); +2978 } +2979 +2980 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2981 continue; +2982 +2983 for (Modifier mod : modifiers) { +2984 sb = mod.modify(rng, sb); +2985 } +2986 +2987 if (capitalize) +2988 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); 2989 -2990 /** -2991 * Generate a sentence from this FakeLanguageGen using the specific RNG. -2992 * -2993 * @param rng the RNG to use for the randomized string building -2994 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2995 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2996 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2997 * space in the middle of a sentence -2998 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2999 * the very end of a sentence -3000 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3001 * midPunctuation should be inserted before spaces -3002 * @return a sentence in the gibberish language as a String -3003 */ -3004 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3005 double midPunctuationFrequency) { -3006 if (minWords < 1) -3007 minWords = 1; -3008 if (minWords > maxWords) -3009 maxWords = minWords; -3010 if (midPunctuationFrequency > 1.0) { -3011 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3012 } -3013 StringBuilder sb = new StringBuilder(12 * maxWords); -3014 sb.append(word(rng, true)); -3015 for (int i = 1; i < minWords; i++) { -3016 if (rng.nextDouble() < midPunctuationFrequency) { -3017 sb.append(rng.getRandomElement(midPunctuation)); -3018 } -3019 sb.append(' '); -3020 sb.append(word(rng, false)); -3021 } -3022 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { -3023 if (rng.nextDouble() < midPunctuationFrequency) { -3024 sb.append(rng.getRandomElement(midPunctuation)); -3025 } -3026 sb.append(' '); -3027 sb.append(word(rng, false)); -3028 } -3029 if (endPunctuation != null && endPunctuation.length > 0) -3030 sb.append(rng.getRandomElement(endPunctuation)); -3031 return sb.toString(); -3032 } -3033 -3034 /** -3035 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. -3036 * -3037 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3038 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3039 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3040 * space in the middle of a sentence -3041 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3042 * the very end of a sentence -3043 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3044 * midPunctuation should be inserted before spaces -3045 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3046 * @return a sentence in the gibberish language as a String -3047 */ -3048 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3049 double midPunctuationFrequency, int maxChars) { -3050 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); -3051 } -3052 -3053 /** -3054 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. -3055 * -3056 * @param rng the RNG to use for the randomized string building -3057 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3058 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3059 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3060 * space in the middle of a sentence -3061 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3062 * the very end of a sentence -3063 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3064 * midPunctuation should be inserted before spaces -3065 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3066 * @return a sentence in the gibberish language as a String -3067 */ -3068 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3069 double midPunctuationFrequency, int maxChars) { -3070 if(maxChars < 0) -3071 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -3072 if (minWords < 1) -3073 minWords = 1; -3074 if (minWords > maxWords) -3075 maxWords = minWords; -3076 if (midPunctuationFrequency > 1.0) { -3077 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3078 } -3079 if (maxChars < 4) -3080 return "!"; -3081 if (maxChars <= 5 * minWords) { -3082 minWords = 1; -3083 maxWords = 1; -3084 } -3085 int frustration = 0; -3086 StringBuilder sb = new StringBuilder(maxChars); -3087 String next = word(rng, true); -3088 while (next.length() >= maxChars - 1 && frustration < 50) { -3089 next = word(rng, true); -3090 frustration++; -3091 } -3092 if (frustration >= 50) return "!"; -3093 sb.append(next); -3094 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { -3095 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3096 sb.append(rng.getRandomElement(midPunctuation)); -3097 } -3098 next = word(rng, false); -3099 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3100 next = word(rng, false); -3101 frustration++; -3102 } -3103 if (frustration >= 50) break; -3104 sb.append(' '); -3105 sb.append(next); -3106 } -3107 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { -3108 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3109 sb.append(rng.getRandomElement(midPunctuation)); -3110 } -3111 next = word(rng, false); -3112 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3113 next = word(rng, false); -3114 frustration++; -3115 } -3116 if (frustration >= 50) break; -3117 sb.append(' '); -3118 sb.append(next); -3119 } -3120 -3121 if (endPunctuation != null && endPunctuation.length > 0) { -3122 -3123 next = rng.getRandomElement(endPunctuation); -3124 if (sb.length() + next.length() >= maxChars) -3125 sb.append('.'); -3126 else -3127 sb.append(next); -3128 } -3129 -3130 if (sb.length() > maxChars) -3131 return "!"; -3132 return sb.toString(); -3133 } -3134 -3135 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { -3136 if (other.length <= 0 && me.length <= 0) -3137 return new String[]{}; -3138 String[] ret = new String[1000]; -3139 int otherCount = (int) (1000 * otherInfluence); -3140 int idx = 0; -3141 if (other.length > 0) { -3142 String[] tmp = new String[other.length]; -3143 rng.shuffle(other, tmp); -3144 for (idx = 0; idx < otherCount; idx++) { -3145 ret[idx] = tmp[idx % tmp.length]; -3146 } -3147 } -3148 if (me.length > 0) { -3149 String[] tmp = new String[me.length]; -3150 rng.shuffle(me, tmp); -3151 for (; idx < 1000; idx++) { -3152 ret[idx] = tmp[idx % tmp.length]; -3153 } -3154 } else { -3155 for (; idx < 1000; idx++) { -3156 ret[idx] = other[idx % other.length]; -3157 } -3158 } -3159 return ret; -3160 } -3161 -3162 -3163 protected String[] accentVowels(RNG rng, String[] me, double influence) { -3164 String[] ret = new String[1000]; -3165 int otherCount = (int) (1000 * influence); -3166 int idx = 0; -3167 Matcher matcher; -3168 if (me.length > 0) { -3169 String[] tmp = new String[me.length]; -3170 rng.shuffle(me, tmp); -3171 for (idx = 0; idx < otherCount; idx++) { -3172 ret[idx] = tmp[idx % tmp.length] -3173 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3174 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3175 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3176 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3177 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3178 matcher = repeats.matcher(ret[idx]); -3179 if (matcher.find()) { -3180 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3181 } -3182 } -3183 for (; idx < 1000; idx++) { -3184 ret[idx] = tmp[idx % tmp.length]; -3185 } -3186 } else -3187 return new String[]{}; -3188 return ret; -3189 } -3190 -3191 protected String[] accentConsonants(RNG rng, String[] me, double influence) { -3192 String[] ret = new String[1000]; -3193 int otherCount = (int) (1000 * influence); -3194 int idx = 0; -3195 Matcher matcher; +2990 if (clean && !checkAll(sb, vulgarChecks)) +2991 continue; +2992 return sb.toString(); +2993 } +2994 } +2995 +2996 /** +2997 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +2998 * +2999 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3000 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3001 * @return a sentence in the gibberish language as a String +3002 */ +3003 public String sentence(int minWords, int maxWords) { +3004 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3005 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3006 } +3007 +3008 /** +3009 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3010 * +3011 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3012 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3013 * @return a sentence in the gibberish language as a String +3014 */ +3015 public String sentence(RNG rng, int minWords, int maxWords) { +3016 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3017 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3018 } +3019 +3020 /** +3021 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3022 * +3023 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3024 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3025 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3026 * space in the middle of a sentence +3027 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3028 * the very end of a sentence +3029 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3030 * midPunctuation should be inserted before spaces +3031 * @return a sentence in the gibberish language as a String +3032 */ +3033 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3034 double midPunctuationFrequency) { +3035 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3036 } +3037 +3038 /** +3039 * Generate a sentence from this FakeLanguageGen using the specific RNG. +3040 * +3041 * @param rng the RNG to use for the randomized string building +3042 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3043 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3044 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3045 * space in the middle of a sentence +3046 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3047 * the very end of a sentence +3048 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3049 * midPunctuation should be inserted before spaces +3050 * @return a sentence in the gibberish language as a String +3051 */ +3052 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3053 double midPunctuationFrequency) { +3054 if (minWords < 1) +3055 minWords = 1; +3056 if (minWords > maxWords) +3057 maxWords = minWords; +3058 if (midPunctuationFrequency > 1.0) { +3059 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3060 } +3061 StringBuilder sb = new StringBuilder(12 * maxWords); +3062 sb.append(word(rng, true)); +3063 for (int i = 1; i < minWords; i++) { +3064 if (rng.nextDouble() < midPunctuationFrequency) { +3065 sb.append(rng.getRandomElement(midPunctuation)); +3066 } +3067 sb.append(' '); +3068 sb.append(word(rng, false)); +3069 } +3070 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { +3071 if (rng.nextDouble() < midPunctuationFrequency) { +3072 sb.append(rng.getRandomElement(midPunctuation)); +3073 } +3074 sb.append(' '); +3075 sb.append(word(rng, false)); +3076 } +3077 if (endPunctuation != null && endPunctuation.length > 0) +3078 sb.append(rng.getRandomElement(endPunctuation)); +3079 return sb.toString(); +3080 } +3081 +3082 /** +3083 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. +3084 * +3085 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3086 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3087 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3088 * space in the middle of a sentence +3089 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3090 * the very end of a sentence +3091 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3092 * midPunctuation should be inserted before spaces +3093 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3094 * @return a sentence in the gibberish language as a String +3095 */ +3096 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3097 double midPunctuationFrequency, int maxChars) { +3098 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); +3099 } +3100 +3101 /** +3102 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. +3103 * +3104 * @param rng the RNG to use for the randomized string building +3105 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3106 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3107 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3108 * space in the middle of a sentence +3109 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3110 * the very end of a sentence +3111 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3112 * midPunctuation should be inserted before spaces +3113 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3114 * @return a sentence in the gibberish language as a String +3115 */ +3116 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3117 double midPunctuationFrequency, int maxChars) { +3118 if(maxChars < 0) +3119 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3120 if (minWords < 1) +3121 minWords = 1; +3122 if (minWords > maxWords) +3123 maxWords = minWords; +3124 if (midPunctuationFrequency > 1.0) { +3125 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3126 } +3127 if (maxChars < 4) +3128 return "!"; +3129 if (maxChars <= 5 * minWords) { +3130 minWords = 1; +3131 maxWords = 1; +3132 } +3133 int frustration = 0; +3134 StringBuilder sb = new StringBuilder(maxChars); +3135 String next = word(rng, true); +3136 while (next.length() >= maxChars - 1 && frustration < 50) { +3137 next = word(rng, true); +3138 frustration++; +3139 } +3140 if (frustration >= 50) return "!"; +3141 sb.append(next); +3142 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { +3143 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3144 sb.append(rng.getRandomElement(midPunctuation)); +3145 } +3146 next = word(rng, false); +3147 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3148 next = word(rng, false); +3149 frustration++; +3150 } +3151 if (frustration >= 50) break; +3152 sb.append(' '); +3153 sb.append(next); +3154 } +3155 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { +3156 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3157 sb.append(rng.getRandomElement(midPunctuation)); +3158 } +3159 next = word(rng, false); +3160 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3161 next = word(rng, false); +3162 frustration++; +3163 } +3164 if (frustration >= 50) break; +3165 sb.append(' '); +3166 sb.append(next); +3167 } +3168 +3169 if (endPunctuation != null && endPunctuation.length > 0) { +3170 +3171 next = rng.getRandomElement(endPunctuation); +3172 if (sb.length() + next.length() >= maxChars) +3173 sb.append('.'); +3174 else +3175 sb.append(next); +3176 } +3177 +3178 if (sb.length() > maxChars) +3179 return "!"; +3180 return sb.toString(); +3181 } +3182 +3183 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { +3184 if (other.length <= 0 && me.length <= 0) +3185 return new String[]{}; +3186 String[] ret = new String[1000]; +3187 int otherCount = (int) (1000 * otherInfluence); +3188 int idx = 0; +3189 if (other.length > 0) { +3190 String[] tmp = new String[other.length]; +3191 rng.shuffle(other, tmp); +3192 for (idx = 0; idx < otherCount; idx++) { +3193 ret[idx] = tmp[idx % tmp.length]; +3194 } +3195 } 3196 if (me.length > 0) { 3197 String[] tmp = new String[me.length]; 3198 rng.shuffle(me, tmp); -3199 for (idx = 0; idx < otherCount; idx++) { -3200 ret[idx] = tmp[idx % tmp.length] -3201 //0 -3202 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3203 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3204 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3205 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3206 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3207 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3208 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3209 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3210 //9 -3211 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3212 //11 -3213 //12 -3214 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3215 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3216 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3217 //16 -3218 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3219 //18 -3220 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3221 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3222 -3223 matcher = repeats.matcher(ret[idx]); -3224 if (matcher.find()) { -3225 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3226 } -3227 } -3228 for (; idx < 1000; idx++) { -3229 ret[idx] = tmp[idx % tmp.length]; +3199 for (; idx < 1000; idx++) { +3200 ret[idx] = tmp[idx % tmp.length]; +3201 } +3202 } else { +3203 for (; idx < 1000; idx++) { +3204 ret[idx] = other[idx % other.length]; +3205 } +3206 } +3207 return ret; +3208 } +3209 +3210 +3211 protected String[] accentVowels(RNG rng, String[] me, double influence) { +3212 String[] ret = new String[1000]; +3213 int otherCount = (int) (1000 * influence); +3214 int idx = 0; +3215 Matcher matcher; +3216 if (me.length > 0) { +3217 String[] tmp = new String[me.length]; +3218 rng.shuffle(me, tmp); +3219 for (idx = 0; idx < otherCount; idx++) { +3220 ret[idx] = tmp[idx % tmp.length] +3221 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3222 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3223 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3224 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3225 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3226 matcher = repeats.matcher(ret[idx]); +3227 if (matcher.find()) { +3228 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3229 } 3230 } -3231 } else -3232 return new String[]{}; -3233 return ret; -3234 } -3235 -3236 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { -3237 String[] ret = new String[1000]; -3238 int idx = 0; -3239 Matcher matcher; -3240 if (me.length > 0) { -3241 String[] tmp = new String[me.length]; -3242 rng.shuffle(me, tmp); -3243 for (idx = 0; idx < 1000; idx++) { -3244 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; -3245 if (subVowel && subCon) { -3246 ret[idx] = tmp[idx % tmp.length] -3247 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3248 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3249 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3250 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3251 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) -3252 -3253 //0 -3254 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3255 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3256 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3257 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3258 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3259 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3260 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3261 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3262 //9 -3263 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3264 //11 -3265 //12 -3266 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3267 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3268 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3269 //16 -3270 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3271 //18 -3272 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3273 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3274 -3275 matcher = repeats.matcher(ret[idx]); -3276 if (matcher.find()) { -3277 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3278 } -3279 } else if (subVowel) { -3280 ret[idx] = tmp[idx % tmp.length] -3281 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3282 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3283 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3284 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3285 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3286 -3287 matcher = repeats.matcher(ret[idx]); -3288 if (matcher.find()) { -3289 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3290 } -3291 } else if (subCon) { -3292 ret[idx] = tmp[idx % tmp.length] -3293 //0 -3294 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3295 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3296 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3297 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3298 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3299 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3300 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3301 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3302 //9 -3303 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3304 //11 -3305 //12 -3306 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3307 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3308 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3309 //16 -3310 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3311 //18 -3312 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3313 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3314 -3315 matcher = repeats.matcher(ret[idx]); -3316 if (matcher.find()) { -3317 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3318 } -3319 } else ret[idx] = tmp[idx % tmp.length]; -3320 -3321 } -3322 } else -3323 return new String[]{}; -3324 return ret; -3325 } -3326 -3327 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { -3328 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); -3329 double myInfluence = 1.0 - otherInfluence; -3330 -3331 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) -3332 ^ NumberTools.doubleToLongBits(otherInfluence)); -3333 -3334 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), -3335 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), -3336 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * -3337 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), -3338 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), -3339 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * -3340 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), -3341 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * -3342 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), -3343 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); -3344 -3345 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); -3346 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { -3347 if (freqs.containsKey(kv.getIntKey())) -3348 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); -3349 else -3350 freqs.put(kv.getIntKey(), kv.getDoubleValue()); -3351 } -3352 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); -3353 mods.addAll(modifiers); -3354 mods.addAll(other.modifiers); -3355 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, -3356 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, -3357 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, -3358 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, -3359 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, -3360 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); -3361 } +3231 for (; idx < 1000; idx++) { +3232 ret[idx] = tmp[idx % tmp.length]; +3233 } +3234 } else +3235 return new String[]{}; +3236 return ret; +3237 } +3238 +3239 protected String[] accentConsonants(RNG rng, String[] me, double influence) { +3240 String[] ret = new String[1000]; +3241 int otherCount = (int) (1000 * influence); +3242 int idx = 0; +3243 Matcher matcher; +3244 if (me.length > 0) { +3245 String[] tmp = new String[me.length]; +3246 rng.shuffle(me, tmp); +3247 for (idx = 0; idx < otherCount; idx++) { +3248 ret[idx] = tmp[idx % tmp.length] +3249 //0 +3250 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3251 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3252 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3253 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3254 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3255 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3256 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3257 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3258 //9 +3259 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3260 //11 +3261 //12 +3262 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3263 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3264 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3265 //16 +3266 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3267 //18 +3268 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3269 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3270 +3271 matcher = repeats.matcher(ret[idx]); +3272 if (matcher.find()) { +3273 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3274 } +3275 } +3276 for (; idx < 1000; idx++) { +3277 ret[idx] = tmp[idx % tmp.length]; +3278 } +3279 } else +3280 return new String[]{}; +3281 return ret; +3282 } +3283 +3284 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { +3285 String[] ret = new String[1000]; +3286 int idx = 0; +3287 Matcher matcher; +3288 if (me.length > 0) { +3289 String[] tmp = new String[me.length]; +3290 rng.shuffle(me, tmp); +3291 for (idx = 0; idx < 1000; idx++) { +3292 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; +3293 if (subVowel && subCon) { +3294 ret[idx] = tmp[idx % tmp.length] +3295 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3296 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3297 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3298 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3299 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) +3300 +3301 //0 +3302 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3303 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3304 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3305 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3306 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3307 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3308 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3309 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3310 //9 +3311 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3312 //11 +3313 //12 +3314 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3315 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3316 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3317 //16 +3318 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3319 //18 +3320 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3321 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3322 +3323 matcher = repeats.matcher(ret[idx]); +3324 if (matcher.find()) { +3325 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3326 } +3327 } else if (subVowel) { +3328 ret[idx] = tmp[idx % tmp.length] +3329 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3330 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3331 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3332 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3333 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3334 +3335 matcher = repeats.matcher(ret[idx]); +3336 if (matcher.find()) { +3337 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3338 } +3339 } else if (subCon) { +3340 ret[idx] = tmp[idx % tmp.length] +3341 //0 +3342 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3343 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3344 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3345 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3346 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3347 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3348 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3349 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3350 //9 +3351 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3352 //11 +3353 //12 +3354 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3355 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3356 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3357 //16 +3358 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3359 //18 +3360 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3361 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); 3362 -3363 private static double readDouble(Object o) { -3364 if (o instanceof Double) return (Double) o; -3365 else if (o instanceof Float) return (Float) o; -3366 else if (o instanceof Long) return ((Long) o).doubleValue(); -3367 else if (o instanceof Integer) return (Integer) o; -3368 else if (o instanceof Short) return (Short) o; -3369 else if (o instanceof Byte) return (Byte) o; -3370 else if (o instanceof Character) return (Character) o; -3371 return 0.0; -3372 } -3373 -3374 /** -3375 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes -3376 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of -3377 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a -3378 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this -3379 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. -3380 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type -3381 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some -3382 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and -3383 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern -3384 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on -3385 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3386 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3387 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3388 * with 0.33 . -3389 * <br> -3390 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the -3391 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for -3392 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 -3393 * the bytes used in one not-quite-simple test). -3394 * -3395 * @param myWeight the weight to assign this FakeLanguageGen in the mix -3396 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} -3397 * @param weight1 the weight to assign other1 in the mix -3398 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements -3399 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights -3400 */ -3401 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { -3402 if (other1 == null || pairs == null) -3403 return copy(); -3404 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); -3405 FakeLanguageGen mixer = removeModifiers(); -3406 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; -3407 double[] weights = new double[languages.length]; -3408 String[] summaries = new String[languages.length]; -3409 boolean summarize = true; -3410 double total = 0.0, current, weight; -3411 languages[0] = mixer; -3412 total += weights[0] = myWeight; -3413 if ((summaries[0] = mixer.summary) == null) summarize = false; -3414 mods.addAll(other1.modifiers); -3415 languages[1] = other1.removeModifiers(); -3416 total += weights[1] = weight1; -3417 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; -3418 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { -3419 if (pairs[i] == null || pairs[i - 1] == null) -3420 continue; -3421 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); -3422 total += weights[p] = readDouble(pairs[i]); -3423 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; -3424 } -3425 if (total == 0) -3426 return copy(); -3427 current = myWeight / total; -3428 for (int i = 1; i < languages.length; i++) { -3429 if ((weight = weights[i]) > 0) -3430 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); -3431 } -3432 if (summarize) { -3433 StringBuilder brief = new StringBuilder(64); -3434 String c; -3435 int idx; -3436 for (int i = 0; i < summaries.length; i++) { -3437 c = summaries[i]; -3438 idx = c.indexOf('@'); -3439 if (idx >= 0) { -3440 brief.append(c.substring(0, idx + 1)).append(weights[i]); -3441 if (i < summaries.length - 1) -3442 brief.append('~'); -3443 } -3444 } -3445 for (int i = 0; i < mods.size(); i++) { -3446 brief.append('℗').append(mods.getAt(i).serializeToString()); -3447 } -3448 return mixer.addModifiers(mods).summarize(brief.toString()); -3449 } else -3450 return mixer.addModifiers(mods); -3451 } -3452 -3453 /** -3454 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. -3455 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the -3456 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double -3457 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then -3458 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them -3459 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one -3460 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on -3461 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3462 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3463 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3464 * with 0.33 . -3465 * <br> -3466 * Not intended for external use, but it could be useful. Used internally in the deserialization code. -3467 * -3468 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements -3469 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights -3470 */ -3471 public static FakeLanguageGen mixAll(Object... pairs) { -3472 int len; -3473 if (pairs == null || (len = pairs.length) <= 0) -3474 return ENGLISH.copy(); -3475 if (len < 4) -3476 return ((FakeLanguageGen) pairs[0]).copy(); -3477 Object[] pairs2 = new Object[len - 4]; -3478 if (len > 4) -3479 System.arraycopy(pairs, 4, pairs2, 0, len - 4); -3480 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); -3481 } -3482 -3483 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { -3484 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); -3485 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); -3486 -3487 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ -3488 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); -3489 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), -3490 mv = accentVowels(rng, midVowels, vowelInfluence), -3491 oc = accentConsonants(rng, openingConsonants, consonantInfluence), -3492 mc = accentConsonants(rng, midConsonants, consonantInfluence), -3493 cc = accentConsonants(rng, closingConsonants, consonantInfluence), -3494 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); -3495 -3496 -3497 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3498 vowelStartFrequency, -3499 vowelEndFrequency, -3500 vowelSplitFrequency, -3501 syllableEndFrequency, sanityChecks, clean, modifiers); -3502 } -3503 -3504 static String[] copyStrings(String[] start) { -3505 String[] next = new String[start.length]; -3506 System.arraycopy(start, 0, next, 0, start.length); -3507 return next; -3508 } -3509 -3510 public FakeLanguageGen removeAccents() { -3511 -3512 String[] ov = copyStrings(openingVowels), -3513 mv = copyStrings(midVowels), -3514 oc = copyStrings(openingConsonants), -3515 mc = copyStrings(midConsonants), -3516 cc = copyStrings(closingConsonants), -3517 cs = copyStrings(closingSyllables); -3518 for (int i = 0; i < ov.length; i++) { -3519 ov[i] = removeAccents(openingVowels[i]).toString(); -3520 } -3521 for (int i = 0; i < mv.length; i++) { -3522 mv[i] = removeAccents(midVowels[i]).toString(); -3523 } -3524 for (int i = 0; i < oc.length; i++) { -3525 oc[i] = removeAccents(openingConsonants[i]).toString(); -3526 } -3527 for (int i = 0; i < mc.length; i++) { -3528 mc[i] = removeAccents(midConsonants[i]).toString(); -3529 } -3530 for (int i = 0; i < cc.length; i++) { -3531 cc[i] = removeAccents(closingConsonants[i]).toString(); -3532 } -3533 for (int i = 0; i < cs.length; i++) { -3534 cs[i] = removeAccents(closingSyllables[i]).toString(); -3535 } -3536 -3537 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3538 vowelStartFrequency, -3539 vowelEndFrequency, -3540 vowelSplitFrequency, -3541 syllableEndFrequency, sanityChecks, clean, modifiers); -3542 } +3363 matcher = repeats.matcher(ret[idx]); +3364 if (matcher.find()) { +3365 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3366 } +3367 } else ret[idx] = tmp[idx % tmp.length]; +3368 +3369 } +3370 } else +3371 return new String[]{}; +3372 return ret; +3373 } +3374 +3375 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { +3376 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); +3377 double myInfluence = 1.0 - otherInfluence; +3378 +3379 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) +3380 ^ NumberTools.doubleToLongBits(otherInfluence)); +3381 +3382 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), +3383 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), +3384 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * +3385 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), +3386 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), +3387 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * +3388 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), +3389 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * +3390 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), +3391 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); +3392 +3393 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); +3394 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { +3395 if (freqs.containsKey(kv.getIntKey())) +3396 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); +3397 else +3398 freqs.put(kv.getIntKey(), kv.getDoubleValue()); +3399 } +3400 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); +3401 mods.addAll(modifiers); +3402 mods.addAll(other.modifiers); +3403 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, +3404 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, +3405 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, +3406 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, +3407 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, +3408 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); +3409 } +3410 +3411 private static double readDouble(Object o) { +3412 if (o instanceof Double) return (Double) o; +3413 else if (o instanceof Float) return (Float) o; +3414 else if (o instanceof Long) return ((Long) o).doubleValue(); +3415 else if (o instanceof Integer) return (Integer) o; +3416 else if (o instanceof Short) return (Short) o; +3417 else if (o instanceof Byte) return (Byte) o; +3418 else if (o instanceof Character) return (Character) o; +3419 return 0.0; +3420 } +3421 +3422 /** +3423 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes +3424 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of +3425 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a +3426 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this +3427 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. +3428 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type +3429 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some +3430 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and +3431 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern +3432 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on +3433 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3434 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3435 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3436 * with 0.33 . +3437 * <br> +3438 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the +3439 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for +3440 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 +3441 * the bytes used in one not-quite-simple test). +3442 * +3443 * @param myWeight the weight to assign this FakeLanguageGen in the mix +3444 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} +3445 * @param weight1 the weight to assign other1 in the mix +3446 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements +3447 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights +3448 */ +3449 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { +3450 if (other1 == null || pairs == null) +3451 return copy(); +3452 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); +3453 FakeLanguageGen mixer = removeModifiers(); +3454 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; +3455 double[] weights = new double[languages.length]; +3456 String[] summaries = new String[languages.length]; +3457 boolean summarize = true; +3458 double total = 0.0, current, weight; +3459 languages[0] = mixer; +3460 total += weights[0] = myWeight; +3461 if ((summaries[0] = mixer.summary) == null) summarize = false; +3462 mods.addAll(other1.modifiers); +3463 languages[1] = other1.removeModifiers(); +3464 total += weights[1] = weight1; +3465 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; +3466 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { +3467 if (pairs[i] == null || pairs[i - 1] == null) +3468 continue; +3469 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); +3470 total += weights[p] = readDouble(pairs[i]); +3471 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; +3472 } +3473 if (total == 0) +3474 return copy(); +3475 current = myWeight / total; +3476 for (int i = 1; i < languages.length; i++) { +3477 if ((weight = weights[i]) > 0) +3478 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); +3479 } +3480 if (summarize) { +3481 StringBuilder brief = new StringBuilder(64); +3482 String c; +3483 int idx; +3484 for (int i = 0; i < summaries.length; i++) { +3485 c = summaries[i]; +3486 idx = c.indexOf('@'); +3487 if (idx >= 0) { +3488 brief.append(c.substring(0, idx + 1)).append(weights[i]); +3489 if (i < summaries.length - 1) +3490 brief.append('~'); +3491 } +3492 } +3493 for (int i = 0; i < mods.size(); i++) { +3494 brief.append('℗').append(mods.getAt(i).serializeToString()); +3495 } +3496 return mixer.addModifiers(mods).summarize(brief.toString()); +3497 } else +3498 return mixer.addModifiers(mods); +3499 } +3500 +3501 /** +3502 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. +3503 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the +3504 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double +3505 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then +3506 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them +3507 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one +3508 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on +3509 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3510 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3511 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3512 * with 0.33 . +3513 * <br> +3514 * Not intended for external use, but it could be useful. Used internally in the deserialization code. +3515 * +3516 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements +3517 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights +3518 */ +3519 public static FakeLanguageGen mixAll(Object... pairs) { +3520 int len; +3521 if (pairs == null || (len = pairs.length) <= 0) +3522 return ENGLISH.copy(); +3523 if (len < 4) +3524 return ((FakeLanguageGen) pairs[0]).copy(); +3525 Object[] pairs2 = new Object[len - 4]; +3526 if (len > 4) +3527 System.arraycopy(pairs, 4, pairs2, 0, len - 4); +3528 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); +3529 } +3530 +3531 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { +3532 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); +3533 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); +3534 +3535 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ +3536 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); +3537 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), +3538 mv = accentVowels(rng, midVowels, vowelInfluence), +3539 oc = accentConsonants(rng, openingConsonants, consonantInfluence), +3540 mc = accentConsonants(rng, midConsonants, consonantInfluence), +3541 cc = accentConsonants(rng, closingConsonants, consonantInfluence), +3542 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); 3543 -3544 /** -3545 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. -3546 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3547 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3548 * -3549 * @param mods an array or vararg of Modifier objects -3550 * @return a copy of this with the Modifiers added -3551 */ -3552 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { -3553 FakeLanguageGen next = copy(); -3554 next.modifiers.addAll(mods); +3544 +3545 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3546 vowelStartFrequency, +3547 vowelEndFrequency, +3548 vowelSplitFrequency, +3549 syllableEndFrequency, sanityChecks, clean, modifiers); +3550 } +3551 +3552 static String[] copyStrings(String[] start) { +3553 String[] next = new String[start.length]; +3554 System.arraycopy(start, 0, next, 0, start.length); 3555 return next; 3556 } 3557 -3558 /** -3559 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. -3560 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3561 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3562 * -3563 * @param mods an array or vararg of Modifier objects -3564 * @return a copy of this with the Modifiers added -3565 */ -3566 public FakeLanguageGen addModifiers(Modifier... mods) { -3567 FakeLanguageGen next = copy(); -3568 Collections.addAll(next.modifiers, mods); -3569 return next; -3570 } -3571 -3572 /** -3573 * Creates a copy of this FakeLanguageGen with no modifiers. -3574 * -3575 * @return a copy of this FakeLanguageGen with modifiers removed. -3576 */ -3577 public FakeLanguageGen removeModifiers() { -3578 FakeLanguageGen next = copy(); -3579 next.modifiers.clear(); -3580 return next; -3581 } -3582 -3583 public static Modifier modifier(String pattern, String replacement) { -3584 return new Modifier(pattern, replacement); -3585 } -3586 -3587 public static Modifier modifier(String pattern, String replacement, double chance) { -3588 return new Modifier(pattern, replacement, chance); -3589 } -3590 -3591 @Override -3592 public boolean equals(Object o) { -3593 if (this == o) return true; -3594 if (o == null || getClass() != o.getClass()) return false; -3595 -3596 FakeLanguageGen that = (FakeLanguageGen) o; -3597 -3598 if (clean != that.clean) return false; -3599 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; -3600 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; -3601 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; -3602 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; -3603 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; -3604 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3605 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; -3606 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3607 if (!Arrays.equals(midVowels, that.midVowels)) return false; -3608 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3609 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; -3610 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3611 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; -3612 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3613 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; -3614 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3615 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; -3616 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3617 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; -3618 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; -3619 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3620 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; -3621 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; -3622 } -3623 -3624 @Override -3625 public int hashCode() { -3626 int result; -3627 long temp; -3628 result = CrossHash.Lightning.hash(openingVowels); -3629 result = 31 * result + CrossHash.Lightning.hash(midVowels); -3630 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); -3631 result = 31 * result + CrossHash.Lightning.hash(midConsonants); -3632 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); -3633 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); -3634 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); -3635 result = 31 * result + (clean ? 1 : 0); -3636 result = 31 * result + syllableFrequencies.hashCode(); -3637 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); -3638 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3639 temp = NumberTools.doubleToLongBits(vowelStartFrequency); -3640 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3641 temp = NumberTools.doubleToLongBits(vowelEndFrequency); -3642 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3643 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); -3644 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3645 temp = NumberTools.doubleToLongBits(syllableEndFrequency); -3646 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3647 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); -3648 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); -3649 return result; -3650 } -3651 -3652 @Override -3653 public String toString() { -3654 return "FakeLanguageGen{" + -3655 "openingVowels=" + Arrays.toString(openingVowels) + -3656 ", midVowels=" + Arrays.toString(midVowels) + -3657 ", openingConsonants=" + Arrays.toString(openingConsonants) + -3658 ", midConsonants=" + Arrays.toString(midConsonants) + -3659 ", closingConsonants=" + Arrays.toString(closingConsonants) + -3660 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + -3661 ", closingSyllables=" + Arrays.toString(closingSyllables) + -3662 ", clean=" + clean + -3663 ", syllableFrequencies=" + syllableFrequencies + -3664 ", totalSyllableFrequency=" + totalSyllableFrequency + -3665 ", vowelStartFrequency=" + vowelStartFrequency + -3666 ", vowelEndFrequency=" + vowelEndFrequency + -3667 ", vowelSplitFrequency=" + vowelSplitFrequency + -3668 ", syllableEndFrequency=" + syllableEndFrequency + -3669 ", sanityChecks=" + Arrays.toString(sanityChecks) + -3670 ", modifiers=" + modifiers + -3671 '}'; -3672 } -3673 -3674 public FakeLanguageGen copy() { -3675 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, -3676 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, -3677 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) -3678 .summarize(summary); -3679 } -3680 -3681 -3682 public String serializeToString() { -3683 return (summary == null) ? "" : summary; -3684 } -3685 -3686 public static FakeLanguageGen deserializeFromString(String data) { -3687 if (data == null || data.equals("")) -3688 return ENGLISH.copy(); -3689 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), -3690 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, -3691 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; -3692 if (tildeIndex < 0) -3693 tildeIndex = data.length(); -3694 -3695 if (snailIndex < 0) -3696 return ENGLISH.copy(); -3697 ArrayList<Object> pairs = new ArrayList<>(4); -3698 while (snailIndex >= 0) { -3699 if (poundIndex >= 0 && poundIndex < snailIndex) // random case -3700 { -3701 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); -3702 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3703 poundIndex = -1; -3704 } else { -3705 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); -3706 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3707 } -3708 snailIndex = data.indexOf('@', snailIndex + 1); -3709 if (snailIndex > breakIndex) -3710 break; -3711 prevTildeIndex = tildeIndex; -3712 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); -3713 if (tildeIndex < 0) -3714 tildeIndex = data.length(); -3715 } -3716 ArrayList<Modifier> mods = new ArrayList<>(8); -3717 if (breakIndex == tempBreak) { -3718 tildeIndex = breakIndex - 1; -3719 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { -3720 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); -3721 if (tildeIndex < 0) tildeIndex = data.length(); -3722 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); -3723 } -3724 } -3725 FakeLanguageGen flg = mixAll(pairs.toArray()); -3726 flg.modifiers.addAll(mods); -3727 return flg; -3728 } +3558 public FakeLanguageGen removeAccents() { +3559 +3560 String[] ov = copyStrings(openingVowels), +3561 mv = copyStrings(midVowels), +3562 oc = copyStrings(openingConsonants), +3563 mc = copyStrings(midConsonants), +3564 cc = copyStrings(closingConsonants), +3565 cs = copyStrings(closingSyllables); +3566 for (int i = 0; i < ov.length; i++) { +3567 ov[i] = removeAccents(openingVowels[i]).toString(); +3568 } +3569 for (int i = 0; i < mv.length; i++) { +3570 mv[i] = removeAccents(midVowels[i]).toString(); +3571 } +3572 for (int i = 0; i < oc.length; i++) { +3573 oc[i] = removeAccents(openingConsonants[i]).toString(); +3574 } +3575 for (int i = 0; i < mc.length; i++) { +3576 mc[i] = removeAccents(midConsonants[i]).toString(); +3577 } +3578 for (int i = 0; i < cc.length; i++) { +3579 cc[i] = removeAccents(closingConsonants[i]).toString(); +3580 } +3581 for (int i = 0; i < cs.length; i++) { +3582 cs[i] = removeAccents(closingSyllables[i]).toString(); +3583 } +3584 +3585 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3586 vowelStartFrequency, +3587 vowelEndFrequency, +3588 vowelSplitFrequency, +3589 syllableEndFrequency, sanityChecks, clean, modifiers); +3590 } +3591 +3592 /** +3593 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. +3594 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3595 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3596 * +3597 * @param mods an array or vararg of Modifier objects +3598 * @return a copy of this with the Modifiers added +3599 */ +3600 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { +3601 FakeLanguageGen next = copy(); +3602 next.modifiers.addAll(mods); +3603 return next; +3604 } +3605 +3606 /** +3607 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. +3608 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3609 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3610 * +3611 * @param mods an array or vararg of Modifier objects +3612 * @return a copy of this with the Modifiers added +3613 */ +3614 public FakeLanguageGen addModifiers(Modifier... mods) { +3615 FakeLanguageGen next = copy(); +3616 Collections.addAll(next.modifiers, mods); +3617 return next; +3618 } +3619 +3620 /** +3621 * Creates a copy of this FakeLanguageGen with no modifiers. +3622 * +3623 * @return a copy of this FakeLanguageGen with modifiers removed. +3624 */ +3625 public FakeLanguageGen removeModifiers() { +3626 FakeLanguageGen next = copy(); +3627 next.modifiers.clear(); +3628 return next; +3629 } +3630 +3631 public static Modifier modifier(String pattern, String replacement) { +3632 return new Modifier(pattern, replacement); +3633 } +3634 +3635 public static Modifier modifier(String pattern, String replacement, double chance) { +3636 return new Modifier(pattern, replacement, chance); +3637 } +3638 +3639 @Override +3640 public boolean equals(Object o) { +3641 if (this == o) return true; +3642 if (o == null || getClass() != o.getClass()) return false; +3643 +3644 FakeLanguageGen that = (FakeLanguageGen) o; +3645 +3646 if (clean != that.clean) return false; +3647 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; +3648 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; +3649 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; +3650 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; +3651 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; +3652 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3653 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; +3654 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3655 if (!Arrays.equals(midVowels, that.midVowels)) return false; +3656 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3657 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; +3658 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3659 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; +3660 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3661 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; +3662 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3663 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; +3664 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3665 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; +3666 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; +3667 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3668 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; +3669 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; +3670 } +3671 +3672 @Override +3673 public int hashCode() { +3674 int result; +3675 long temp; +3676 result = CrossHash.Lightning.hash(openingVowels); +3677 result = 31 * result + CrossHash.Lightning.hash(midVowels); +3678 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); +3679 result = 31 * result + CrossHash.Lightning.hash(midConsonants); +3680 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); +3681 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); +3682 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); +3683 result = 31 * result + (clean ? 1 : 0); +3684 result = 31 * result + syllableFrequencies.hashCode(); +3685 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); +3686 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3687 temp = NumberTools.doubleToLongBits(vowelStartFrequency); +3688 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3689 temp = NumberTools.doubleToLongBits(vowelEndFrequency); +3690 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3691 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); +3692 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3693 temp = NumberTools.doubleToLongBits(syllableEndFrequency); +3694 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3695 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); +3696 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); +3697 return result; +3698 } +3699 +3700 @Override +3701 public String toString() { +3702 return "FakeLanguageGen{" + +3703 "openingVowels=" + Arrays.toString(openingVowels) + +3704 ", midVowels=" + Arrays.toString(midVowels) + +3705 ", openingConsonants=" + Arrays.toString(openingConsonants) + +3706 ", midConsonants=" + Arrays.toString(midConsonants) + +3707 ", closingConsonants=" + Arrays.toString(closingConsonants) + +3708 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + +3709 ", closingSyllables=" + Arrays.toString(closingSyllables) + +3710 ", clean=" + clean + +3711 ", syllableFrequencies=" + syllableFrequencies + +3712 ", totalSyllableFrequency=" + totalSyllableFrequency + +3713 ", vowelStartFrequency=" + vowelStartFrequency + +3714 ", vowelEndFrequency=" + vowelEndFrequency + +3715 ", vowelSplitFrequency=" + vowelSplitFrequency + +3716 ", syllableEndFrequency=" + syllableEndFrequency + +3717 ", sanityChecks=" + Arrays.toString(sanityChecks) + +3718 ", modifiers=" + modifiers + +3719 '}'; +3720 } +3721 +3722 public FakeLanguageGen copy() { +3723 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, +3724 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, +3725 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) +3726 .summarize(summary); +3727 } +3728 3729 -3730 public static class Modifier implements Serializable { -3731 private static final long serialVersionUID = 1734863678490422371L; -3732 public final Alteration[] alterations; +3730 public String serializeToString() { +3731 return (summary == null) ? "" : summary; +3732 } 3733 -3734 public Modifier() { -3735 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -3736 } -3737 -3738 public Modifier(String pattern, String replacement) { -3739 alterations = new Alteration[]{new Alteration(pattern, replacement)}; -3740 } -3741 -3742 public Modifier(String pattern, String replacement, double chance) { -3743 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; -3744 } -3745 -3746 public Modifier(Alteration... alts) { -3747 alterations = (alts == null) ? new Alteration[0] : alts; -3748 } -3749 -3750 public StringBuilder modify(RNG rng, StringBuilder sb) { -3751 Matcher m; -3752 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); -3753 String tmp; -3754 boolean found; -3755 Alteration alt; -3756 for (int a = 0; a < alterations.length; a++) { -3757 alt = alterations[a]; -3758 tmp = working.toString(); -3759 tb = Replacer.wrap(new StringBuilder(tmp.length())); -3760 m = alt.replacer.getPattern().matcher(tmp); -3761 -3762 found = false; -3763 while (true) { -3764 if (rng.nextDouble() < alt.chance) { -3765 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) -3766 break; -3767 found = true; -3768 } else { -3769 if (!m.find()) -3770 break; -3771 found = true; -3772 m.getGroup(MatchResult.PREFIX, tb); -3773 m.getGroup(MatchResult.MATCH, tb); -3774 m.setTarget(m, MatchResult.SUFFIX); -3775 } -3776 } -3777 if (found) { -3778 m.getGroup(MatchResult.TARGET, tb); -3779 working = tb; -3780 } -3781 } -3782 return working.toStringBuilder(); -3783 } -3784 -3785 /** -3786 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. -3787 */ -3788 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3734 public static FakeLanguageGen deserializeFromString(String data) { +3735 if (data == null || data.equals("")) +3736 return ENGLISH.copy(); +3737 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), +3738 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, +3739 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; +3740 if (tildeIndex < 0) +3741 tildeIndex = data.length(); +3742 +3743 if (snailIndex < 0) +3744 return ENGLISH.copy(); +3745 ArrayList<Object> pairs = new ArrayList<>(4); +3746 while (snailIndex >= 0) { +3747 if (poundIndex >= 0 && poundIndex < snailIndex) // random case +3748 { +3749 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); +3750 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3751 poundIndex = -1; +3752 } else { +3753 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); +3754 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3755 } +3756 snailIndex = data.indexOf('@', snailIndex + 1); +3757 if (snailIndex > breakIndex) +3758 break; +3759 prevTildeIndex = tildeIndex; +3760 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); +3761 if (tildeIndex < 0) +3762 tildeIndex = data.length(); +3763 } +3764 ArrayList<Modifier> mods = new ArrayList<>(8); +3765 if (breakIndex == tempBreak) { +3766 tildeIndex = breakIndex - 1; +3767 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { +3768 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); +3769 if (tildeIndex < 0) tildeIndex = data.length(); +3770 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); +3771 } +3772 } +3773 FakeLanguageGen flg = mixAll(pairs.toArray()); +3774 flg.modifiers.addAll(mods); +3775 return flg; +3776 } +3777 +3778 public static class Modifier implements Serializable { +3779 private static final long serialVersionUID = 1734863678490422371L; +3780 public final Alteration[] alterations; +3781 +3782 public Modifier() { +3783 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3784 } +3785 +3786 public Modifier(String pattern, String replacement) { +3787 alterations = new Alteration[]{new Alteration(pattern, replacement)}; +3788 } 3789 -3790 /** -3791 * For a character who always lengthens 's' and 'z' sounds not starting a word. -3792 */ -3793 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); -3794 -3795 /** -3796 * For a character who has a 20% chance to repeat a starting consonant or vowel. -3797 */ -3798 public static final Modifier STUTTER = new Modifier( -3799 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), -3800 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); -3801 -3802 /** -3803 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them -3804 * like å or ö, but not merged letters like æ and œ). -3805 */ -3806 public static final Modifier DOUBLE_VOWELS = new Modifier( -3807 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" -3808 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" -3809 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); -3810 -3811 -3812 /** -3813 * For a language that has a 50% chance to repeat a single consonant. -3814 */ -3815 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + -3816 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + -3817 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); -3818 -3819 /** -3820 * For a language that never repeats the same letter twice in a row. -3821 */ -3822 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); -3823 -3824 /** -3825 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. -3826 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j -3827 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ -3828 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. -3829 */ -3830 public static final Modifier SIMPLIFY_NORSE = replacementTable( -3831 "á", "a", -3832 "é", "e", -3833 "í", "i", -3834 "ý", "y", -3835 "ó", "o", -3836 "ú", "u", -3837 "æ", "ae", -3838 "ö", "ou", -3839 "([^aeiou])jy", "$1yai", -3840 "([^aeiou])j(?:[aeiouy]+)", "$1yo", -3841 "s([ðþ])", "st", -3842 "\\bf[ðþ]", "fr", -3843 "[ðþ]", "th"); -3844 -3845 /** -3846 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". -3847 */ -3848 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); -3849 /** -3850 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate -3851 * for fixing a word that isn't pronounceable. -3852 */ -3853 public static final Modifier GENERAL_CLEANUP = replacementTable( -3854 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", -3855 "q([ùúûüũūŭůűųu])$", "q$1e", -3856 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", -3857 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", -3858 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", -3859 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", -3860 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", -3861 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", -3862 "qq", "q"); -3863 -3864 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy -3865 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3790 public Modifier(String pattern, String replacement, double chance) { +3791 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; +3792 } +3793 +3794 public Modifier(Alteration... alts) { +3795 alterations = (alts == null) ? new Alteration[0] : alts; +3796 } +3797 +3798 public StringBuilder modify(RNG rng, StringBuilder sb) { +3799 Matcher m; +3800 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); +3801 String tmp; +3802 boolean found; +3803 Alteration alt; +3804 for (int a = 0; a < alterations.length; a++) { +3805 alt = alterations[a]; +3806 tmp = working.toString(); +3807 tb = Replacer.wrap(new StringBuilder(tmp.length())); +3808 m = alt.replacer.getPattern().matcher(tmp); +3809 +3810 found = false; +3811 while (true) { +3812 if (rng.nextDouble() < alt.chance) { +3813 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) +3814 break; +3815 found = true; +3816 } else { +3817 if (!m.find()) +3818 break; +3819 found = true; +3820 m.getGroup(MatchResult.PREFIX, tb); +3821 m.getGroup(MatchResult.MATCH, tb); +3822 m.setTarget(m, MatchResult.SUFFIX); +3823 } +3824 } +3825 if (found) { +3826 m.getGroup(MatchResult.TARGET, tb); +3827 working = tb; +3828 } +3829 } +3830 return working.toStringBuilder(); +3831 } +3832 +3833 /** +3834 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. +3835 */ +3836 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3837 +3838 /** +3839 * For a character who always lengthens 's' and 'z' sounds not starting a word. +3840 */ +3841 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); +3842 +3843 /** +3844 * For a character who has a 20% chance to repeat a starting consonant or vowel. +3845 */ +3846 public static final Modifier STUTTER = new Modifier( +3847 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), +3848 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); +3849 +3850 /** +3851 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them +3852 * like å or ö, but not merged letters like æ and œ). +3853 */ +3854 public static final Modifier DOUBLE_VOWELS = new Modifier( +3855 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" +3856 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" +3857 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); +3858 +3859 +3860 /** +3861 * For a language that has a 50% chance to repeat a single consonant. +3862 */ +3863 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + +3864 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + +3865 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); 3866 3867 /** -3868 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and -3869 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the -3870 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3871 * -3872 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text -3873 * @param change a String containing characters that will replace occurrences of characters in initial -3874 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3875 */ -3876 public static Modifier charReplacementTable(String initial, String change) { -3877 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; -3878 for (int i = 0; i < alts.length; i++) { -3879 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, -3880 // which is slightly slower and has some odd escaping cases. -3881 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); -3882 } -3883 return new Modifier(alts); -3884 } -3885 -3886 /** -3887 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the -3888 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3889 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, -3890 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3891 * this example to replace the repeated section with only the first vowel. -3892 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced -3893 * first, possibly making the later key not match), or if an earlier replacement causes a later one to -3894 * become valid. -3895 * -3896 * @param map containing String keys to replace and String values to use instead; replacements happen in order -3897 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3898 */ -3899 public static Modifier replacementTable(OrderedMap<String, String> map) { -3900 if (map == null) -3901 return new Modifier(); -3902 Alteration[] alts = new Alteration[map.size()]; -3903 for (int i = 0; i < alts.length; i++) { -3904 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); -3905 } -3906 return new Modifier(alts); -3907 } -3908 -3909 /** -3910 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because -3911 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3912 * This overload of replacementTable allows full regex syntax for search and replacement Strings, -3913 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3914 * this example to replace the repeated section with only the first vowel. -3915 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced -3916 * first, possibly making the later search not match), or if an earlier replacement causes a later one to -3917 * become valid. -3918 * -3919 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order -3920 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3921 */ -3922 public static Modifier replacementTable(String... pairs) { -3923 int len; -3924 if (pairs == null || (len = pairs.length) <= 1) -3925 return new Modifier(); -3926 Alteration[] alts = new Alteration[len >> 1]; -3927 for (int i = 0; i < alts.length; i++) { -3928 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); -3929 } -3930 return new Modifier(alts); -3931 } -3932 -3933 /** -3934 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3935 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel -3936 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the -3937 * newly-inserted vowel to be likely to be present in every word of some sentences. -3938 * @param insertion the String to use as an additional vowel -3939 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less -3940 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3941 */ -3942 public static Modifier insertVowel(String insertion, double chance) -3943 { -3944 return new Modifier(anyVowelCluster, insertion, chance); -3945 } -3946 -3947 /** -3948 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3949 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had -3950 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you -3951 * want the newly-inserted consonant to be likely to be present in every word of some sentences. -3952 * @param insertion the String to use as an additional consonant -3953 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less -3954 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3955 */ -3956 public static Modifier insertConsonant(String insertion, double chance) -3957 { -3958 return new Modifier(anyConsonantCluster, insertion, chance); -3959 } -3960 -3961 /** -3962 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3963 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of -3964 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3965 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, -3966 * so this might not do anything. -3967 * @param insertion the String to use as an additional opening vowel -3968 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3969 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3970 */ -3971 public static Modifier insertOpeningVowel(String insertion, double chance) -3972 { -3973 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); -3974 } -3975 -3976 /** -3977 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3978 * that the language already uses; insertion will replace an existing consonant at the start of a word with a -3979 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -3980 * consonant to be likely to start every word of some sentences. Not all languages can start words with -3981 * consonants, or do that very rarely, so this might not do anything. -3982 * @param insertion the String to use as an additional opening consonant -3983 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3984 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3985 */ -3986 public static Modifier insertOpeningConsonant(String insertion, double chance) -3987 { -3988 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); -3989 } -3990 -3991 /** -3992 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3993 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of -3994 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3995 * to end every word of some sentences. Not all languages can end words with vowels, or do that very -3996 * rarely, so this might not do anything. -3997 * @param insertion the String to use as an additional closing vowel -3998 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less -3999 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4000 */ -4001 public static Modifier insertClosingVowel(String insertion, double chance) -4002 { -4003 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); -4004 } -4005 -4006 /** -4007 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -4008 * that the language already uses; insertion will replace an existing consonant at the end of a word with a -4009 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -4010 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, -4011 * or do that very rarely, so this might not do anything. -4012 * @param insertion the String to use as an additional closing consonant -4013 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less -4014 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4015 */ -4016 public static Modifier insertClosingConsonant(String insertion, double chance) -4017 { -4018 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); -4019 } -4020 -4021 /** -4022 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek -4023 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of -4024 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this -4025 * Modifier is a no-op. Its use is never needed any more. -4026 * @deprecated This Modifier doesn't do anything, and isn't needed. -4027 */ -4028 @Deprecated -4029 public static final Modifier SIMPLIFY_ARABIC = new Modifier( -4030 /* -4031 new Alteration("ţ", "th"), -4032 new Alteration("ĥ", "kh"), -4033 new Alteration("ħ", "khr"), -4034 new Alteration("đ", "dh"), -4035 new Alteration("ď", "dt"), -4036 new Alteration("š", "sh"), -4037 new Alteration("ş", "shw"), -4038 new Alteration("ť", "ch"), -4039 new Alteration("ż", "zh"), -4040 new Alteration("ξ", "khm"), -4041 new Alteration("δ", "gh"), -4042 new Alteration("ā", "aa"), -4043 new Alteration("ū", "uu"), -4044 new Alteration("ī", "ii")*/); -4045 -4046 @Override -4047 public boolean equals(Object o) { -4048 if (this == o) return true; -4049 if (o == null || getClass() != o.getClass()) return false; -4050 -4051 Modifier modifier = (Modifier) o; -4052 -4053 // Probably incorrect - comparing Object[] arrays with Arrays.equals -4054 return Arrays.equals(alterations, modifier.alterations); -4055 } -4056 -4057 @Override -4058 public int hashCode() { -4059 return CrossHash.Lightning.hash(alterations); -4060 } -4061 -4062 @Override -4063 public String toString() { -4064 return "Modifier{" + -4065 "alterations=" + Arrays.toString(alterations) + -4066 '}'; +3868 * For a language that never repeats the same letter twice in a row. +3869 */ +3870 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); +3871 +3872 /** +3873 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. +3874 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j +3875 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ +3876 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. +3877 */ +3878 public static final Modifier SIMPLIFY_NORSE = replacementTable( +3879 "á", "a", +3880 "é", "e", +3881 "í", "i", +3882 "ý", "y", +3883 "ó", "o", +3884 "ú", "u", +3885 "æ", "ae", +3886 "ö", "ou", +3887 "([^aeiou])jy", "$1yai", +3888 "([^aeiou])j(?:[aeiouy]+)", "$1yo", +3889 "s([ðþ])", "st", +3890 "\\bf[ðþ]", "fr", +3891 "[ðþ]", "th"); +3892 +3893 /** +3894 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". +3895 */ +3896 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); +3897 /** +3898 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate +3899 * for fixing a word that isn't pronounceable. +3900 */ +3901 public static final Modifier GENERAL_CLEANUP = replacementTable( +3902 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", +3903 "q([ùúûüũūŭůűųu])$", "q$1e", +3904 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", +3905 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", +3906 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", +3907 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", +3908 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", +3909 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", +3910 "qq", "q"); +3911 +3912 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy +3913 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3914 +3915 /** +3916 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and +3917 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the +3918 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3919 * +3920 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text +3921 * @param change a String containing characters that will replace occurrences of characters in initial +3922 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3923 */ +3924 public static Modifier charReplacementTable(String initial, String change) { +3925 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; +3926 for (int i = 0; i < alts.length; i++) { +3927 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, +3928 // which is slightly slower and has some odd escaping cases. +3929 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); +3930 } +3931 return new Modifier(alts); +3932 } +3933 +3934 /** +3935 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the +3936 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3937 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, +3938 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3939 * this example to replace the repeated section with only the first vowel. +3940 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced +3941 * first, possibly making the later key not match), or if an earlier replacement causes a later one to +3942 * become valid. +3943 * +3944 * @param map containing String keys to replace and String values to use instead; replacements happen in order +3945 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3946 */ +3947 public static Modifier replacementTable(OrderedMap<String, String> map) { +3948 if (map == null) +3949 return new Modifier(); +3950 Alteration[] alts = new Alteration[map.size()]; +3951 for (int i = 0; i < alts.length; i++) { +3952 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); +3953 } +3954 return new Modifier(alts); +3955 } +3956 +3957 /** +3958 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because +3959 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3960 * This overload of replacementTable allows full regex syntax for search and replacement Strings, +3961 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3962 * this example to replace the repeated section with only the first vowel. +3963 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced +3964 * first, possibly making the later search not match), or if an earlier replacement causes a later one to +3965 * become valid. +3966 * +3967 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order +3968 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3969 */ +3970 public static Modifier replacementTable(String... pairs) { +3971 int len; +3972 if (pairs == null || (len = pairs.length) <= 1) +3973 return new Modifier(); +3974 Alteration[] alts = new Alteration[len >> 1]; +3975 for (int i = 0; i < alts.length; i++) { +3976 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); +3977 } +3978 return new Modifier(alts); +3979 } +3980 +3981 /** +3982 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +3983 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel +3984 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the +3985 * newly-inserted vowel to be likely to be present in every word of some sentences. +3986 * @param insertion the String to use as an additional vowel +3987 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less +3988 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3989 */ +3990 public static Modifier insertVowel(String insertion, double chance) +3991 { +3992 return new Modifier(anyVowelCluster, insertion, chance); +3993 } +3994 +3995 /** +3996 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +3997 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had +3998 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you +3999 * want the newly-inserted consonant to be likely to be present in every word of some sentences. +4000 * @param insertion the String to use as an additional consonant +4001 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less +4002 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4003 */ +4004 public static Modifier insertConsonant(String insertion, double chance) +4005 { +4006 return new Modifier(anyConsonantCluster, insertion, chance); +4007 } +4008 +4009 /** +4010 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4011 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of +4012 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4013 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, +4014 * so this might not do anything. +4015 * @param insertion the String to use as an additional opening vowel +4016 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4017 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4018 */ +4019 public static Modifier insertOpeningVowel(String insertion, double chance) +4020 { +4021 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); +4022 } +4023 +4024 /** +4025 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4026 * that the language already uses; insertion will replace an existing consonant at the start of a word with a +4027 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4028 * consonant to be likely to start every word of some sentences. Not all languages can start words with +4029 * consonants, or do that very rarely, so this might not do anything. +4030 * @param insertion the String to use as an additional opening consonant +4031 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4032 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4033 */ +4034 public static Modifier insertOpeningConsonant(String insertion, double chance) +4035 { +4036 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); +4037 } +4038 +4039 /** +4040 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4041 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of +4042 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4043 * to end every word of some sentences. Not all languages can end words with vowels, or do that very +4044 * rarely, so this might not do anything. +4045 * @param insertion the String to use as an additional closing vowel +4046 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4047 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4048 */ +4049 public static Modifier insertClosingVowel(String insertion, double chance) +4050 { +4051 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); +4052 } +4053 +4054 /** +4055 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4056 * that the language already uses; insertion will replace an existing consonant at the end of a word with a +4057 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4058 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, +4059 * or do that very rarely, so this might not do anything. +4060 * @param insertion the String to use as an additional closing consonant +4061 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4062 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4063 */ +4064 public static Modifier insertClosingConsonant(String insertion, double chance) +4065 { +4066 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); 4067 } 4068 -4069 public String serializeToString() { -4070 if (alterations == null || alterations.length == 0) return "\6"; -4071 StringBuilder sb = new StringBuilder(32).append('\6'); -4072 for (int i = 0; i < alterations.length; i++) -4073 sb.append(alterations[i].serializeToString()).append('\6'); -4074 return sb.toString(); -4075 } -4076 -4077 public static Modifier deserializeFromString(String data) { -4078 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; -4079 while (currIdx >= 0) { -4080 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) -4081 break; -4082 matches++; -4083 } -4084 Alteration[] alts = new Alteration[matches]; -4085 for (int i = 0; i < matches; i++) { -4086 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); -4087 } -4088 return new Modifier(alts); -4089 } -4090 } -4091 -4092 public static class Alteration implements Serializable { -4093 private static final long serialVersionUID = -2138854697837563188L; -4094 public Replacer replacer; -4095 public String replacement; -4096 public double chance; -4097 -4098 public Alteration() { -4099 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -4100 } -4101 -4102 public Alteration(String pattern, String replacement) { -4103 this.replacement = replacement; -4104 replacer = Pattern.compile(pattern).replacer(replacement); -4105 chance = 1.0; -4106 } -4107 -4108 public Alteration(String pattern, String replacement, double chance) { -4109 this.replacement = replacement; -4110 replacer = Pattern.compile(pattern).replacer(replacement); -4111 this.chance = chance; -4112 } -4113 -4114 public Alteration(Pattern pattern, String replacement, double chance) { -4115 this.replacement = replacement; -4116 replacer = pattern.replacer(replacement); -4117 this.chance = chance; -4118 } -4119 -4120 @Override -4121 public boolean equals(Object o) { -4122 if (this == o) return true; -4123 if (o == null || getClass() != o.getClass()) return false; +4069 /** +4070 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek +4071 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of +4072 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this +4073 * Modifier is a no-op. Its use is never needed any more. +4074 * @deprecated This Modifier doesn't do anything, and isn't needed. +4075 */ +4076 @Deprecated +4077 public static final Modifier SIMPLIFY_ARABIC = new Modifier( +4078 /* +4079 new Alteration("ţ", "th"), +4080 new Alteration("ĥ", "kh"), +4081 new Alteration("ħ", "khr"), +4082 new Alteration("đ", "dh"), +4083 new Alteration("ď", "dt"), +4084 new Alteration("š", "sh"), +4085 new Alteration("ş", "shw"), +4086 new Alteration("ť", "ch"), +4087 new Alteration("ż", "zh"), +4088 new Alteration("ξ", "khm"), +4089 new Alteration("δ", "gh"), +4090 new Alteration("ā", "aa"), +4091 new Alteration("ū", "uu"), +4092 new Alteration("ī", "ii")*/); +4093 +4094 @Override +4095 public boolean equals(Object o) { +4096 if (this == o) return true; +4097 if (o == null || getClass() != o.getClass()) return false; +4098 +4099 Modifier modifier = (Modifier) o; +4100 +4101 // Probably incorrect - comparing Object[] arrays with Arrays.equals +4102 return Arrays.equals(alterations, modifier.alterations); +4103 } +4104 +4105 @Override +4106 public int hashCode() { +4107 return CrossHash.Lightning.hash(alterations); +4108 } +4109 +4110 @Override +4111 public String toString() { +4112 return "Modifier{" + +4113 "alterations=" + Arrays.toString(alterations) + +4114 '}'; +4115 } +4116 +4117 public String serializeToString() { +4118 if (alterations == null || alterations.length == 0) return "\6"; +4119 StringBuilder sb = new StringBuilder(32).append('\6'); +4120 for (int i = 0; i < alterations.length; i++) +4121 sb.append(alterations[i].serializeToString()).append('\6'); +4122 return sb.toString(); +4123 } 4124 -4125 Alteration that = (Alteration) o; -4126 -4127 if (Double.compare(that.chance, chance) != 0) return false; -4128 return replacer.equals(that.replacer); -4129 -4130 } -4131 -4132 @Override -4133 public int hashCode() { -4134 int result; -4135 long temp; -4136 result = replacer.hashCode(); -4137 temp = NumberTools.doubleToLongBits(chance); -4138 result = 31 * result + (int) (temp ^ (temp >>> 32)); -4139 return result; -4140 } -4141 -4142 @Override -4143 public String toString() { -4144 return "Alteration{" + -4145 "replacer=" + replacer + -4146 ", chance=" + chance + -4147 '}'; +4125 public static Modifier deserializeFromString(String data) { +4126 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; +4127 while (currIdx >= 0) { +4128 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) +4129 break; +4130 matches++; +4131 } +4132 Alteration[] alts = new Alteration[matches]; +4133 for (int i = 0; i < matches; i++) { +4134 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); +4135 } +4136 return new Modifier(alts); +4137 } +4138 } +4139 +4140 public static class Alteration implements Serializable { +4141 private static final long serialVersionUID = -2138854697837563188L; +4142 public Replacer replacer; +4143 public String replacement; +4144 public double chance; +4145 +4146 public Alteration() { +4147 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); 4148 } 4149 -4150 public String serializeToString() { -4151 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; -4152 } -4153 -4154 public static Alteration deserializeFromString(String data) { -4155 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); -4156 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), -4157 data.substring(split2 + 1, split4), -4158 Double.parseDouble(data.substring(split4 + 1))); -4159 } -4160 } +4150 public Alteration(String pattern, String replacement) { +4151 this.replacement = replacement; +4152 replacer = Pattern.compile(pattern).replacer(replacement); +4153 chance = 1.0; +4154 } +4155 +4156 public Alteration(String pattern, String replacement, double chance) { +4157 this.replacement = replacement; +4158 replacer = Pattern.compile(pattern).replacer(replacement); +4159 this.chance = chance; +4160 } 4161 -4162 /** -4163 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling -4164 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. -4165 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given -4166 * at construction. The parameters to -4167 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of -4168 * the same name, and all fields in this class are public and modifiable. -4169 */ -4170 public static class SentenceForm implements Serializable -4171 { -4172 private static final long serialVersionUID = 1246527948419533147L; -4173 public StatefulRNG rng; -4174 public int minWords, maxWords, maxChars; -4175 public String[] midPunctuation, endPunctuation; -4176 public double midPunctuationFrequency; -4177 public FakeLanguageGen language; -4178 public SentenceForm() -4179 { -4180 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, -4181 new String[]{",", ",", ",", ";", ";"}, -4182 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); -4183 } -4184 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) -4185 { -4186 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, -4187 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4162 public Alteration(Pattern pattern, String replacement, double chance) { +4163 this.replacement = replacement; +4164 replacer = pattern.replacer(replacement); +4165 this.chance = chance; +4166 } +4167 +4168 @Override +4169 public boolean equals(Object o) { +4170 if (this == o) return true; +4171 if (o == null || getClass() != o.getClass()) return false; +4172 +4173 Alteration that = (Alteration) o; +4174 +4175 if (Double.compare(that.chance, chance) != 0) return false; +4176 return replacer.equals(that.replacer); +4177 +4178 } +4179 +4180 @Override +4181 public int hashCode() { +4182 int result; +4183 long temp; +4184 result = replacer.hashCode(); +4185 temp = NumberTools.doubleToLongBits(chance); +4186 result = 31 * result + (int) (temp ^ (temp >>> 32)); +4187 return result; 4188 } -4189 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4190 String[] endPunctuation, double midPunctuationFrequency) -4191 { -4192 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4193 midPunctuationFrequency, -1); -4194 } -4195 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4196 String[] endPunctuation, double midPunctuationFrequency, int maxChars) -4197 { -4198 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4199 midPunctuationFrequency, maxChars); +4189 +4190 @Override +4191 public String toString() { +4192 return "Alteration{" + +4193 "replacer=" + replacer + +4194 ", chance=" + chance + +4195 '}'; +4196 } +4197 +4198 public String serializeToString() { +4199 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; 4200 } 4201 -4202 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, -4203 String[] midPunctuation, String[] endPunctuation, -4204 double midPunctuationFrequency, int maxChars) -4205 { -4206 this.language = language; -4207 this.rng = new StatefulRNG(rng.getState()); -4208 this.minWords = minWords; -4209 this.maxWords = maxWords; -4210 this.midPunctuation = midPunctuation; -4211 this.endPunctuation = endPunctuation; -4212 this.midPunctuationFrequency = midPunctuationFrequency; -4213 this.maxChars = maxChars; -4214 } -4215 public String sentence() -4216 { -4217 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, -4218 midPunctuationFrequency, maxChars); -4219 } -4220 -4221 public String serializeToString() { -4222 return language.serializeToString() + '℘' + -4223 rng.getState() + '℘' + -4224 minWords + '℘' + -4225 maxWords + '℘' + -4226 StringKit.join("ℙ", midPunctuation) + '℘' + -4227 StringKit.join("ℙ", endPunctuation) + '℘' + -4228 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + -4229 maxChars; -4230 } -4231 public static SentenceForm deserializeFromString(String ser) -4232 { -4233 int gap = ser.indexOf('℘'); -4234 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); -4235 StatefulRNG rng = new StatefulRNG( -4236 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4237 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4238 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4239 String[] midPunctuation = -4240 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4241 String[] endPunctuation = -4242 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4243 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4244 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); -4245 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); -4246 } -4247 } -4248} +4202 public static Alteration deserializeFromString(String data) { +4203 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); +4204 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), +4205 data.substring(split2 + 1, split4), +4206 Double.parseDouble(data.substring(split4 + 1))); +4207 } +4208 } +4209 +4210 /** +4211 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling +4212 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. +4213 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given +4214 * at construction. The parameters to +4215 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of +4216 * the same name, and all fields in this class are public and modifiable. +4217 */ +4218 public static class SentenceForm implements Serializable +4219 { +4220 private static final long serialVersionUID = 1246527948419533147L; +4221 public StatefulRNG rng; +4222 public int minWords, maxWords, maxChars; +4223 public String[] midPunctuation, endPunctuation; +4224 public double midPunctuationFrequency; +4225 public FakeLanguageGen language; +4226 public SentenceForm() +4227 { +4228 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, +4229 new String[]{",", ",", ",", ";", ";"}, +4230 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4231 } +4232 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) +4233 { +4234 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, +4235 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4236 } +4237 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4238 String[] endPunctuation, double midPunctuationFrequency) +4239 { +4240 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4241 midPunctuationFrequency, -1); +4242 } +4243 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4244 String[] endPunctuation, double midPunctuationFrequency, int maxChars) +4245 { +4246 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4247 midPunctuationFrequency, maxChars); +4248 } +4249 +4250 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, +4251 String[] midPunctuation, String[] endPunctuation, +4252 double midPunctuationFrequency, int maxChars) +4253 { +4254 this.language = language; +4255 this.rng = new StatefulRNG(rng.getState()); +4256 this.minWords = minWords; +4257 this.maxWords = maxWords; +4258 this.midPunctuation = midPunctuation; +4259 this.endPunctuation = endPunctuation; +4260 this.midPunctuationFrequency = midPunctuationFrequency; +4261 this.maxChars = maxChars; +4262 } +4263 public String sentence() +4264 { +4265 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, +4266 midPunctuationFrequency, maxChars); +4267 } +4268 +4269 public String serializeToString() { +4270 return language.serializeToString() + '℘' + +4271 rng.getState() + '℘' + +4272 minWords + '℘' + +4273 maxWords + '℘' + +4274 StringKit.join("ℙ", midPunctuation) + '℘' + +4275 StringKit.join("ℙ", endPunctuation) + '℘' + +4276 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + +4277 maxChars; +4278 } +4279 public static SentenceForm deserializeFromString(String ser) +4280 { +4281 int gap = ser.indexOf('℘'); +4282 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); +4283 StatefulRNG rng = new StatefulRNG( +4284 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4285 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4286 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4287 String[] midPunctuation = +4288 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4289 String[] endPunctuation = +4290 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4291 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4292 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); +4293 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); +4294 } +4295 } +4296} diff --git a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.SentenceForm.html b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.SentenceForm.html index ec9e555de4..9b8646dc36 100644 --- a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.SentenceForm.html +++ b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.SentenceForm.html @@ -2059,2201 +2059,2249 @@ 2051 */ 2052 public static final FakeLanguageGen ALIEN_O = alien_o().register(); 2053 -2054 /** -2055 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages -2056 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric -2057 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this -2058 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, -2059 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null -2060 * elements in its original state, so some code may rely on the items being usable and non-null. -2061 */ -2062 public static final FakeLanguageGen[] registered; -2063 -2064 static { -2065 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. -2066 registered = new FakeLanguageGen[registry.size()-1]; -2067 for (int i = 0; i < registered.length; i++) { -2068 registered[i] = registry.getAt(i+1); -2069 } -2070 } -2071 /** -2072 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . -2073 */ -2074 public FakeLanguageGen() { -2075 this( -2076 new String[]{ -2077 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2078 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2079 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2080 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2081 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", -2082 }, -2083 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, -2084 new String[]{ -2085 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", -2086 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", -2087 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", -2088 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", -2089 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", -2090 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", -2091 "b", "d", "f", "g", "h", "l", "m", "n", -2092 "p", "r", "s", "sh", "t", "th", -2093 "b", "d", "f", "g", "h", "l", "m", "n", -2094 "p", "r", "s", "sh", "t", "th", -2095 "r", "s", "t", "l", "n", -2096 "str", "spr", "spl", "wr", "kn", "kn", "gn", -2097 }, -2098 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", -2099 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", -2100 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" -2101 }, -2102 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", -2103 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", -2104 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", -2105 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", -2106 }, -2107 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2108 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2109 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2110 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", -2111 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2112 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2113 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", -2114 }, -2115 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); -2116 } -2117 -2118 /** -2119 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2120 * class, LOVECRAFT and GREEK_ROMANIZED. -2121 * -2122 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2123 * of a word or in the middle; elements may be repeated to make them more common -2124 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2125 * middle of the word; all openingVowels are automatically copied into this internally. -2126 * Elements may be repeated to make them more common -2127 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2128 * at the start of a word; elements may be repeated to make them more common -2129 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2130 * between vowels; all closingConsonants are automatically copied into this internally. -2131 * Elements may be repeated to make them more common -2132 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2133 * at the end of a word; elements may be repeated to make them more common -2134 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2135 * whatever the word should end in; elements may be repeated to make them more common -2136 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2137 * then "a-a" may be possible; elements may be repeated to make them more common -2138 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2139 * tied to syllableFrequencies -2140 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2141 * represents how often each syllable count should appear relative to other counts; there -2142 * is no need to restrict the numbers to add up to any other number -2143 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2144 * higher numbers yield more words starting with vowels -2145 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2146 * numbers yield more words ending in vowels -2147 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2148 * often a vowel will be split into two vowels separated by one of those splitters -2149 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2150 * closingSyllables is used instead of ending normally -2151 */ -2152 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2153 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2154 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2155 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { -2156 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, -2157 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, -2158 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); -2159 } -2160 -2161 /** -2162 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2163 * class, LOVECRAFT and GREEK_ROMANIZED. -2164 * -2165 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2166 * of a word or in the middle; elements may be repeated to make them more common -2167 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2168 * middle of the word; all openingVowels are automatically copied into this internally. -2169 * Elements may be repeated to make them more common -2170 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2171 * at the start of a word; elements may be repeated to make them more common -2172 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2173 * between vowels; all closingConsonants are automatically copied into this internally. +2054 // àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳ +2055 // çðþñýćĉċčďđĝğġģĥħĵķĺļľŀłńņňŋŕŗřśŝşšţťŵŷÿźżžșțẁẃẅ +2056 private static FakeLanguageGen alien_u(){ +2057 return new FakeLanguageGen( +2058 new String[]{ +2059 "a", "a", "a", "a", "ä", "i", "o", "o", "o", "ö", "u", "u", "u", "u", "u", "u", "ü", "ü" +2060 }, +2061 new String[]{}, +2062 new String[]{ +2063 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2064 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2065 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2066 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2067 }, +2068 new String[]{ +2069 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2070 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2071 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2072 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2073 }, +2074 new String[]{ +2075 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", +2076 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2077 "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2078 }, +2079 new String[]{"emb", "embrid", "embraŋ", "eŋ", "eŋul", "eŋov", "eẃul", "eẃuld", "eẃulb", +2080 "eviś", "evim", "ełurn", "ełav", "egiġ", "ergiġ", "elgiġ", "eŕu", "eŕup", "eŕulm", "eŕuv", +2081 "eħul", "eħid", "eħiŋ", "eyü", "eyür", "eyürl", "eyüld", "eyüns", "eqä", "eqäp", "eqäġ", +2082 "esu", "esumb", "esulg", "esurl", "eśo", "eśold", "eśolg", "eśu", "eśur", "eśuŋ", +2083 "eñu", "eñuns", "eñurn", "eño", "eñolb", "eñols" +2084 }, +2085 new String[]{"'"}, new int[]{1, 2, 3, 4, 5}, new double[]{3, 4, 7, 5, 2}, 0.4, 0.15, 0.06, 0.5, null, true); +2086 } +2087 +2088 /** +2089 * Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for +2090 * an alien species. This alien language is meant to have an abrupt change mid-word for many words, with the suffix +2091 * of roughly half of words using the letter "e", which is absent from the rest of the language; these suffixes can +2092 * also use consonant clusters, which are similarly absent elsewhere. The suffixes would make sense as a historical +2093 * relic or as a linguistic holdout from a historical merger. As the name would suggest, it strongly prefers +2094 * using the vowel "u", with it present in about half the groups, and can use the umlaut accent "ü" on some vowels. +2095 * The consonants completely avoid hard sounds like "t" and "k", and don't cluster; they often have special marks. +2096 * This should be relatively easy to pronounce for an alien language, though the words are rather long. +2097 * <br> +2098 * Üweħid vuŕeħid deẃul leŋul waloyeyür; äyovavü... +2099 */ +2100 public static final FakeLanguageGen ALIEN_U = alien_u().register(); +2101 +2102 /** +2103 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages +2104 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric +2105 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this +2106 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, +2107 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null +2108 * elements in its original state, so some code may rely on the items being usable and non-null. +2109 */ +2110 public static final FakeLanguageGen[] registered; +2111 +2112 static { +2113 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. +2114 registered = new FakeLanguageGen[registry.size()-1]; +2115 for (int i = 0; i < registered.length; i++) { +2116 registered[i] = registry.getAt(i+1); +2117 } +2118 } +2119 /** +2120 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . +2121 */ +2122 public FakeLanguageGen() { +2123 this( +2124 new String[]{ +2125 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2126 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2127 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2128 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2129 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", +2130 }, +2131 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, +2132 new String[]{ +2133 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", +2134 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", +2135 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", +2136 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", +2137 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", +2138 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", +2139 "b", "d", "f", "g", "h", "l", "m", "n", +2140 "p", "r", "s", "sh", "t", "th", +2141 "b", "d", "f", "g", "h", "l", "m", "n", +2142 "p", "r", "s", "sh", "t", "th", +2143 "r", "s", "t", "l", "n", +2144 "str", "spr", "spl", "wr", "kn", "kn", "gn", +2145 }, +2146 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", +2147 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", +2148 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" +2149 }, +2150 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", +2151 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", +2152 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", +2153 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", +2154 }, +2155 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2156 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2157 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2158 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", +2159 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2160 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2161 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", +2162 }, +2163 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); +2164 } +2165 +2166 /** +2167 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2168 * class, LOVECRAFT and GREEK_ROMANIZED. +2169 * +2170 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2171 * of a word or in the middle; elements may be repeated to make them more common +2172 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2173 * middle of the word; all openingVowels are automatically copied into this internally. 2174 * Elements may be repeated to make them more common -2175 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2176 * at the end of a word; elements may be repeated to make them more common -2177 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2178 * whatever the word should end in; elements may be repeated to make them more common -2179 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2180 * then "a-a" may be possible; elements may be repeated to make them more common -2181 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2182 * tied to syllableFrequencies -2183 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2184 * represents how often each syllable count should appear relative to other counts; there -2185 * is no need to restrict the numbers to add up to any other number -2186 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2187 * higher numbers yield more words starting with vowels -2188 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2189 * numbers yield more words ending in vowels -2190 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2191 * often a vowel will be split into two vowels separated by one of those splitters -2192 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2193 * closingSyllables is used instead of ending normally -2194 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many -2195 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets -2196 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a -2197 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly -2198 */ -2199 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2200 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2201 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2202 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, -2203 Pattern[] sane, boolean clean) { -2204 this.openingVowels = openingVowels; -2205 this.midVowels = new String[openingVowels.length + midVowels.length]; -2206 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); -2207 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); -2208 this.openingConsonants = openingConsonants; -2209 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; -2210 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); -2211 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); -2212 this.closingConsonants = closingConsonants; -2213 this.vowelSplitters = vowelSplitters; -2214 this.closingSyllables = closingSyllables; -2215 -2216 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); -2217 -2218 totalSyllableFrequency = this.syllableFrequencies.values().sum(); -2219 if (vowelStartFrequency > 1.0) -2220 this.vowelStartFrequency = 1.0 / vowelStartFrequency; -2221 else -2222 this.vowelStartFrequency = vowelStartFrequency; -2223 if (vowelEndFrequency > 1.0) -2224 this.vowelEndFrequency = 1.0 / vowelEndFrequency; -2225 else -2226 this.vowelEndFrequency = vowelEndFrequency; -2227 if (vowelSplitters.length == 0) -2228 this.vowelSplitFrequency = 0.0; -2229 else if (vowelSplitFrequency > 1.0) -2230 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; -2231 else -2232 this.vowelSplitFrequency = vowelSplitFrequency; -2233 if (closingSyllables.length == 0) -2234 this.syllableEndFrequency = 0.0; -2235 else if (syllableEndFrequency > 1.0) -2236 this.syllableEndFrequency = 1.0 / syllableEndFrequency; -2237 else -2238 this.syllableEndFrequency = syllableEndFrequency; -2239 this.clean = clean; -2240 sanityChecks = sane; -2241 modifiers = new ArrayList<>(16); -2242 } -2243 -2244 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2245 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, -2246 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, -2247 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, -2248 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, -2249 List<Modifier> modifiers) { -2250 this.openingVowels = copyStrings(openingVowels); -2251 this.midVowels = copyStrings(midVowels); -2252 this.openingConsonants = copyStrings(openingConsonants); -2253 this.midConsonants = copyStrings(midConsonants); -2254 this.closingConsonants = copyStrings(closingConsonants); -2255 this.closingSyllables = copyStrings(closingSyllables); -2256 this.vowelSplitters = copyStrings(vowelSplitters); -2257 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); -2258 this.vowelStartFrequency = vowelStartFrequency; -2259 this.vowelEndFrequency = vowelEndFrequency; -2260 this.vowelSplitFrequency = vowelSplitFrequency; -2261 this.syllableEndFrequency = syllableEndFrequency; -2262 for (Double freq : this.syllableFrequencies.values()) { -2263 totalSyllableFrequency += freq; -2264 } -2265 if (sanityChecks == null) -2266 this.sanityChecks = null; -2267 else { -2268 this.sanityChecks = new Pattern[sanityChecks.length]; -2269 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); -2270 } -2271 this.clean = clean; -2272 this.modifiers = new ArrayList<>(modifiers); -2273 } -2274 -2275 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, -2276 Set<String> forbidden, RNG rng, double repeatSingleChance, -2277 int preferredLimit) { -2278 int l, sz = parts.size(); -2279 List<String> working = new ArrayList<>(sz * 24); -2280 String pair; -2281 for (int e = 0; e < parts.size(); e++) { -2282 Map.Entry<String, String> sn = parts.entryAt(e); -2283 if (missingSounds.contains(sn.getKey())) -2284 continue; -2285 for (String t : sn.getValue().split(" ")) { -2286 if (forbidden.contains(t)) -2287 continue; -2288 l = t.length(); -2289 int num; -2290 char c; -2291 switch (l) { -2292 case 0: -2293 break; -2294 case 1: -2295 working.add(t); -2296 working.add(t); -2297 working.add(t); -2298 c = t.charAt(0); -2299 num = 0; -2300 boolean repeat = true; -2301 switch (c) { -2302 case 'w': -2303 num += 2; -2304 case 'y': -2305 case 'h': -2306 num += 4; -2307 case 'q': -2308 case 'x': -2309 num += 4; -2310 repeat = false; -2311 break; -2312 case 'i': -2313 case 'u': -2314 repeat = false; -2315 num = 13; -2316 break; -2317 case 'z': -2318 case 'v': -2319 num = 4; -2320 break; -2321 case 'j': -2322 num = 7; -2323 break; -2324 default: -2325 if (e >= preferredLimit) -2326 num = 6; -2327 else -2328 num = 13; -2329 } -2330 for (int i = 0; i < num * 3; i++) { -2331 if (rng.nextDouble() < 0.75) { -2332 working.add(t); -2333 } -2334 } -2335 -2336 if (repeat && rng.nextDouble() < repeatSingleChance) { -2337 pair = t + t; -2338 if (missingSounds.contains(pair)) -2339 continue; -2340 working.add(pair); -2341 working.add(pair); -2342 working.add(pair); -2343 if (rng.nextDouble() < 0.7) { -2344 working.add(pair); -2345 working.add(pair); -2346 } -2347 if (rng.nextDouble() < 0.7) { -2348 working.add(pair); -2349 } -2350 } -2351 -2352 break; -2353 case 2: -2354 if (rng.nextDouble() < 0.65) { -2355 c = t.charAt(1); -2356 num = 0; -2357 switch (c) { -2358 case 'z': -2359 num = 1; -2360 break; -2361 case 'w': -2362 num = 3; -2363 break; -2364 case 'n': -2365 num = 4; -2366 break; -2367 default: -2368 -2369 if (e >= preferredLimit) -2370 num = 2; -2371 else -2372 num = 7; -2373 } -2374 working.add(t); -2375 for (int i = 0; i < num; i++) { -2376 if (rng.nextDouble() < 0.25) { -2377 working.add(t); -2378 } -2379 } -2380 } -2381 break; -2382 case 3: -2383 if (rng.nextDouble() < 0.5) { -2384 c = t.charAt(0); -2385 switch (c) { -2386 case 'z': -2387 num = 1; -2388 break; -2389 case 'w': -2390 num = 3; -2391 break; -2392 case 'n': -2393 num = 4; -2394 break; -2395 default: -2396 if (e >= preferredLimit) -2397 num = 2; -2398 else -2399 num = 6; -2400 } -2401 working.add(t); -2402 for (int i = 0; i < num; i++) { -2403 if (rng.nextDouble() < 0.2) { -2404 working.add(t); -2405 } -2406 } -2407 } -2408 break; -2409 default: -2410 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { -2411 working.add(t); -2412 } -2413 break; -2414 } -2415 } -2416 } -2417 return working.toArray(new String[0]); -2418 } -2419 -2420 /*private static final String[][] openVowels = new String[][]{ -2421 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, -2422 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, -2423 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, -2424 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, -2425 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, -2426 }; -2427*/ -2428 -2429 public static FakeLanguageGen randomLanguage(RNG rng) { -2430 return randomLanguage(rng.nextLong()); -2431 } -2432 -2433 public static FakeLanguageGen randomLanguage(long seed) { -2434 StatefulRNG rng = new StatefulRNG(seed); -2435 int[] lengths = new int[rng.between(3, 5)]; -2436 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); -2437 double[] chances = new double[lengths.length]; -2438 System.arraycopy(new double[]{ -2439 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) -2440 }, 0, chances, 0, chances.length); -2441 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); -2442 int sz = openCons.size(); -2443 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); -2444 OrderedMap<String, String> -2445 parts0 = new OrderedMap<>(openVowels), -2446 parts1 = new OrderedMap<>(openCons), -2447 parts2 = new OrderedMap<>(midCons), -2448 parts3 = new OrderedMap<>(closeCons); -2449 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); -2450 parts1.reorder(reordering); -2451 parts2.reorder(reordering); -2452 parts3.reorder(reordering); -2453 parts0.reorder(vOrd); -2454 int n = 0; -2455 -2456 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; -2457 -2458 for (n = 0; n < mn; n++) { -2459 missingSounds.add(parts0.keyAt(0)); -2460 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); -2461 parts0.removeFirst(); -2462 } -2463 p0s = parts0.size(); -2464 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); -2465 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; -2466 int vowelAccent = rng.between(1, 7); -2467 for (int i = 0; i < sz0; i++) { -2468 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; -2469 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; -2470 } -2471 if (rng.nextDouble() < 0.8) { -2472 for (int i = 0; i < sz0; i++) { -2473 char ac = nextAccents[i], ua = unaccented[i]; -2474 String v = "", uas = String.valueOf(ua); -2475 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); -2476 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); -2477 for (int j = 0; j < p0s; j++) { -2478 String k = parts0.keyAt(j); -2479 if (uas.equals(k)) -2480 v = parts0.getAt(j); -2481 else { -2482 String current = parts0.getAt(j); -2483 String[] splits = current.split(" "); -2484 for (int s = 0; s < splits.length; s++) { -2485 if (forbidden.contains(uas) && splits[s].contains(uas)) -2486 forbidden.add(splits[s].replace(ua, ac)); -2487 } -2488 parts0.put(k, rep.replace(current)); -2489 } -2490 } -2491 parts0.put(String.valueOf(ac), repLess.replace(v)); -2492 } -2493 } -2494 -2495 n = 0; -2496 if (rng.nextDouble() < 0.75) { -2497 missingSounds.add("z"); -2498 Collections.addAll(forbidden, parts1.get("z").split(" ")); -2499 Collections.addAll(forbidden, parts2.get("z").split(" ")); -2500 Collections.addAll(forbidden, parts3.get("z").split(" ")); -2501 n++; -2502 } -2503 if (rng.nextDouble() < 0.82) { -2504 missingSounds.add("x"); -2505 Collections.addAll(forbidden, parts1.get("x").split(" ")); -2506 Collections.addAll(forbidden, parts2.get("x").split(" ")); -2507 Collections.addAll(forbidden, parts3.get("x").split(" ")); -2508 n++; -2509 } -2510 if (rng.nextDouble() < 0.92) { -2511 missingSounds.add("qu"); -2512 Collections.addAll(forbidden, parts1.get("qu").split(" ")); -2513 Collections.addAll(forbidden, parts2.get("qu").split(" ")); -2514 Collections.addAll(forbidden, parts3.get("qu").split(" ")); -2515 n++; -2516 } -2517 if (rng.nextDouble() < 0.96) { -2518 missingSounds.add("q"); -2519 Collections.addAll(forbidden, parts1.get("q").split(" ")); -2520 Collections.addAll(forbidden, parts2.get("q").split(" ")); -2521 Collections.addAll(forbidden, parts3.get("q").split(" ")); -2522 n++; -2523 } -2524 if (rng.nextDouble() < 0.97) { -2525 missingSounds.add("tl"); -2526 Collections.addAll(forbidden, parts1.get("tl").split(" ")); -2527 Collections.addAll(forbidden, parts2.get("tl").split(" ")); -2528 Collections.addAll(forbidden, parts3.get("tl").split(" ")); -2529 n++; -2530 } -2531 if (rng.nextDouble() < 0.86) { -2532 missingSounds.add("ph"); -2533 Collections.addAll(forbidden, parts1.get("ph").split(" ")); -2534 Collections.addAll(forbidden, parts2.get("ph").split(" ")); -2535 Collections.addAll(forbidden, parts3.get("ph").split(" ")); -2536 n++; -2537 } -2538 if (rng.nextDouble() < 0.94) { -2539 missingSounds.add("kh"); -2540 Collections.addAll(forbidden, parts1.get("kh").split(" ")); -2541 Collections.addAll(forbidden, parts2.get("kh").split(" ")); -2542 Collections.addAll(forbidden, parts3.get("kh").split(" ")); -2543 n++; -2544 } -2545 if (rng.nextDouble() < 0.96) { -2546 missingSounds.add("bh"); -2547 missingSounds.add("dh"); -2548 Collections.addAll(forbidden, parts1.get("bh").split(" ")); -2549 Collections.addAll(forbidden, parts2.get("bh").split(" ")); -2550 Collections.addAll(forbidden, parts3.get("bh").split(" ")); -2551 Collections.addAll(forbidden, parts1.get("dh").split(" ")); -2552 Collections.addAll(forbidden, parts2.get("dh").split(" ")); -2553 Collections.addAll(forbidden, parts3.get("dh").split(" ")); -2554 n++; -2555 n++; -2556 } -2557 -2558 for (; n < sz * removalRate; n++) { -2559 missingSounds.add(parts1.keyAt(n)); -2560 missingSounds.add(parts2.keyAt(n)); -2561 missingSounds.add(parts3.keyAt(n)); -2562 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); -2563 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); -2564 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); -2565 } -2566 -2567 return new FakeLanguageGen( -2568 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), -2569 new String[]{"y", "y"}, -2570 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), -2571 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), -2572 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), -2573 new String[]{}, -2574 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); -2575 } -2576 -2577 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { -2578 CharSequence fixed = removeAccents(testing); -2579 for (int i = 0; i < checks.length; i++) { -2580 if (checks[i].matcher(fixed).find()) -2581 return false; -2582 } -2583 return true; -2584 } -2585 -2586 /** -2587 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text -2588 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives -2589 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers -2590 * that could look like letters. -2591 * @param testing the text, as a CharSequence such as a String, to check -2592 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't -2593 */ -2594 public static boolean checkVulgarity(CharSequence testing) -2595 { -2596 CharSequence fixed = removeAccents(testing); -2597 for (int i = 0; i < vulgarChecks.length; i++) { -2598 if (vulgarChecks[i].matcher(fixed).find()) -2599 { -2600 System.out.println(vulgarChecks[i]); -2601 return true; -2602 } -2603 } -2604 return false; -2605 } -2606 -2607 /** -2608 * Generate a word from this FakeLanguageGen, using and changing the current seed. -2609 * -2610 * @param capitalize true if the word should start with a capital letter, false otherwise -2611 * @return a word in the fake language as a String -2612 */ -2613 public String word(boolean capitalize) { -2614 return word(srng, capitalize); -2615 } -2616 -2617 /** -2618 * Generate a word from this FakeLanguageGen using the specified RNG. -2619 * -2620 * @param rng the RNG to use for the randomized string building -2621 * @param capitalize true if the word should start with a capital letter, false otherwise -2622 * @return a word in the fake language as a String -2623 */ -2624 public String word(RNG rng, boolean capitalize) { -2625 while (true) { -2626 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2627 double syllableChance = rng.nextDouble(totalSyllableFrequency); -2628 int syllables = 1, i = 0; -2629 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { -2630 if (syllableChance < kv.getDoubleValue()) { -2631 syllables = kv.getIntKey(); -2632 break; -2633 } else -2634 syllableChance -= kv.getDoubleValue(); -2635 } -2636 if (rng.nextDouble() < vowelStartFrequency) { -2637 sb.append(rng.getRandomElement(openingVowels)); -2638 if (syllables == 1) -2639 sb.append(rng.getRandomElement(closingConsonants)); -2640 else -2641 sb.append(rng.getRandomElement(midConsonants)); -2642 i++; -2643 } else { -2644 sb.append(rng.getRandomElement(openingConsonants)); -2645 } -2646 String close = ""; -2647 boolean redouble = false; -2648 if (i < syllables) { -2649 if (rng.nextDouble() < syllableEndFrequency) { -2650 close = rng.getRandomElement(closingSyllables); -2651 if (close.contains("@") && (syllables & 1) == 0) { -2652 redouble = true; -2653 syllables = (syllables | 1) >> 1; +2175 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2176 * at the start of a word; elements may be repeated to make them more common +2177 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2178 * between vowels; all closingConsonants are automatically copied into this internally. +2179 * Elements may be repeated to make them more common +2180 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2181 * at the end of a word; elements may be repeated to make them more common +2182 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2183 * whatever the word should end in; elements may be repeated to make them more common +2184 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2185 * then "a-a" may be possible; elements may be repeated to make them more common +2186 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2187 * tied to syllableFrequencies +2188 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2189 * represents how often each syllable count should appear relative to other counts; there +2190 * is no need to restrict the numbers to add up to any other number +2191 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2192 * higher numbers yield more words starting with vowels +2193 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2194 * numbers yield more words ending in vowels +2195 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2196 * often a vowel will be split into two vowels separated by one of those splitters +2197 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2198 * closingSyllables is used instead of ending normally +2199 */ +2200 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2201 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2202 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2203 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { +2204 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, +2205 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, +2206 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); +2207 } +2208 +2209 /** +2210 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2211 * class, LOVECRAFT and GREEK_ROMANIZED. +2212 * +2213 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2214 * of a word or in the middle; elements may be repeated to make them more common +2215 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2216 * middle of the word; all openingVowels are automatically copied into this internally. +2217 * Elements may be repeated to make them more common +2218 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2219 * at the start of a word; elements may be repeated to make them more common +2220 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2221 * between vowels; all closingConsonants are automatically copied into this internally. +2222 * Elements may be repeated to make them more common +2223 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2224 * at the end of a word; elements may be repeated to make them more common +2225 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2226 * whatever the word should end in; elements may be repeated to make them more common +2227 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2228 * then "a-a" may be possible; elements may be repeated to make them more common +2229 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2230 * tied to syllableFrequencies +2231 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2232 * represents how often each syllable count should appear relative to other counts; there +2233 * is no need to restrict the numbers to add up to any other number +2234 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2235 * higher numbers yield more words starting with vowels +2236 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2237 * numbers yield more words ending in vowels +2238 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2239 * often a vowel will be split into two vowels separated by one of those splitters +2240 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2241 * closingSyllables is used instead of ending normally +2242 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many +2243 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets +2244 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a +2245 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly +2246 */ +2247 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2248 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2249 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2250 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, +2251 Pattern[] sane, boolean clean) { +2252 this.openingVowels = openingVowels; +2253 this.midVowels = new String[openingVowels.length + midVowels.length]; +2254 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); +2255 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); +2256 this.openingConsonants = openingConsonants; +2257 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; +2258 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); +2259 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); +2260 this.closingConsonants = closingConsonants; +2261 this.vowelSplitters = vowelSplitters; +2262 this.closingSyllables = closingSyllables; +2263 +2264 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); +2265 +2266 totalSyllableFrequency = this.syllableFrequencies.values().sum(); +2267 if (vowelStartFrequency > 1.0) +2268 this.vowelStartFrequency = 1.0 / vowelStartFrequency; +2269 else +2270 this.vowelStartFrequency = vowelStartFrequency; +2271 if (vowelEndFrequency > 1.0) +2272 this.vowelEndFrequency = 1.0 / vowelEndFrequency; +2273 else +2274 this.vowelEndFrequency = vowelEndFrequency; +2275 if (vowelSplitters.length == 0) +2276 this.vowelSplitFrequency = 0.0; +2277 else if (vowelSplitFrequency > 1.0) +2278 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; +2279 else +2280 this.vowelSplitFrequency = vowelSplitFrequency; +2281 if (closingSyllables.length == 0) +2282 this.syllableEndFrequency = 0.0; +2283 else if (syllableEndFrequency > 1.0) +2284 this.syllableEndFrequency = 1.0 / syllableEndFrequency; +2285 else +2286 this.syllableEndFrequency = syllableEndFrequency; +2287 this.clean = clean; +2288 sanityChecks = sane; +2289 modifiers = new ArrayList<>(16); +2290 } +2291 +2292 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2293 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, +2294 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, +2295 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, +2296 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, +2297 List<Modifier> modifiers) { +2298 this.openingVowels = copyStrings(openingVowels); +2299 this.midVowels = copyStrings(midVowels); +2300 this.openingConsonants = copyStrings(openingConsonants); +2301 this.midConsonants = copyStrings(midConsonants); +2302 this.closingConsonants = copyStrings(closingConsonants); +2303 this.closingSyllables = copyStrings(closingSyllables); +2304 this.vowelSplitters = copyStrings(vowelSplitters); +2305 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); +2306 this.vowelStartFrequency = vowelStartFrequency; +2307 this.vowelEndFrequency = vowelEndFrequency; +2308 this.vowelSplitFrequency = vowelSplitFrequency; +2309 this.syllableEndFrequency = syllableEndFrequency; +2310 for (Double freq : this.syllableFrequencies.values()) { +2311 totalSyllableFrequency += freq; +2312 } +2313 if (sanityChecks == null) +2314 this.sanityChecks = null; +2315 else { +2316 this.sanityChecks = new Pattern[sanityChecks.length]; +2317 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); +2318 } +2319 this.clean = clean; +2320 this.modifiers = new ArrayList<>(modifiers); +2321 } +2322 +2323 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, +2324 Set<String> forbidden, RNG rng, double repeatSingleChance, +2325 int preferredLimit) { +2326 int l, sz = parts.size(); +2327 List<String> working = new ArrayList<>(sz * 24); +2328 String pair; +2329 for (int e = 0; e < parts.size(); e++) { +2330 Map.Entry<String, String> sn = parts.entryAt(e); +2331 if (missingSounds.contains(sn.getKey())) +2332 continue; +2333 for (String t : sn.getValue().split(" ")) { +2334 if (forbidden.contains(t)) +2335 continue; +2336 l = t.length(); +2337 int num; +2338 char c; +2339 switch (l) { +2340 case 0: +2341 break; +2342 case 1: +2343 working.add(t); +2344 working.add(t); +2345 working.add(t); +2346 c = t.charAt(0); +2347 num = 0; +2348 boolean repeat = true; +2349 switch (c) { +2350 case 'w': +2351 num += 2; +2352 case 'y': +2353 case 'h': +2354 num += 4; +2355 case 'q': +2356 case 'x': +2357 num += 4; +2358 repeat = false; +2359 break; +2360 case 'i': +2361 case 'u': +2362 repeat = false; +2363 num = 13; +2364 break; +2365 case 'z': +2366 case 'v': +2367 num = 4; +2368 break; +2369 case 'j': +2370 num = 7; +2371 break; +2372 default: +2373 if (e >= preferredLimit) +2374 num = 6; +2375 else +2376 num = 13; +2377 } +2378 for (int i = 0; i < num * 3; i++) { +2379 if (rng.nextDouble() < 0.75) { +2380 working.add(t); +2381 } +2382 } +2383 +2384 if (repeat && rng.nextDouble() < repeatSingleChance) { +2385 pair = t + t; +2386 if (missingSounds.contains(pair)) +2387 continue; +2388 working.add(pair); +2389 working.add(pair); +2390 working.add(pair); +2391 if (rng.nextDouble() < 0.7) { +2392 working.add(pair); +2393 working.add(pair); +2394 } +2395 if (rng.nextDouble() < 0.7) { +2396 working.add(pair); +2397 } +2398 } +2399 +2400 break; +2401 case 2: +2402 if (rng.nextDouble() < 0.65) { +2403 c = t.charAt(1); +2404 num = 0; +2405 switch (c) { +2406 case 'z': +2407 num = 1; +2408 break; +2409 case 'w': +2410 num = 3; +2411 break; +2412 case 'n': +2413 num = 4; +2414 break; +2415 default: +2416 +2417 if (e >= preferredLimit) +2418 num = 2; +2419 else +2420 num = 7; +2421 } +2422 working.add(t); +2423 for (int i = 0; i < num; i++) { +2424 if (rng.nextDouble() < 0.25) { +2425 working.add(t); +2426 } +2427 } +2428 } +2429 break; +2430 case 3: +2431 if (rng.nextDouble() < 0.5) { +2432 c = t.charAt(0); +2433 switch (c) { +2434 case 'z': +2435 num = 1; +2436 break; +2437 case 'w': +2438 num = 3; +2439 break; +2440 case 'n': +2441 num = 4; +2442 break; +2443 default: +2444 if (e >= preferredLimit) +2445 num = 2; +2446 else +2447 num = 6; +2448 } +2449 working.add(t); +2450 for (int i = 0; i < num; i++) { +2451 if (rng.nextDouble() < 0.2) { +2452 working.add(t); +2453 } +2454 } +2455 } +2456 break; +2457 default: +2458 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { +2459 working.add(t); +2460 } +2461 break; +2462 } +2463 } +2464 } +2465 return working.toArray(new String[0]); +2466 } +2467 +2468 /*private static final String[][] openVowels = new String[][]{ +2469 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, +2470 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, +2471 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, +2472 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, +2473 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, +2474 }; +2475*/ +2476 +2477 public static FakeLanguageGen randomLanguage(RNG rng) { +2478 return randomLanguage(rng.nextLong()); +2479 } +2480 +2481 public static FakeLanguageGen randomLanguage(long seed) { +2482 StatefulRNG rng = new StatefulRNG(seed); +2483 int[] lengths = new int[rng.between(3, 5)]; +2484 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); +2485 double[] chances = new double[lengths.length]; +2486 System.arraycopy(new double[]{ +2487 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) +2488 }, 0, chances, 0, chances.length); +2489 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); +2490 int sz = openCons.size(); +2491 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); +2492 OrderedMap<String, String> +2493 parts0 = new OrderedMap<>(openVowels), +2494 parts1 = new OrderedMap<>(openCons), +2495 parts2 = new OrderedMap<>(midCons), +2496 parts3 = new OrderedMap<>(closeCons); +2497 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); +2498 parts1.reorder(reordering); +2499 parts2.reorder(reordering); +2500 parts3.reorder(reordering); +2501 parts0.reorder(vOrd); +2502 int n = 0; +2503 +2504 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; +2505 +2506 for (n = 0; n < mn; n++) { +2507 missingSounds.add(parts0.keyAt(0)); +2508 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); +2509 parts0.removeFirst(); +2510 } +2511 p0s = parts0.size(); +2512 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); +2513 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; +2514 int vowelAccent = rng.between(1, 7); +2515 for (int i = 0; i < sz0; i++) { +2516 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; +2517 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; +2518 } +2519 if (rng.nextDouble() < 0.8) { +2520 for (int i = 0; i < sz0; i++) { +2521 char ac = nextAccents[i], ua = unaccented[i]; +2522 String v = "", uas = String.valueOf(ua); +2523 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); +2524 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); +2525 for (int j = 0; j < p0s; j++) { +2526 String k = parts0.keyAt(j); +2527 if (uas.equals(k)) +2528 v = parts0.getAt(j); +2529 else { +2530 String current = parts0.getAt(j); +2531 String[] splits = current.split(" "); +2532 for (int s = 0; s < splits.length; s++) { +2533 if (forbidden.contains(uas) && splits[s].contains(uas)) +2534 forbidden.add(splits[s].replace(ua, ac)); +2535 } +2536 parts0.put(k, rep.replace(current)); +2537 } +2538 } +2539 parts0.put(String.valueOf(ac), repLess.replace(v)); +2540 } +2541 } +2542 +2543 n = 0; +2544 if (rng.nextDouble() < 0.75) { +2545 missingSounds.add("z"); +2546 Collections.addAll(forbidden, parts1.get("z").split(" ")); +2547 Collections.addAll(forbidden, parts2.get("z").split(" ")); +2548 Collections.addAll(forbidden, parts3.get("z").split(" ")); +2549 n++; +2550 } +2551 if (rng.nextDouble() < 0.82) { +2552 missingSounds.add("x"); +2553 Collections.addAll(forbidden, parts1.get("x").split(" ")); +2554 Collections.addAll(forbidden, parts2.get("x").split(" ")); +2555 Collections.addAll(forbidden, parts3.get("x").split(" ")); +2556 n++; +2557 } +2558 if (rng.nextDouble() < 0.92) { +2559 missingSounds.add("qu"); +2560 Collections.addAll(forbidden, parts1.get("qu").split(" ")); +2561 Collections.addAll(forbidden, parts2.get("qu").split(" ")); +2562 Collections.addAll(forbidden, parts3.get("qu").split(" ")); +2563 n++; +2564 } +2565 if (rng.nextDouble() < 0.96) { +2566 missingSounds.add("q"); +2567 Collections.addAll(forbidden, parts1.get("q").split(" ")); +2568 Collections.addAll(forbidden, parts2.get("q").split(" ")); +2569 Collections.addAll(forbidden, parts3.get("q").split(" ")); +2570 n++; +2571 } +2572 if (rng.nextDouble() < 0.97) { +2573 missingSounds.add("tl"); +2574 Collections.addAll(forbidden, parts1.get("tl").split(" ")); +2575 Collections.addAll(forbidden, parts2.get("tl").split(" ")); +2576 Collections.addAll(forbidden, parts3.get("tl").split(" ")); +2577 n++; +2578 } +2579 if (rng.nextDouble() < 0.86) { +2580 missingSounds.add("ph"); +2581 Collections.addAll(forbidden, parts1.get("ph").split(" ")); +2582 Collections.addAll(forbidden, parts2.get("ph").split(" ")); +2583 Collections.addAll(forbidden, parts3.get("ph").split(" ")); +2584 n++; +2585 } +2586 if (rng.nextDouble() < 0.94) { +2587 missingSounds.add("kh"); +2588 Collections.addAll(forbidden, parts1.get("kh").split(" ")); +2589 Collections.addAll(forbidden, parts2.get("kh").split(" ")); +2590 Collections.addAll(forbidden, parts3.get("kh").split(" ")); +2591 n++; +2592 } +2593 if (rng.nextDouble() < 0.96) { +2594 missingSounds.add("bh"); +2595 missingSounds.add("dh"); +2596 Collections.addAll(forbidden, parts1.get("bh").split(" ")); +2597 Collections.addAll(forbidden, parts2.get("bh").split(" ")); +2598 Collections.addAll(forbidden, parts3.get("bh").split(" ")); +2599 Collections.addAll(forbidden, parts1.get("dh").split(" ")); +2600 Collections.addAll(forbidden, parts2.get("dh").split(" ")); +2601 Collections.addAll(forbidden, parts3.get("dh").split(" ")); +2602 n++; +2603 n++; +2604 } +2605 +2606 for (; n < sz * removalRate; n++) { +2607 missingSounds.add(parts1.keyAt(n)); +2608 missingSounds.add(parts2.keyAt(n)); +2609 missingSounds.add(parts3.keyAt(n)); +2610 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); +2611 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); +2612 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); +2613 } +2614 +2615 return new FakeLanguageGen( +2616 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), +2617 new String[]{"y", "y"}, +2618 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), +2619 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), +2620 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), +2621 new String[]{}, +2622 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); +2623 } +2624 +2625 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { +2626 CharSequence fixed = removeAccents(testing); +2627 for (int i = 0; i < checks.length; i++) { +2628 if (checks[i].matcher(fixed).find()) +2629 return false; +2630 } +2631 return true; +2632 } +2633 +2634 /** +2635 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text +2636 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives +2637 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers +2638 * that could look like letters. +2639 * @param testing the text, as a CharSequence such as a String, to check +2640 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't +2641 */ +2642 public static boolean checkVulgarity(CharSequence testing) +2643 { +2644 CharSequence fixed = removeAccents(testing); +2645 for (int i = 0; i < vulgarChecks.length; i++) { +2646 if (vulgarChecks[i].matcher(fixed).find()) +2647 { +2648 System.out.println(vulgarChecks[i]); +2649 return true; +2650 } +2651 } +2652 return false; +2653 } 2654 -2655 //sb.append(close.replaceAll("@\\d", sb.toString())); -2656 } -2657 if (!close.contains("@")) -2658 ender.append(close); -2659 else if (rng.nextDouble() < vowelEndFrequency) { -2660 ender.append(rng.getRandomElement(midVowels)); -2661 if (rng.nextDouble() < vowelSplitFrequency) { -2662 ender.append(rng.getRandomElement(vowelSplitters)); -2663 ender.append(rng.getRandomElement(midVowels)); -2664 } -2665 } -2666 } else { -2667 ender.append(rng.getRandomElement(midVowels)); -2668 if (rng.nextDouble() < vowelSplitFrequency) { -2669 ender.append(rng.getRandomElement(vowelSplitters)); -2670 ender.append(rng.getRandomElement(midVowels)); -2671 } -2672 if (rng.nextDouble() >= vowelEndFrequency) { -2673 ender.append(rng.getRandomElement(closingConsonants)); -2674 if (rng.nextDouble() < syllableEndFrequency) { -2675 close = rng.getRandomElement(closingSyllables); -2676 if (close.contains("@") && (syllables & 1) == 0) { -2677 redouble = true; -2678 syllables = (syllables | 1) >> 1; -2679 -2680 //sb.append(close.replaceAll("@\\d", sb.toString())); -2681 } -2682 if (!close.contains("@")) -2683 ender.append(close); -2684 } -2685 } -2686 } -2687 i += vowelClusters.matcher(ender).findAll().count(); -2688 -2689 } -2690 -2691 for (; i < syllables; i++) { -2692 sb.append(rng.getRandomElement(midVowels)); -2693 if (rng.nextDouble() < vowelSplitFrequency) { -2694 sb.append(rng.getRandomElement(vowelSplitters)); -2695 sb.append(rng.getRandomElement(midVowels)); -2696 } -2697 sb.append(rng.getRandomElement(midConsonants)); -2698 } -2699 -2700 sb.append(ender); -2701 if (redouble && i <= syllables + 1) { -2702 sb.append(close.replaceAll("@", sb.toString())); -2703 } -2704 -2705 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2706 continue; -2707 -2708 for (Modifier mod : modifiers) { -2709 sb = mod.modify(rng, sb); -2710 } -2711 -2712 if (capitalize) -2713 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2714 -2715 if (clean && !checkAll(sb, vulgarChecks)) -2716 continue; -2717 return sb.toString(); -2718 } -2719 } -2720 -2721 /** -2722 * Generate a word from this FakeLanguageGen using the specified RNG. -2723 * -2724 * @param rng the RNG to use for the randomized string building -2725 * @param capitalize true if the word should start with a capital letter, false otherwise -2726 * @return a word in the fake language as a String -2727 */ -2728 public String word(RNG rng, boolean capitalize, int approxSyllables) { -2729 return word(rng, capitalize, approxSyllables, null); -2730 } -2731 -2732 /** -2733 * Generate a word from this FakeLanguageGen using the specified RNG. -2734 * -2735 * @param rng the RNG to use for the randomized string building -2736 * @param capitalize true if the word should start with a capital letter, false otherwise -2737 * @return a word in the fake language as a String -2738 */ -2739 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { -2740 if (approxSyllables <= 0) { -2741 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2742 for (Modifier mod : modifiers) { -2743 sb = mod.modify(rng, sb); -2744 } -2745 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2746 return sb.toString(); -2747 } -2748 while (true) { -2749 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2750 int i = 0; -2751 if (rng.nextDouble() < vowelStartFrequency) { -2752 sb.append(rng.getRandomElement(openingVowels)); -2753 if (approxSyllables == 1 && closingConsonants.length > 0) -2754 sb.append(rng.getRandomElement(closingConsonants)); -2755 else if (midConsonants.length > 0) -2756 sb.append(rng.getRandomElement(midConsonants)); -2757 i++; -2758 } else if (openingConsonants.length > 0) { -2759 sb.append(rng.getRandomElement(openingConsonants)); -2760 } -2761 String close = ""; -2762 boolean redouble = false; -2763 if (i < approxSyllables) { -2764 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { -2765 close = rng.getRandomElement(closingSyllables); -2766 if (close.contains("@") && (approxSyllables & 1) == 0) { -2767 redouble = true; -2768 approxSyllables = approxSyllables >> 1; -2769 -2770 //sb.append(close.replaceAll("@\\d", sb.toString())); -2771 } -2772 if (!close.contains("@")) -2773 ender.append(close); -2774 else if (redouble && rng.nextDouble() < vowelEndFrequency) { -2775 ender.append(rng.getRandomElement(midVowels)); -2776 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { -2777 ender.append(rng.getRandomElement(vowelSplitters)); -2778 ender.append(rng.getRandomElement(midVowels)); -2779 } -2780 } -2781 } else { -2782 ender.append(rng.getRandomElement(midVowels)); -2783 if (rng.nextDouble() < vowelSplitFrequency) { -2784 ender.append(rng.getRandomElement(vowelSplitters)); -2785 ender.append(rng.getRandomElement(midVowels)); -2786 } -2787 if (rng.nextDouble() >= vowelEndFrequency) { -2788 ender.append(rng.getRandomElement(closingConsonants)); -2789 if (rng.nextDouble() < syllableEndFrequency) { -2790 close = rng.getRandomElement(closingSyllables); -2791 if (close.contains("@") && (approxSyllables & 1) == 0) { -2792 redouble = true; -2793 approxSyllables = approxSyllables >> 1; -2794 -2795 //sb.append(close.replaceAll("@\\d", sb.toString())); -2796 } -2797 if (!close.contains("@")) -2798 ender.append(close); -2799 } -2800 } -2801 } -2802 i += vowelClusters.matcher(ender).findAll().count(); -2803 } -2804 -2805 for (; i < approxSyllables; i++) { -2806 sb.append(rng.getRandomElement(midVowels)); -2807 if (rng.nextDouble() < vowelSplitFrequency) { -2808 sb.append(rng.getRandomElement(vowelSplitters)); -2809 sb.append(rng.getRandomElement(midVowels)); -2810 } -2811 sb.append(rng.getRandomElement(midConsonants)); -2812 } -2813 -2814 sb.append(ender); -2815 if (redouble && i <= approxSyllables + 1) { -2816 sb.append(close.replaceAll("@", sb.toString())); -2817 } -2818 -2819 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2820 continue; -2821 -2822 for (Modifier mod : modifiers) { -2823 sb = mod.modify(rng, sb); -2824 } -2825 -2826 if (clean && !checkAll(sb, vulgarChecks)) -2827 continue; -2828 -2829 if (additionalChecks != null && !checkAll(sb, additionalChecks)) -2830 continue; -2831 -2832 if (capitalize) -2833 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2834 -2835 return sb.toString(); -2836 } -2837 } -2838 -2839 /** -2840 * Generate a word from this FakeLanguageGen using the specified RNG. -2841 * -2842 * @param rng the RNG to use for the randomized string building -2843 * @param capitalize true if the word should start with a capital letter, false otherwise -2844 * @return a word in the fake language as a String -2845 */ -2846 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { -2847 if (approxSyllables <= 0) { -2848 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2849 for (Modifier mod : modifiers) { -2850 sb = mod.modify(rng, sb); +2655 /** +2656 * Generate a word from this FakeLanguageGen, using and changing the current seed. +2657 * +2658 * @param capitalize true if the word should start with a capital letter, false otherwise +2659 * @return a word in the fake language as a String +2660 */ +2661 public String word(boolean capitalize) { +2662 return word(srng, capitalize); +2663 } +2664 +2665 /** +2666 * Generate a word from this FakeLanguageGen using the specified RNG. +2667 * +2668 * @param rng the RNG to use for the randomized string building +2669 * @param capitalize true if the word should start with a capital letter, false otherwise +2670 * @return a word in the fake language as a String +2671 */ +2672 public String word(RNG rng, boolean capitalize) { +2673 while (true) { +2674 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2675 double syllableChance = rng.nextDouble(totalSyllableFrequency); +2676 int syllables = 1, i = 0; +2677 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { +2678 if (syllableChance < kv.getDoubleValue()) { +2679 syllables = kv.getIntKey(); +2680 break; +2681 } else +2682 syllableChance -= kv.getDoubleValue(); +2683 } +2684 if (rng.nextDouble() < vowelStartFrequency) { +2685 sb.append(rng.getRandomElement(openingVowels)); +2686 if (syllables == 1) +2687 sb.append(rng.getRandomElement(closingConsonants)); +2688 else +2689 sb.append(rng.getRandomElement(midConsonants)); +2690 i++; +2691 } else { +2692 sb.append(rng.getRandomElement(openingConsonants)); +2693 } +2694 String close = ""; +2695 boolean redouble = false; +2696 if (i < syllables) { +2697 if (rng.nextDouble() < syllableEndFrequency) { +2698 close = rng.getRandomElement(closingSyllables); +2699 if (close.contains("@") && (syllables & 1) == 0) { +2700 redouble = true; +2701 syllables = (syllables | 1) >> 1; +2702 +2703 //sb.append(close.replaceAll("@\\d", sb.toString())); +2704 } +2705 if (!close.contains("@")) +2706 ender.append(close); +2707 else if (rng.nextDouble() < vowelEndFrequency) { +2708 ender.append(rng.getRandomElement(midVowels)); +2709 if (rng.nextDouble() < vowelSplitFrequency) { +2710 ender.append(rng.getRandomElement(vowelSplitters)); +2711 ender.append(rng.getRandomElement(midVowels)); +2712 } +2713 } +2714 } else { +2715 ender.append(rng.getRandomElement(midVowels)); +2716 if (rng.nextDouble() < vowelSplitFrequency) { +2717 ender.append(rng.getRandomElement(vowelSplitters)); +2718 ender.append(rng.getRandomElement(midVowels)); +2719 } +2720 if (rng.nextDouble() >= vowelEndFrequency) { +2721 ender.append(rng.getRandomElement(closingConsonants)); +2722 if (rng.nextDouble() < syllableEndFrequency) { +2723 close = rng.getRandomElement(closingSyllables); +2724 if (close.contains("@") && (syllables & 1) == 0) { +2725 redouble = true; +2726 syllables = (syllables | 1) >> 1; +2727 +2728 //sb.append(close.replaceAll("@\\d", sb.toString())); +2729 } +2730 if (!close.contains("@")) +2731 ender.append(close); +2732 } +2733 } +2734 } +2735 i += vowelClusters.matcher(ender).findAll().count(); +2736 +2737 } +2738 +2739 for (; i < syllables; i++) { +2740 sb.append(rng.getRandomElement(midVowels)); +2741 if (rng.nextDouble() < vowelSplitFrequency) { +2742 sb.append(rng.getRandomElement(vowelSplitters)); +2743 sb.append(rng.getRandomElement(midVowels)); +2744 } +2745 sb.append(rng.getRandomElement(midConsonants)); +2746 } +2747 +2748 sb.append(ender); +2749 if (redouble && i <= syllables + 1) { +2750 sb.append(close.replaceAll("@", sb.toString())); +2751 } +2752 +2753 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2754 continue; +2755 +2756 for (Modifier mod : modifiers) { +2757 sb = mod.modify(rng, sb); +2758 } +2759 +2760 if (capitalize) +2761 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2762 +2763 if (clean && !checkAll(sb, vulgarChecks)) +2764 continue; +2765 return sb.toString(); +2766 } +2767 } +2768 +2769 /** +2770 * Generate a word from this FakeLanguageGen using the specified RNG. +2771 * +2772 * @param rng the RNG to use for the randomized string building +2773 * @param capitalize true if the word should start with a capital letter, false otherwise +2774 * @return a word in the fake language as a String +2775 */ +2776 public String word(RNG rng, boolean capitalize, int approxSyllables) { +2777 return word(rng, capitalize, approxSyllables, null); +2778 } +2779 +2780 /** +2781 * Generate a word from this FakeLanguageGen using the specified RNG. +2782 * +2783 * @param rng the RNG to use for the randomized string building +2784 * @param capitalize true if the word should start with a capital letter, false otherwise +2785 * @return a word in the fake language as a String +2786 */ +2787 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { +2788 if (approxSyllables <= 0) { +2789 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2790 for (Modifier mod : modifiers) { +2791 sb = mod.modify(rng, sb); +2792 } +2793 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2794 return sb.toString(); +2795 } +2796 while (true) { +2797 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2798 int i = 0; +2799 if (rng.nextDouble() < vowelStartFrequency) { +2800 sb.append(rng.getRandomElement(openingVowels)); +2801 if (approxSyllables == 1 && closingConsonants.length > 0) +2802 sb.append(rng.getRandomElement(closingConsonants)); +2803 else if (midConsonants.length > 0) +2804 sb.append(rng.getRandomElement(midConsonants)); +2805 i++; +2806 } else if (openingConsonants.length > 0) { +2807 sb.append(rng.getRandomElement(openingConsonants)); +2808 } +2809 String close = ""; +2810 boolean redouble = false; +2811 if (i < approxSyllables) { +2812 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { +2813 close = rng.getRandomElement(closingSyllables); +2814 if (close.contains("@") && (approxSyllables & 1) == 0) { +2815 redouble = true; +2816 approxSyllables = approxSyllables >> 1; +2817 +2818 //sb.append(close.replaceAll("@\\d", sb.toString())); +2819 } +2820 if (!close.contains("@")) +2821 ender.append(close); +2822 else if (redouble && rng.nextDouble() < vowelEndFrequency) { +2823 ender.append(rng.getRandomElement(midVowels)); +2824 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { +2825 ender.append(rng.getRandomElement(vowelSplitters)); +2826 ender.append(rng.getRandomElement(midVowels)); +2827 } +2828 } +2829 } else { +2830 ender.append(rng.getRandomElement(midVowels)); +2831 if (rng.nextDouble() < vowelSplitFrequency) { +2832 ender.append(rng.getRandomElement(vowelSplitters)); +2833 ender.append(rng.getRandomElement(midVowels)); +2834 } +2835 if (rng.nextDouble() >= vowelEndFrequency) { +2836 ender.append(rng.getRandomElement(closingConsonants)); +2837 if (rng.nextDouble() < syllableEndFrequency) { +2838 close = rng.getRandomElement(closingSyllables); +2839 if (close.contains("@") && (approxSyllables & 1) == 0) { +2840 redouble = true; +2841 approxSyllables = approxSyllables >> 1; +2842 +2843 //sb.append(close.replaceAll("@\\d", sb.toString())); +2844 } +2845 if (!close.contains("@")) +2846 ender.append(close); +2847 } +2848 } +2849 } +2850 i += vowelClusters.matcher(ender).findAll().count(); 2851 } -2852 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2853 return sb.toString(); -2854 } -2855 int numSeeds, fraction = 1; -2856 if (reseeds != null) -2857 numSeeds = Math.min(reseeds.length, approxSyllables - 1); -2858 else numSeeds = 0; -2859 while (true) { -2860 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2861 int i = 0; -2862 if (rng.nextDouble() < vowelStartFrequency) { -2863 sb.append(rng.getRandomElement(openingVowels)); -2864 if (approxSyllables == 1) -2865 sb.append(rng.getRandomElement(closingConsonants)); -2866 else -2867 sb.append(rng.getRandomElement(midConsonants)); -2868 i++; -2869 } else { -2870 sb.append(rng.getRandomElement(openingConsonants)); -2871 } -2872 String close = ""; -2873 boolean redouble = false; -2874 if (i < approxSyllables) { -2875 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2876 rng.setState(reseeds[fraction++ - 1]); -2877 if (rng.nextDouble() < syllableEndFrequency) { -2878 close = rng.getRandomElement(closingSyllables); -2879 if (close.contains("@") && (approxSyllables & 1) == 0) { -2880 redouble = true; -2881 approxSyllables = approxSyllables >> 1; -2882 } -2883 if (!close.contains("@")) -2884 ender.append(close); -2885 else if (rng.nextDouble() < vowelEndFrequency) { -2886 ender.append(rng.getRandomElement(midVowels)); -2887 if (rng.nextDouble() < vowelSplitFrequency) { -2888 ender.append(rng.getRandomElement(vowelSplitters)); -2889 ender.append(rng.getRandomElement(midVowels)); -2890 } -2891 } -2892 } else { -2893 ender.append(rng.getRandomElement(midVowels)); -2894 if (rng.nextDouble() < vowelSplitFrequency) { -2895 ender.append(rng.getRandomElement(vowelSplitters)); -2896 ender.append(rng.getRandomElement(midVowels)); -2897 } -2898 if (rng.nextDouble() >= vowelEndFrequency) { -2899 ender.append(rng.getRandomElement(closingConsonants)); -2900 if (rng.nextDouble() < syllableEndFrequency) { -2901 close = rng.getRandomElement(closingSyllables); -2902 if (close.contains("@") && (approxSyllables & 1) == 0) { -2903 redouble = true; -2904 approxSyllables = approxSyllables >> 1; -2905 -2906 //sb.append(close.replaceAll("@\\d", sb.toString())); -2907 } -2908 if (!close.contains("@")) -2909 ender.append(close); -2910 } -2911 } -2912 } -2913 i += vowelClusters.matcher(ender).findAll().count(); -2914 } -2915 -2916 for (; i < approxSyllables; i++) { -2917 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2918 rng.setState(reseeds[fraction++ - 1]); -2919 sb.append(rng.getRandomElement(midVowels)); -2920 if (rng.nextDouble() < vowelSplitFrequency) { -2921 sb.append(rng.getRandomElement(vowelSplitters)); -2922 sb.append(rng.getRandomElement(midVowels)); -2923 } -2924 sb.append(rng.getRandomElement(midConsonants)); -2925 } -2926 -2927 sb.append(ender); -2928 if (redouble && i <= approxSyllables + 1) { -2929 sb.append(close.replaceAll("@", sb.toString())); -2930 } -2931 -2932 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2933 continue; -2934 -2935 for (Modifier mod : modifiers) { -2936 sb = mod.modify(rng, sb); -2937 } -2938 -2939 if (capitalize) -2940 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2941 -2942 if (clean && !checkAll(sb, vulgarChecks)) -2943 continue; -2944 return sb.toString(); -2945 } -2946 } -2947 -2948 /** -2949 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2950 * -2951 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2952 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2953 * @return a sentence in the gibberish language as a String -2954 */ -2955 public String sentence(int minWords, int maxWords) { -2956 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2957 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2958 } -2959 -2960 /** -2961 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2962 * -2963 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2964 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2965 * @return a sentence in the gibberish language as a String -2966 */ -2967 public String sentence(RNG rng, int minWords, int maxWords) { -2968 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2969 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2970 } -2971 -2972 /** -2973 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2974 * -2975 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2976 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2977 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2978 * space in the middle of a sentence -2979 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2980 * the very end of a sentence -2981 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -2982 * midPunctuation should be inserted before spaces -2983 * @return a sentence in the gibberish language as a String -2984 */ -2985 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -2986 double midPunctuationFrequency) { -2987 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -2988 } +2852 +2853 for (; i < approxSyllables; i++) { +2854 sb.append(rng.getRandomElement(midVowels)); +2855 if (rng.nextDouble() < vowelSplitFrequency) { +2856 sb.append(rng.getRandomElement(vowelSplitters)); +2857 sb.append(rng.getRandomElement(midVowels)); +2858 } +2859 sb.append(rng.getRandomElement(midConsonants)); +2860 } +2861 +2862 sb.append(ender); +2863 if (redouble && i <= approxSyllables + 1) { +2864 sb.append(close.replaceAll("@", sb.toString())); +2865 } +2866 +2867 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2868 continue; +2869 +2870 for (Modifier mod : modifiers) { +2871 sb = mod.modify(rng, sb); +2872 } +2873 +2874 if (clean && !checkAll(sb, vulgarChecks)) +2875 continue; +2876 +2877 if (additionalChecks != null && !checkAll(sb, additionalChecks)) +2878 continue; +2879 +2880 if (capitalize) +2881 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2882 +2883 return sb.toString(); +2884 } +2885 } +2886 +2887 /** +2888 * Generate a word from this FakeLanguageGen using the specified RNG. +2889 * +2890 * @param rng the RNG to use for the randomized string building +2891 * @param capitalize true if the word should start with a capital letter, false otherwise +2892 * @return a word in the fake language as a String +2893 */ +2894 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { +2895 if (approxSyllables <= 0) { +2896 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2897 for (Modifier mod : modifiers) { +2898 sb = mod.modify(rng, sb); +2899 } +2900 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2901 return sb.toString(); +2902 } +2903 int numSeeds, fraction = 1; +2904 if (reseeds != null) +2905 numSeeds = Math.min(reseeds.length, approxSyllables - 1); +2906 else numSeeds = 0; +2907 while (true) { +2908 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2909 int i = 0; +2910 if (rng.nextDouble() < vowelStartFrequency) { +2911 sb.append(rng.getRandomElement(openingVowels)); +2912 if (approxSyllables == 1) +2913 sb.append(rng.getRandomElement(closingConsonants)); +2914 else +2915 sb.append(rng.getRandomElement(midConsonants)); +2916 i++; +2917 } else { +2918 sb.append(rng.getRandomElement(openingConsonants)); +2919 } +2920 String close = ""; +2921 boolean redouble = false; +2922 if (i < approxSyllables) { +2923 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2924 rng.setState(reseeds[fraction++ - 1]); +2925 if (rng.nextDouble() < syllableEndFrequency) { +2926 close = rng.getRandomElement(closingSyllables); +2927 if (close.contains("@") && (approxSyllables & 1) == 0) { +2928 redouble = true; +2929 approxSyllables = approxSyllables >> 1; +2930 } +2931 if (!close.contains("@")) +2932 ender.append(close); +2933 else if (rng.nextDouble() < vowelEndFrequency) { +2934 ender.append(rng.getRandomElement(midVowels)); +2935 if (rng.nextDouble() < vowelSplitFrequency) { +2936 ender.append(rng.getRandomElement(vowelSplitters)); +2937 ender.append(rng.getRandomElement(midVowels)); +2938 } +2939 } +2940 } else { +2941 ender.append(rng.getRandomElement(midVowels)); +2942 if (rng.nextDouble() < vowelSplitFrequency) { +2943 ender.append(rng.getRandomElement(vowelSplitters)); +2944 ender.append(rng.getRandomElement(midVowels)); +2945 } +2946 if (rng.nextDouble() >= vowelEndFrequency) { +2947 ender.append(rng.getRandomElement(closingConsonants)); +2948 if (rng.nextDouble() < syllableEndFrequency) { +2949 close = rng.getRandomElement(closingSyllables); +2950 if (close.contains("@") && (approxSyllables & 1) == 0) { +2951 redouble = true; +2952 approxSyllables = approxSyllables >> 1; +2953 +2954 //sb.append(close.replaceAll("@\\d", sb.toString())); +2955 } +2956 if (!close.contains("@")) +2957 ender.append(close); +2958 } +2959 } +2960 } +2961 i += vowelClusters.matcher(ender).findAll().count(); +2962 } +2963 +2964 for (; i < approxSyllables; i++) { +2965 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2966 rng.setState(reseeds[fraction++ - 1]); +2967 sb.append(rng.getRandomElement(midVowels)); +2968 if (rng.nextDouble() < vowelSplitFrequency) { +2969 sb.append(rng.getRandomElement(vowelSplitters)); +2970 sb.append(rng.getRandomElement(midVowels)); +2971 } +2972 sb.append(rng.getRandomElement(midConsonants)); +2973 } +2974 +2975 sb.append(ender); +2976 if (redouble && i <= approxSyllables + 1) { +2977 sb.append(close.replaceAll("@", sb.toString())); +2978 } +2979 +2980 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2981 continue; +2982 +2983 for (Modifier mod : modifiers) { +2984 sb = mod.modify(rng, sb); +2985 } +2986 +2987 if (capitalize) +2988 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); 2989 -2990 /** -2991 * Generate a sentence from this FakeLanguageGen using the specific RNG. -2992 * -2993 * @param rng the RNG to use for the randomized string building -2994 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2995 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2996 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2997 * space in the middle of a sentence -2998 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2999 * the very end of a sentence -3000 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3001 * midPunctuation should be inserted before spaces -3002 * @return a sentence in the gibberish language as a String -3003 */ -3004 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3005 double midPunctuationFrequency) { -3006 if (minWords < 1) -3007 minWords = 1; -3008 if (minWords > maxWords) -3009 maxWords = minWords; -3010 if (midPunctuationFrequency > 1.0) { -3011 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3012 } -3013 StringBuilder sb = new StringBuilder(12 * maxWords); -3014 sb.append(word(rng, true)); -3015 for (int i = 1; i < minWords; i++) { -3016 if (rng.nextDouble() < midPunctuationFrequency) { -3017 sb.append(rng.getRandomElement(midPunctuation)); -3018 } -3019 sb.append(' '); -3020 sb.append(word(rng, false)); -3021 } -3022 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { -3023 if (rng.nextDouble() < midPunctuationFrequency) { -3024 sb.append(rng.getRandomElement(midPunctuation)); -3025 } -3026 sb.append(' '); -3027 sb.append(word(rng, false)); -3028 } -3029 if (endPunctuation != null && endPunctuation.length > 0) -3030 sb.append(rng.getRandomElement(endPunctuation)); -3031 return sb.toString(); -3032 } -3033 -3034 /** -3035 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. -3036 * -3037 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3038 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3039 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3040 * space in the middle of a sentence -3041 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3042 * the very end of a sentence -3043 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3044 * midPunctuation should be inserted before spaces -3045 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3046 * @return a sentence in the gibberish language as a String -3047 */ -3048 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3049 double midPunctuationFrequency, int maxChars) { -3050 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); -3051 } -3052 -3053 /** -3054 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. -3055 * -3056 * @param rng the RNG to use for the randomized string building -3057 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3058 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3059 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3060 * space in the middle of a sentence -3061 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3062 * the very end of a sentence -3063 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3064 * midPunctuation should be inserted before spaces -3065 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3066 * @return a sentence in the gibberish language as a String -3067 */ -3068 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3069 double midPunctuationFrequency, int maxChars) { -3070 if(maxChars < 0) -3071 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -3072 if (minWords < 1) -3073 minWords = 1; -3074 if (minWords > maxWords) -3075 maxWords = minWords; -3076 if (midPunctuationFrequency > 1.0) { -3077 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3078 } -3079 if (maxChars < 4) -3080 return "!"; -3081 if (maxChars <= 5 * minWords) { -3082 minWords = 1; -3083 maxWords = 1; -3084 } -3085 int frustration = 0; -3086 StringBuilder sb = new StringBuilder(maxChars); -3087 String next = word(rng, true); -3088 while (next.length() >= maxChars - 1 && frustration < 50) { -3089 next = word(rng, true); -3090 frustration++; -3091 } -3092 if (frustration >= 50) return "!"; -3093 sb.append(next); -3094 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { -3095 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3096 sb.append(rng.getRandomElement(midPunctuation)); -3097 } -3098 next = word(rng, false); -3099 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3100 next = word(rng, false); -3101 frustration++; -3102 } -3103 if (frustration >= 50) break; -3104 sb.append(' '); -3105 sb.append(next); -3106 } -3107 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { -3108 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3109 sb.append(rng.getRandomElement(midPunctuation)); -3110 } -3111 next = word(rng, false); -3112 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3113 next = word(rng, false); -3114 frustration++; -3115 } -3116 if (frustration >= 50) break; -3117 sb.append(' '); -3118 sb.append(next); -3119 } -3120 -3121 if (endPunctuation != null && endPunctuation.length > 0) { -3122 -3123 next = rng.getRandomElement(endPunctuation); -3124 if (sb.length() + next.length() >= maxChars) -3125 sb.append('.'); -3126 else -3127 sb.append(next); -3128 } -3129 -3130 if (sb.length() > maxChars) -3131 return "!"; -3132 return sb.toString(); -3133 } -3134 -3135 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { -3136 if (other.length <= 0 && me.length <= 0) -3137 return new String[]{}; -3138 String[] ret = new String[1000]; -3139 int otherCount = (int) (1000 * otherInfluence); -3140 int idx = 0; -3141 if (other.length > 0) { -3142 String[] tmp = new String[other.length]; -3143 rng.shuffle(other, tmp); -3144 for (idx = 0; idx < otherCount; idx++) { -3145 ret[idx] = tmp[idx % tmp.length]; -3146 } -3147 } -3148 if (me.length > 0) { -3149 String[] tmp = new String[me.length]; -3150 rng.shuffle(me, tmp); -3151 for (; idx < 1000; idx++) { -3152 ret[idx] = tmp[idx % tmp.length]; -3153 } -3154 } else { -3155 for (; idx < 1000; idx++) { -3156 ret[idx] = other[idx % other.length]; -3157 } -3158 } -3159 return ret; -3160 } -3161 -3162 -3163 protected String[] accentVowels(RNG rng, String[] me, double influence) { -3164 String[] ret = new String[1000]; -3165 int otherCount = (int) (1000 * influence); -3166 int idx = 0; -3167 Matcher matcher; -3168 if (me.length > 0) { -3169 String[] tmp = new String[me.length]; -3170 rng.shuffle(me, tmp); -3171 for (idx = 0; idx < otherCount; idx++) { -3172 ret[idx] = tmp[idx % tmp.length] -3173 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3174 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3175 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3176 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3177 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3178 matcher = repeats.matcher(ret[idx]); -3179 if (matcher.find()) { -3180 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3181 } -3182 } -3183 for (; idx < 1000; idx++) { -3184 ret[idx] = tmp[idx % tmp.length]; -3185 } -3186 } else -3187 return new String[]{}; -3188 return ret; -3189 } -3190 -3191 protected String[] accentConsonants(RNG rng, String[] me, double influence) { -3192 String[] ret = new String[1000]; -3193 int otherCount = (int) (1000 * influence); -3194 int idx = 0; -3195 Matcher matcher; +2990 if (clean && !checkAll(sb, vulgarChecks)) +2991 continue; +2992 return sb.toString(); +2993 } +2994 } +2995 +2996 /** +2997 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +2998 * +2999 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3000 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3001 * @return a sentence in the gibberish language as a String +3002 */ +3003 public String sentence(int minWords, int maxWords) { +3004 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3005 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3006 } +3007 +3008 /** +3009 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3010 * +3011 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3012 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3013 * @return a sentence in the gibberish language as a String +3014 */ +3015 public String sentence(RNG rng, int minWords, int maxWords) { +3016 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3017 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3018 } +3019 +3020 /** +3021 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3022 * +3023 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3024 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3025 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3026 * space in the middle of a sentence +3027 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3028 * the very end of a sentence +3029 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3030 * midPunctuation should be inserted before spaces +3031 * @return a sentence in the gibberish language as a String +3032 */ +3033 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3034 double midPunctuationFrequency) { +3035 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3036 } +3037 +3038 /** +3039 * Generate a sentence from this FakeLanguageGen using the specific RNG. +3040 * +3041 * @param rng the RNG to use for the randomized string building +3042 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3043 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3044 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3045 * space in the middle of a sentence +3046 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3047 * the very end of a sentence +3048 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3049 * midPunctuation should be inserted before spaces +3050 * @return a sentence in the gibberish language as a String +3051 */ +3052 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3053 double midPunctuationFrequency) { +3054 if (minWords < 1) +3055 minWords = 1; +3056 if (minWords > maxWords) +3057 maxWords = minWords; +3058 if (midPunctuationFrequency > 1.0) { +3059 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3060 } +3061 StringBuilder sb = new StringBuilder(12 * maxWords); +3062 sb.append(word(rng, true)); +3063 for (int i = 1; i < minWords; i++) { +3064 if (rng.nextDouble() < midPunctuationFrequency) { +3065 sb.append(rng.getRandomElement(midPunctuation)); +3066 } +3067 sb.append(' '); +3068 sb.append(word(rng, false)); +3069 } +3070 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { +3071 if (rng.nextDouble() < midPunctuationFrequency) { +3072 sb.append(rng.getRandomElement(midPunctuation)); +3073 } +3074 sb.append(' '); +3075 sb.append(word(rng, false)); +3076 } +3077 if (endPunctuation != null && endPunctuation.length > 0) +3078 sb.append(rng.getRandomElement(endPunctuation)); +3079 return sb.toString(); +3080 } +3081 +3082 /** +3083 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. +3084 * +3085 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3086 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3087 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3088 * space in the middle of a sentence +3089 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3090 * the very end of a sentence +3091 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3092 * midPunctuation should be inserted before spaces +3093 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3094 * @return a sentence in the gibberish language as a String +3095 */ +3096 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3097 double midPunctuationFrequency, int maxChars) { +3098 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); +3099 } +3100 +3101 /** +3102 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. +3103 * +3104 * @param rng the RNG to use for the randomized string building +3105 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3106 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3107 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3108 * space in the middle of a sentence +3109 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3110 * the very end of a sentence +3111 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3112 * midPunctuation should be inserted before spaces +3113 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3114 * @return a sentence in the gibberish language as a String +3115 */ +3116 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3117 double midPunctuationFrequency, int maxChars) { +3118 if(maxChars < 0) +3119 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3120 if (minWords < 1) +3121 minWords = 1; +3122 if (minWords > maxWords) +3123 maxWords = minWords; +3124 if (midPunctuationFrequency > 1.0) { +3125 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3126 } +3127 if (maxChars < 4) +3128 return "!"; +3129 if (maxChars <= 5 * minWords) { +3130 minWords = 1; +3131 maxWords = 1; +3132 } +3133 int frustration = 0; +3134 StringBuilder sb = new StringBuilder(maxChars); +3135 String next = word(rng, true); +3136 while (next.length() >= maxChars - 1 && frustration < 50) { +3137 next = word(rng, true); +3138 frustration++; +3139 } +3140 if (frustration >= 50) return "!"; +3141 sb.append(next); +3142 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { +3143 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3144 sb.append(rng.getRandomElement(midPunctuation)); +3145 } +3146 next = word(rng, false); +3147 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3148 next = word(rng, false); +3149 frustration++; +3150 } +3151 if (frustration >= 50) break; +3152 sb.append(' '); +3153 sb.append(next); +3154 } +3155 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { +3156 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3157 sb.append(rng.getRandomElement(midPunctuation)); +3158 } +3159 next = word(rng, false); +3160 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3161 next = word(rng, false); +3162 frustration++; +3163 } +3164 if (frustration >= 50) break; +3165 sb.append(' '); +3166 sb.append(next); +3167 } +3168 +3169 if (endPunctuation != null && endPunctuation.length > 0) { +3170 +3171 next = rng.getRandomElement(endPunctuation); +3172 if (sb.length() + next.length() >= maxChars) +3173 sb.append('.'); +3174 else +3175 sb.append(next); +3176 } +3177 +3178 if (sb.length() > maxChars) +3179 return "!"; +3180 return sb.toString(); +3181 } +3182 +3183 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { +3184 if (other.length <= 0 && me.length <= 0) +3185 return new String[]{}; +3186 String[] ret = new String[1000]; +3187 int otherCount = (int) (1000 * otherInfluence); +3188 int idx = 0; +3189 if (other.length > 0) { +3190 String[] tmp = new String[other.length]; +3191 rng.shuffle(other, tmp); +3192 for (idx = 0; idx < otherCount; idx++) { +3193 ret[idx] = tmp[idx % tmp.length]; +3194 } +3195 } 3196 if (me.length > 0) { 3197 String[] tmp = new String[me.length]; 3198 rng.shuffle(me, tmp); -3199 for (idx = 0; idx < otherCount; idx++) { -3200 ret[idx] = tmp[idx % tmp.length] -3201 //0 -3202 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3203 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3204 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3205 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3206 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3207 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3208 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3209 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3210 //9 -3211 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3212 //11 -3213 //12 -3214 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3215 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3216 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3217 //16 -3218 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3219 //18 -3220 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3221 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3222 -3223 matcher = repeats.matcher(ret[idx]); -3224 if (matcher.find()) { -3225 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3226 } -3227 } -3228 for (; idx < 1000; idx++) { -3229 ret[idx] = tmp[idx % tmp.length]; +3199 for (; idx < 1000; idx++) { +3200 ret[idx] = tmp[idx % tmp.length]; +3201 } +3202 } else { +3203 for (; idx < 1000; idx++) { +3204 ret[idx] = other[idx % other.length]; +3205 } +3206 } +3207 return ret; +3208 } +3209 +3210 +3211 protected String[] accentVowels(RNG rng, String[] me, double influence) { +3212 String[] ret = new String[1000]; +3213 int otherCount = (int) (1000 * influence); +3214 int idx = 0; +3215 Matcher matcher; +3216 if (me.length > 0) { +3217 String[] tmp = new String[me.length]; +3218 rng.shuffle(me, tmp); +3219 for (idx = 0; idx < otherCount; idx++) { +3220 ret[idx] = tmp[idx % tmp.length] +3221 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3222 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3223 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3224 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3225 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3226 matcher = repeats.matcher(ret[idx]); +3227 if (matcher.find()) { +3228 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3229 } 3230 } -3231 } else -3232 return new String[]{}; -3233 return ret; -3234 } -3235 -3236 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { -3237 String[] ret = new String[1000]; -3238 int idx = 0; -3239 Matcher matcher; -3240 if (me.length > 0) { -3241 String[] tmp = new String[me.length]; -3242 rng.shuffle(me, tmp); -3243 for (idx = 0; idx < 1000; idx++) { -3244 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; -3245 if (subVowel && subCon) { -3246 ret[idx] = tmp[idx % tmp.length] -3247 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3248 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3249 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3250 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3251 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) -3252 -3253 //0 -3254 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3255 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3256 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3257 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3258 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3259 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3260 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3261 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3262 //9 -3263 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3264 //11 -3265 //12 -3266 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3267 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3268 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3269 //16 -3270 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3271 //18 -3272 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3273 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3274 -3275 matcher = repeats.matcher(ret[idx]); -3276 if (matcher.find()) { -3277 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3278 } -3279 } else if (subVowel) { -3280 ret[idx] = tmp[idx % tmp.length] -3281 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3282 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3283 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3284 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3285 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3286 -3287 matcher = repeats.matcher(ret[idx]); -3288 if (matcher.find()) { -3289 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3290 } -3291 } else if (subCon) { -3292 ret[idx] = tmp[idx % tmp.length] -3293 //0 -3294 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3295 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3296 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3297 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3298 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3299 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3300 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3301 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3302 //9 -3303 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3304 //11 -3305 //12 -3306 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3307 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3308 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3309 //16 -3310 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3311 //18 -3312 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3313 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3314 -3315 matcher = repeats.matcher(ret[idx]); -3316 if (matcher.find()) { -3317 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3318 } -3319 } else ret[idx] = tmp[idx % tmp.length]; -3320 -3321 } -3322 } else -3323 return new String[]{}; -3324 return ret; -3325 } -3326 -3327 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { -3328 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); -3329 double myInfluence = 1.0 - otherInfluence; -3330 -3331 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) -3332 ^ NumberTools.doubleToLongBits(otherInfluence)); -3333 -3334 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), -3335 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), -3336 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * -3337 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), -3338 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), -3339 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * -3340 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), -3341 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * -3342 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), -3343 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); -3344 -3345 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); -3346 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { -3347 if (freqs.containsKey(kv.getIntKey())) -3348 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); -3349 else -3350 freqs.put(kv.getIntKey(), kv.getDoubleValue()); -3351 } -3352 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); -3353 mods.addAll(modifiers); -3354 mods.addAll(other.modifiers); -3355 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, -3356 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, -3357 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, -3358 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, -3359 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, -3360 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); -3361 } +3231 for (; idx < 1000; idx++) { +3232 ret[idx] = tmp[idx % tmp.length]; +3233 } +3234 } else +3235 return new String[]{}; +3236 return ret; +3237 } +3238 +3239 protected String[] accentConsonants(RNG rng, String[] me, double influence) { +3240 String[] ret = new String[1000]; +3241 int otherCount = (int) (1000 * influence); +3242 int idx = 0; +3243 Matcher matcher; +3244 if (me.length > 0) { +3245 String[] tmp = new String[me.length]; +3246 rng.shuffle(me, tmp); +3247 for (idx = 0; idx < otherCount; idx++) { +3248 ret[idx] = tmp[idx % tmp.length] +3249 //0 +3250 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3251 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3252 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3253 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3254 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3255 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3256 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3257 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3258 //9 +3259 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3260 //11 +3261 //12 +3262 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3263 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3264 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3265 //16 +3266 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3267 //18 +3268 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3269 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3270 +3271 matcher = repeats.matcher(ret[idx]); +3272 if (matcher.find()) { +3273 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3274 } +3275 } +3276 for (; idx < 1000; idx++) { +3277 ret[idx] = tmp[idx % tmp.length]; +3278 } +3279 } else +3280 return new String[]{}; +3281 return ret; +3282 } +3283 +3284 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { +3285 String[] ret = new String[1000]; +3286 int idx = 0; +3287 Matcher matcher; +3288 if (me.length > 0) { +3289 String[] tmp = new String[me.length]; +3290 rng.shuffle(me, tmp); +3291 for (idx = 0; idx < 1000; idx++) { +3292 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; +3293 if (subVowel && subCon) { +3294 ret[idx] = tmp[idx % tmp.length] +3295 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3296 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3297 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3298 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3299 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) +3300 +3301 //0 +3302 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3303 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3304 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3305 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3306 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3307 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3308 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3309 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3310 //9 +3311 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3312 //11 +3313 //12 +3314 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3315 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3316 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3317 //16 +3318 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3319 //18 +3320 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3321 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3322 +3323 matcher = repeats.matcher(ret[idx]); +3324 if (matcher.find()) { +3325 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3326 } +3327 } else if (subVowel) { +3328 ret[idx] = tmp[idx % tmp.length] +3329 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3330 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3331 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3332 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3333 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3334 +3335 matcher = repeats.matcher(ret[idx]); +3336 if (matcher.find()) { +3337 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3338 } +3339 } else if (subCon) { +3340 ret[idx] = tmp[idx % tmp.length] +3341 //0 +3342 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3343 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3344 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3345 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3346 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3347 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3348 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3349 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3350 //9 +3351 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3352 //11 +3353 //12 +3354 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3355 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3356 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3357 //16 +3358 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3359 //18 +3360 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3361 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); 3362 -3363 private static double readDouble(Object o) { -3364 if (o instanceof Double) return (Double) o; -3365 else if (o instanceof Float) return (Float) o; -3366 else if (o instanceof Long) return ((Long) o).doubleValue(); -3367 else if (o instanceof Integer) return (Integer) o; -3368 else if (o instanceof Short) return (Short) o; -3369 else if (o instanceof Byte) return (Byte) o; -3370 else if (o instanceof Character) return (Character) o; -3371 return 0.0; -3372 } -3373 -3374 /** -3375 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes -3376 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of -3377 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a -3378 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this -3379 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. -3380 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type -3381 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some -3382 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and -3383 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern -3384 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on -3385 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3386 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3387 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3388 * with 0.33 . -3389 * <br> -3390 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the -3391 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for -3392 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 -3393 * the bytes used in one not-quite-simple test). -3394 * -3395 * @param myWeight the weight to assign this FakeLanguageGen in the mix -3396 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} -3397 * @param weight1 the weight to assign other1 in the mix -3398 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements -3399 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights -3400 */ -3401 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { -3402 if (other1 == null || pairs == null) -3403 return copy(); -3404 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); -3405 FakeLanguageGen mixer = removeModifiers(); -3406 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; -3407 double[] weights = new double[languages.length]; -3408 String[] summaries = new String[languages.length]; -3409 boolean summarize = true; -3410 double total = 0.0, current, weight; -3411 languages[0] = mixer; -3412 total += weights[0] = myWeight; -3413 if ((summaries[0] = mixer.summary) == null) summarize = false; -3414 mods.addAll(other1.modifiers); -3415 languages[1] = other1.removeModifiers(); -3416 total += weights[1] = weight1; -3417 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; -3418 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { -3419 if (pairs[i] == null || pairs[i - 1] == null) -3420 continue; -3421 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); -3422 total += weights[p] = readDouble(pairs[i]); -3423 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; -3424 } -3425 if (total == 0) -3426 return copy(); -3427 current = myWeight / total; -3428 for (int i = 1; i < languages.length; i++) { -3429 if ((weight = weights[i]) > 0) -3430 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); -3431 } -3432 if (summarize) { -3433 StringBuilder brief = new StringBuilder(64); -3434 String c; -3435 int idx; -3436 for (int i = 0; i < summaries.length; i++) { -3437 c = summaries[i]; -3438 idx = c.indexOf('@'); -3439 if (idx >= 0) { -3440 brief.append(c.substring(0, idx + 1)).append(weights[i]); -3441 if (i < summaries.length - 1) -3442 brief.append('~'); -3443 } -3444 } -3445 for (int i = 0; i < mods.size(); i++) { -3446 brief.append('℗').append(mods.getAt(i).serializeToString()); -3447 } -3448 return mixer.addModifiers(mods).summarize(brief.toString()); -3449 } else -3450 return mixer.addModifiers(mods); -3451 } -3452 -3453 /** -3454 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. -3455 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the -3456 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double -3457 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then -3458 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them -3459 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one -3460 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on -3461 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3462 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3463 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3464 * with 0.33 . -3465 * <br> -3466 * Not intended for external use, but it could be useful. Used internally in the deserialization code. -3467 * -3468 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements -3469 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights -3470 */ -3471 public static FakeLanguageGen mixAll(Object... pairs) { -3472 int len; -3473 if (pairs == null || (len = pairs.length) <= 0) -3474 return ENGLISH.copy(); -3475 if (len < 4) -3476 return ((FakeLanguageGen) pairs[0]).copy(); -3477 Object[] pairs2 = new Object[len - 4]; -3478 if (len > 4) -3479 System.arraycopy(pairs, 4, pairs2, 0, len - 4); -3480 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); -3481 } -3482 -3483 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { -3484 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); -3485 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); -3486 -3487 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ -3488 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); -3489 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), -3490 mv = accentVowels(rng, midVowels, vowelInfluence), -3491 oc = accentConsonants(rng, openingConsonants, consonantInfluence), -3492 mc = accentConsonants(rng, midConsonants, consonantInfluence), -3493 cc = accentConsonants(rng, closingConsonants, consonantInfluence), -3494 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); -3495 -3496 -3497 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3498 vowelStartFrequency, -3499 vowelEndFrequency, -3500 vowelSplitFrequency, -3501 syllableEndFrequency, sanityChecks, clean, modifiers); -3502 } -3503 -3504 static String[] copyStrings(String[] start) { -3505 String[] next = new String[start.length]; -3506 System.arraycopy(start, 0, next, 0, start.length); -3507 return next; -3508 } -3509 -3510 public FakeLanguageGen removeAccents() { -3511 -3512 String[] ov = copyStrings(openingVowels), -3513 mv = copyStrings(midVowels), -3514 oc = copyStrings(openingConsonants), -3515 mc = copyStrings(midConsonants), -3516 cc = copyStrings(closingConsonants), -3517 cs = copyStrings(closingSyllables); -3518 for (int i = 0; i < ov.length; i++) { -3519 ov[i] = removeAccents(openingVowels[i]).toString(); -3520 } -3521 for (int i = 0; i < mv.length; i++) { -3522 mv[i] = removeAccents(midVowels[i]).toString(); -3523 } -3524 for (int i = 0; i < oc.length; i++) { -3525 oc[i] = removeAccents(openingConsonants[i]).toString(); -3526 } -3527 for (int i = 0; i < mc.length; i++) { -3528 mc[i] = removeAccents(midConsonants[i]).toString(); -3529 } -3530 for (int i = 0; i < cc.length; i++) { -3531 cc[i] = removeAccents(closingConsonants[i]).toString(); -3532 } -3533 for (int i = 0; i < cs.length; i++) { -3534 cs[i] = removeAccents(closingSyllables[i]).toString(); -3535 } -3536 -3537 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3538 vowelStartFrequency, -3539 vowelEndFrequency, -3540 vowelSplitFrequency, -3541 syllableEndFrequency, sanityChecks, clean, modifiers); -3542 } +3363 matcher = repeats.matcher(ret[idx]); +3364 if (matcher.find()) { +3365 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3366 } +3367 } else ret[idx] = tmp[idx % tmp.length]; +3368 +3369 } +3370 } else +3371 return new String[]{}; +3372 return ret; +3373 } +3374 +3375 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { +3376 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); +3377 double myInfluence = 1.0 - otherInfluence; +3378 +3379 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) +3380 ^ NumberTools.doubleToLongBits(otherInfluence)); +3381 +3382 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), +3383 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), +3384 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * +3385 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), +3386 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), +3387 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * +3388 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), +3389 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * +3390 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), +3391 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); +3392 +3393 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); +3394 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { +3395 if (freqs.containsKey(kv.getIntKey())) +3396 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); +3397 else +3398 freqs.put(kv.getIntKey(), kv.getDoubleValue()); +3399 } +3400 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); +3401 mods.addAll(modifiers); +3402 mods.addAll(other.modifiers); +3403 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, +3404 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, +3405 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, +3406 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, +3407 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, +3408 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); +3409 } +3410 +3411 private static double readDouble(Object o) { +3412 if (o instanceof Double) return (Double) o; +3413 else if (o instanceof Float) return (Float) o; +3414 else if (o instanceof Long) return ((Long) o).doubleValue(); +3415 else if (o instanceof Integer) return (Integer) o; +3416 else if (o instanceof Short) return (Short) o; +3417 else if (o instanceof Byte) return (Byte) o; +3418 else if (o instanceof Character) return (Character) o; +3419 return 0.0; +3420 } +3421 +3422 /** +3423 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes +3424 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of +3425 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a +3426 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this +3427 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. +3428 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type +3429 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some +3430 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and +3431 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern +3432 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on +3433 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3434 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3435 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3436 * with 0.33 . +3437 * <br> +3438 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the +3439 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for +3440 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 +3441 * the bytes used in one not-quite-simple test). +3442 * +3443 * @param myWeight the weight to assign this FakeLanguageGen in the mix +3444 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} +3445 * @param weight1 the weight to assign other1 in the mix +3446 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements +3447 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights +3448 */ +3449 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { +3450 if (other1 == null || pairs == null) +3451 return copy(); +3452 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); +3453 FakeLanguageGen mixer = removeModifiers(); +3454 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; +3455 double[] weights = new double[languages.length]; +3456 String[] summaries = new String[languages.length]; +3457 boolean summarize = true; +3458 double total = 0.0, current, weight; +3459 languages[0] = mixer; +3460 total += weights[0] = myWeight; +3461 if ((summaries[0] = mixer.summary) == null) summarize = false; +3462 mods.addAll(other1.modifiers); +3463 languages[1] = other1.removeModifiers(); +3464 total += weights[1] = weight1; +3465 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; +3466 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { +3467 if (pairs[i] == null || pairs[i - 1] == null) +3468 continue; +3469 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); +3470 total += weights[p] = readDouble(pairs[i]); +3471 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; +3472 } +3473 if (total == 0) +3474 return copy(); +3475 current = myWeight / total; +3476 for (int i = 1; i < languages.length; i++) { +3477 if ((weight = weights[i]) > 0) +3478 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); +3479 } +3480 if (summarize) { +3481 StringBuilder brief = new StringBuilder(64); +3482 String c; +3483 int idx; +3484 for (int i = 0; i < summaries.length; i++) { +3485 c = summaries[i]; +3486 idx = c.indexOf('@'); +3487 if (idx >= 0) { +3488 brief.append(c.substring(0, idx + 1)).append(weights[i]); +3489 if (i < summaries.length - 1) +3490 brief.append('~'); +3491 } +3492 } +3493 for (int i = 0; i < mods.size(); i++) { +3494 brief.append('℗').append(mods.getAt(i).serializeToString()); +3495 } +3496 return mixer.addModifiers(mods).summarize(brief.toString()); +3497 } else +3498 return mixer.addModifiers(mods); +3499 } +3500 +3501 /** +3502 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. +3503 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the +3504 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double +3505 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then +3506 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them +3507 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one +3508 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on +3509 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3510 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3511 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3512 * with 0.33 . +3513 * <br> +3514 * Not intended for external use, but it could be useful. Used internally in the deserialization code. +3515 * +3516 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements +3517 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights +3518 */ +3519 public static FakeLanguageGen mixAll(Object... pairs) { +3520 int len; +3521 if (pairs == null || (len = pairs.length) <= 0) +3522 return ENGLISH.copy(); +3523 if (len < 4) +3524 return ((FakeLanguageGen) pairs[0]).copy(); +3525 Object[] pairs2 = new Object[len - 4]; +3526 if (len > 4) +3527 System.arraycopy(pairs, 4, pairs2, 0, len - 4); +3528 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); +3529 } +3530 +3531 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { +3532 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); +3533 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); +3534 +3535 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ +3536 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); +3537 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), +3538 mv = accentVowels(rng, midVowels, vowelInfluence), +3539 oc = accentConsonants(rng, openingConsonants, consonantInfluence), +3540 mc = accentConsonants(rng, midConsonants, consonantInfluence), +3541 cc = accentConsonants(rng, closingConsonants, consonantInfluence), +3542 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); 3543 -3544 /** -3545 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. -3546 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3547 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3548 * -3549 * @param mods an array or vararg of Modifier objects -3550 * @return a copy of this with the Modifiers added -3551 */ -3552 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { -3553 FakeLanguageGen next = copy(); -3554 next.modifiers.addAll(mods); +3544 +3545 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3546 vowelStartFrequency, +3547 vowelEndFrequency, +3548 vowelSplitFrequency, +3549 syllableEndFrequency, sanityChecks, clean, modifiers); +3550 } +3551 +3552 static String[] copyStrings(String[] start) { +3553 String[] next = new String[start.length]; +3554 System.arraycopy(start, 0, next, 0, start.length); 3555 return next; 3556 } 3557 -3558 /** -3559 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. -3560 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3561 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3562 * -3563 * @param mods an array or vararg of Modifier objects -3564 * @return a copy of this with the Modifiers added -3565 */ -3566 public FakeLanguageGen addModifiers(Modifier... mods) { -3567 FakeLanguageGen next = copy(); -3568 Collections.addAll(next.modifiers, mods); -3569 return next; -3570 } -3571 -3572 /** -3573 * Creates a copy of this FakeLanguageGen with no modifiers. -3574 * -3575 * @return a copy of this FakeLanguageGen with modifiers removed. -3576 */ -3577 public FakeLanguageGen removeModifiers() { -3578 FakeLanguageGen next = copy(); -3579 next.modifiers.clear(); -3580 return next; -3581 } -3582 -3583 public static Modifier modifier(String pattern, String replacement) { -3584 return new Modifier(pattern, replacement); -3585 } -3586 -3587 public static Modifier modifier(String pattern, String replacement, double chance) { -3588 return new Modifier(pattern, replacement, chance); -3589 } -3590 -3591 @Override -3592 public boolean equals(Object o) { -3593 if (this == o) return true; -3594 if (o == null || getClass() != o.getClass()) return false; -3595 -3596 FakeLanguageGen that = (FakeLanguageGen) o; -3597 -3598 if (clean != that.clean) return false; -3599 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; -3600 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; -3601 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; -3602 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; -3603 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; -3604 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3605 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; -3606 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3607 if (!Arrays.equals(midVowels, that.midVowels)) return false; -3608 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3609 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; -3610 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3611 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; -3612 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3613 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; -3614 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3615 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; -3616 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3617 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; -3618 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; -3619 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3620 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; -3621 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; -3622 } -3623 -3624 @Override -3625 public int hashCode() { -3626 int result; -3627 long temp; -3628 result = CrossHash.Lightning.hash(openingVowels); -3629 result = 31 * result + CrossHash.Lightning.hash(midVowels); -3630 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); -3631 result = 31 * result + CrossHash.Lightning.hash(midConsonants); -3632 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); -3633 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); -3634 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); -3635 result = 31 * result + (clean ? 1 : 0); -3636 result = 31 * result + syllableFrequencies.hashCode(); -3637 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); -3638 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3639 temp = NumberTools.doubleToLongBits(vowelStartFrequency); -3640 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3641 temp = NumberTools.doubleToLongBits(vowelEndFrequency); -3642 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3643 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); -3644 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3645 temp = NumberTools.doubleToLongBits(syllableEndFrequency); -3646 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3647 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); -3648 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); -3649 return result; -3650 } -3651 -3652 @Override -3653 public String toString() { -3654 return "FakeLanguageGen{" + -3655 "openingVowels=" + Arrays.toString(openingVowels) + -3656 ", midVowels=" + Arrays.toString(midVowels) + -3657 ", openingConsonants=" + Arrays.toString(openingConsonants) + -3658 ", midConsonants=" + Arrays.toString(midConsonants) + -3659 ", closingConsonants=" + Arrays.toString(closingConsonants) + -3660 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + -3661 ", closingSyllables=" + Arrays.toString(closingSyllables) + -3662 ", clean=" + clean + -3663 ", syllableFrequencies=" + syllableFrequencies + -3664 ", totalSyllableFrequency=" + totalSyllableFrequency + -3665 ", vowelStartFrequency=" + vowelStartFrequency + -3666 ", vowelEndFrequency=" + vowelEndFrequency + -3667 ", vowelSplitFrequency=" + vowelSplitFrequency + -3668 ", syllableEndFrequency=" + syllableEndFrequency + -3669 ", sanityChecks=" + Arrays.toString(sanityChecks) + -3670 ", modifiers=" + modifiers + -3671 '}'; -3672 } -3673 -3674 public FakeLanguageGen copy() { -3675 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, -3676 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, -3677 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) -3678 .summarize(summary); -3679 } -3680 -3681 -3682 public String serializeToString() { -3683 return (summary == null) ? "" : summary; -3684 } -3685 -3686 public static FakeLanguageGen deserializeFromString(String data) { -3687 if (data == null || data.equals("")) -3688 return ENGLISH.copy(); -3689 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), -3690 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, -3691 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; -3692 if (tildeIndex < 0) -3693 tildeIndex = data.length(); -3694 -3695 if (snailIndex < 0) -3696 return ENGLISH.copy(); -3697 ArrayList<Object> pairs = new ArrayList<>(4); -3698 while (snailIndex >= 0) { -3699 if (poundIndex >= 0 && poundIndex < snailIndex) // random case -3700 { -3701 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); -3702 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3703 poundIndex = -1; -3704 } else { -3705 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); -3706 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3707 } -3708 snailIndex = data.indexOf('@', snailIndex + 1); -3709 if (snailIndex > breakIndex) -3710 break; -3711 prevTildeIndex = tildeIndex; -3712 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); -3713 if (tildeIndex < 0) -3714 tildeIndex = data.length(); -3715 } -3716 ArrayList<Modifier> mods = new ArrayList<>(8); -3717 if (breakIndex == tempBreak) { -3718 tildeIndex = breakIndex - 1; -3719 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { -3720 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); -3721 if (tildeIndex < 0) tildeIndex = data.length(); -3722 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); -3723 } -3724 } -3725 FakeLanguageGen flg = mixAll(pairs.toArray()); -3726 flg.modifiers.addAll(mods); -3727 return flg; -3728 } +3558 public FakeLanguageGen removeAccents() { +3559 +3560 String[] ov = copyStrings(openingVowels), +3561 mv = copyStrings(midVowels), +3562 oc = copyStrings(openingConsonants), +3563 mc = copyStrings(midConsonants), +3564 cc = copyStrings(closingConsonants), +3565 cs = copyStrings(closingSyllables); +3566 for (int i = 0; i < ov.length; i++) { +3567 ov[i] = removeAccents(openingVowels[i]).toString(); +3568 } +3569 for (int i = 0; i < mv.length; i++) { +3570 mv[i] = removeAccents(midVowels[i]).toString(); +3571 } +3572 for (int i = 0; i < oc.length; i++) { +3573 oc[i] = removeAccents(openingConsonants[i]).toString(); +3574 } +3575 for (int i = 0; i < mc.length; i++) { +3576 mc[i] = removeAccents(midConsonants[i]).toString(); +3577 } +3578 for (int i = 0; i < cc.length; i++) { +3579 cc[i] = removeAccents(closingConsonants[i]).toString(); +3580 } +3581 for (int i = 0; i < cs.length; i++) { +3582 cs[i] = removeAccents(closingSyllables[i]).toString(); +3583 } +3584 +3585 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3586 vowelStartFrequency, +3587 vowelEndFrequency, +3588 vowelSplitFrequency, +3589 syllableEndFrequency, sanityChecks, clean, modifiers); +3590 } +3591 +3592 /** +3593 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. +3594 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3595 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3596 * +3597 * @param mods an array or vararg of Modifier objects +3598 * @return a copy of this with the Modifiers added +3599 */ +3600 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { +3601 FakeLanguageGen next = copy(); +3602 next.modifiers.addAll(mods); +3603 return next; +3604 } +3605 +3606 /** +3607 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. +3608 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3609 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3610 * +3611 * @param mods an array or vararg of Modifier objects +3612 * @return a copy of this with the Modifiers added +3613 */ +3614 public FakeLanguageGen addModifiers(Modifier... mods) { +3615 FakeLanguageGen next = copy(); +3616 Collections.addAll(next.modifiers, mods); +3617 return next; +3618 } +3619 +3620 /** +3621 * Creates a copy of this FakeLanguageGen with no modifiers. +3622 * +3623 * @return a copy of this FakeLanguageGen with modifiers removed. +3624 */ +3625 public FakeLanguageGen removeModifiers() { +3626 FakeLanguageGen next = copy(); +3627 next.modifiers.clear(); +3628 return next; +3629 } +3630 +3631 public static Modifier modifier(String pattern, String replacement) { +3632 return new Modifier(pattern, replacement); +3633 } +3634 +3635 public static Modifier modifier(String pattern, String replacement, double chance) { +3636 return new Modifier(pattern, replacement, chance); +3637 } +3638 +3639 @Override +3640 public boolean equals(Object o) { +3641 if (this == o) return true; +3642 if (o == null || getClass() != o.getClass()) return false; +3643 +3644 FakeLanguageGen that = (FakeLanguageGen) o; +3645 +3646 if (clean != that.clean) return false; +3647 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; +3648 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; +3649 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; +3650 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; +3651 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; +3652 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3653 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; +3654 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3655 if (!Arrays.equals(midVowels, that.midVowels)) return false; +3656 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3657 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; +3658 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3659 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; +3660 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3661 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; +3662 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3663 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; +3664 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3665 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; +3666 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; +3667 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3668 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; +3669 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; +3670 } +3671 +3672 @Override +3673 public int hashCode() { +3674 int result; +3675 long temp; +3676 result = CrossHash.Lightning.hash(openingVowels); +3677 result = 31 * result + CrossHash.Lightning.hash(midVowels); +3678 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); +3679 result = 31 * result + CrossHash.Lightning.hash(midConsonants); +3680 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); +3681 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); +3682 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); +3683 result = 31 * result + (clean ? 1 : 0); +3684 result = 31 * result + syllableFrequencies.hashCode(); +3685 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); +3686 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3687 temp = NumberTools.doubleToLongBits(vowelStartFrequency); +3688 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3689 temp = NumberTools.doubleToLongBits(vowelEndFrequency); +3690 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3691 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); +3692 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3693 temp = NumberTools.doubleToLongBits(syllableEndFrequency); +3694 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3695 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); +3696 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); +3697 return result; +3698 } +3699 +3700 @Override +3701 public String toString() { +3702 return "FakeLanguageGen{" + +3703 "openingVowels=" + Arrays.toString(openingVowels) + +3704 ", midVowels=" + Arrays.toString(midVowels) + +3705 ", openingConsonants=" + Arrays.toString(openingConsonants) + +3706 ", midConsonants=" + Arrays.toString(midConsonants) + +3707 ", closingConsonants=" + Arrays.toString(closingConsonants) + +3708 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + +3709 ", closingSyllables=" + Arrays.toString(closingSyllables) + +3710 ", clean=" + clean + +3711 ", syllableFrequencies=" + syllableFrequencies + +3712 ", totalSyllableFrequency=" + totalSyllableFrequency + +3713 ", vowelStartFrequency=" + vowelStartFrequency + +3714 ", vowelEndFrequency=" + vowelEndFrequency + +3715 ", vowelSplitFrequency=" + vowelSplitFrequency + +3716 ", syllableEndFrequency=" + syllableEndFrequency + +3717 ", sanityChecks=" + Arrays.toString(sanityChecks) + +3718 ", modifiers=" + modifiers + +3719 '}'; +3720 } +3721 +3722 public FakeLanguageGen copy() { +3723 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, +3724 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, +3725 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) +3726 .summarize(summary); +3727 } +3728 3729 -3730 public static class Modifier implements Serializable { -3731 private static final long serialVersionUID = 1734863678490422371L; -3732 public final Alteration[] alterations; +3730 public String serializeToString() { +3731 return (summary == null) ? "" : summary; +3732 } 3733 -3734 public Modifier() { -3735 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -3736 } -3737 -3738 public Modifier(String pattern, String replacement) { -3739 alterations = new Alteration[]{new Alteration(pattern, replacement)}; -3740 } -3741 -3742 public Modifier(String pattern, String replacement, double chance) { -3743 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; -3744 } -3745 -3746 public Modifier(Alteration... alts) { -3747 alterations = (alts == null) ? new Alteration[0] : alts; -3748 } -3749 -3750 public StringBuilder modify(RNG rng, StringBuilder sb) { -3751 Matcher m; -3752 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); -3753 String tmp; -3754 boolean found; -3755 Alteration alt; -3756 for (int a = 0; a < alterations.length; a++) { -3757 alt = alterations[a]; -3758 tmp = working.toString(); -3759 tb = Replacer.wrap(new StringBuilder(tmp.length())); -3760 m = alt.replacer.getPattern().matcher(tmp); -3761 -3762 found = false; -3763 while (true) { -3764 if (rng.nextDouble() < alt.chance) { -3765 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) -3766 break; -3767 found = true; -3768 } else { -3769 if (!m.find()) -3770 break; -3771 found = true; -3772 m.getGroup(MatchResult.PREFIX, tb); -3773 m.getGroup(MatchResult.MATCH, tb); -3774 m.setTarget(m, MatchResult.SUFFIX); -3775 } -3776 } -3777 if (found) { -3778 m.getGroup(MatchResult.TARGET, tb); -3779 working = tb; -3780 } -3781 } -3782 return working.toStringBuilder(); -3783 } -3784 -3785 /** -3786 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. -3787 */ -3788 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3734 public static FakeLanguageGen deserializeFromString(String data) { +3735 if (data == null || data.equals("")) +3736 return ENGLISH.copy(); +3737 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), +3738 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, +3739 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; +3740 if (tildeIndex < 0) +3741 tildeIndex = data.length(); +3742 +3743 if (snailIndex < 0) +3744 return ENGLISH.copy(); +3745 ArrayList<Object> pairs = new ArrayList<>(4); +3746 while (snailIndex >= 0) { +3747 if (poundIndex >= 0 && poundIndex < snailIndex) // random case +3748 { +3749 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); +3750 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3751 poundIndex = -1; +3752 } else { +3753 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); +3754 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3755 } +3756 snailIndex = data.indexOf('@', snailIndex + 1); +3757 if (snailIndex > breakIndex) +3758 break; +3759 prevTildeIndex = tildeIndex; +3760 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); +3761 if (tildeIndex < 0) +3762 tildeIndex = data.length(); +3763 } +3764 ArrayList<Modifier> mods = new ArrayList<>(8); +3765 if (breakIndex == tempBreak) { +3766 tildeIndex = breakIndex - 1; +3767 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { +3768 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); +3769 if (tildeIndex < 0) tildeIndex = data.length(); +3770 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); +3771 } +3772 } +3773 FakeLanguageGen flg = mixAll(pairs.toArray()); +3774 flg.modifiers.addAll(mods); +3775 return flg; +3776 } +3777 +3778 public static class Modifier implements Serializable { +3779 private static final long serialVersionUID = 1734863678490422371L; +3780 public final Alteration[] alterations; +3781 +3782 public Modifier() { +3783 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3784 } +3785 +3786 public Modifier(String pattern, String replacement) { +3787 alterations = new Alteration[]{new Alteration(pattern, replacement)}; +3788 } 3789 -3790 /** -3791 * For a character who always lengthens 's' and 'z' sounds not starting a word. -3792 */ -3793 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); -3794 -3795 /** -3796 * For a character who has a 20% chance to repeat a starting consonant or vowel. -3797 */ -3798 public static final Modifier STUTTER = new Modifier( -3799 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), -3800 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); -3801 -3802 /** -3803 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them -3804 * like å or ö, but not merged letters like æ and œ). -3805 */ -3806 public static final Modifier DOUBLE_VOWELS = new Modifier( -3807 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" -3808 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" -3809 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); -3810 -3811 -3812 /** -3813 * For a language that has a 50% chance to repeat a single consonant. -3814 */ -3815 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + -3816 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + -3817 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); -3818 -3819 /** -3820 * For a language that never repeats the same letter twice in a row. -3821 */ -3822 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); -3823 -3824 /** -3825 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. -3826 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j -3827 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ -3828 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. -3829 */ -3830 public static final Modifier SIMPLIFY_NORSE = replacementTable( -3831 "á", "a", -3832 "é", "e", -3833 "í", "i", -3834 "ý", "y", -3835 "ó", "o", -3836 "ú", "u", -3837 "æ", "ae", -3838 "ö", "ou", -3839 "([^aeiou])jy", "$1yai", -3840 "([^aeiou])j(?:[aeiouy]+)", "$1yo", -3841 "s([ðþ])", "st", -3842 "\\bf[ðþ]", "fr", -3843 "[ðþ]", "th"); -3844 -3845 /** -3846 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". -3847 */ -3848 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); -3849 /** -3850 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate -3851 * for fixing a word that isn't pronounceable. -3852 */ -3853 public static final Modifier GENERAL_CLEANUP = replacementTable( -3854 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", -3855 "q([ùúûüũūŭůűųu])$", "q$1e", -3856 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", -3857 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", -3858 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", -3859 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", -3860 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", -3861 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", -3862 "qq", "q"); -3863 -3864 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy -3865 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3790 public Modifier(String pattern, String replacement, double chance) { +3791 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; +3792 } +3793 +3794 public Modifier(Alteration... alts) { +3795 alterations = (alts == null) ? new Alteration[0] : alts; +3796 } +3797 +3798 public StringBuilder modify(RNG rng, StringBuilder sb) { +3799 Matcher m; +3800 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); +3801 String tmp; +3802 boolean found; +3803 Alteration alt; +3804 for (int a = 0; a < alterations.length; a++) { +3805 alt = alterations[a]; +3806 tmp = working.toString(); +3807 tb = Replacer.wrap(new StringBuilder(tmp.length())); +3808 m = alt.replacer.getPattern().matcher(tmp); +3809 +3810 found = false; +3811 while (true) { +3812 if (rng.nextDouble() < alt.chance) { +3813 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) +3814 break; +3815 found = true; +3816 } else { +3817 if (!m.find()) +3818 break; +3819 found = true; +3820 m.getGroup(MatchResult.PREFIX, tb); +3821 m.getGroup(MatchResult.MATCH, tb); +3822 m.setTarget(m, MatchResult.SUFFIX); +3823 } +3824 } +3825 if (found) { +3826 m.getGroup(MatchResult.TARGET, tb); +3827 working = tb; +3828 } +3829 } +3830 return working.toStringBuilder(); +3831 } +3832 +3833 /** +3834 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. +3835 */ +3836 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3837 +3838 /** +3839 * For a character who always lengthens 's' and 'z' sounds not starting a word. +3840 */ +3841 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); +3842 +3843 /** +3844 * For a character who has a 20% chance to repeat a starting consonant or vowel. +3845 */ +3846 public static final Modifier STUTTER = new Modifier( +3847 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), +3848 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); +3849 +3850 /** +3851 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them +3852 * like å or ö, but not merged letters like æ and œ). +3853 */ +3854 public static final Modifier DOUBLE_VOWELS = new Modifier( +3855 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" +3856 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" +3857 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); +3858 +3859 +3860 /** +3861 * For a language that has a 50% chance to repeat a single consonant. +3862 */ +3863 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + +3864 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + +3865 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); 3866 3867 /** -3868 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and -3869 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the -3870 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3871 * -3872 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text -3873 * @param change a String containing characters that will replace occurrences of characters in initial -3874 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3875 */ -3876 public static Modifier charReplacementTable(String initial, String change) { -3877 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; -3878 for (int i = 0; i < alts.length; i++) { -3879 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, -3880 // which is slightly slower and has some odd escaping cases. -3881 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); -3882 } -3883 return new Modifier(alts); -3884 } -3885 -3886 /** -3887 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the -3888 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3889 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, -3890 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3891 * this example to replace the repeated section with only the first vowel. -3892 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced -3893 * first, possibly making the later key not match), or if an earlier replacement causes a later one to -3894 * become valid. -3895 * -3896 * @param map containing String keys to replace and String values to use instead; replacements happen in order -3897 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3898 */ -3899 public static Modifier replacementTable(OrderedMap<String, String> map) { -3900 if (map == null) -3901 return new Modifier(); -3902 Alteration[] alts = new Alteration[map.size()]; -3903 for (int i = 0; i < alts.length; i++) { -3904 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); -3905 } -3906 return new Modifier(alts); -3907 } -3908 -3909 /** -3910 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because -3911 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3912 * This overload of replacementTable allows full regex syntax for search and replacement Strings, -3913 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3914 * this example to replace the repeated section with only the first vowel. -3915 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced -3916 * first, possibly making the later search not match), or if an earlier replacement causes a later one to -3917 * become valid. -3918 * -3919 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order -3920 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3921 */ -3922 public static Modifier replacementTable(String... pairs) { -3923 int len; -3924 if (pairs == null || (len = pairs.length) <= 1) -3925 return new Modifier(); -3926 Alteration[] alts = new Alteration[len >> 1]; -3927 for (int i = 0; i < alts.length; i++) { -3928 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); -3929 } -3930 return new Modifier(alts); -3931 } -3932 -3933 /** -3934 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3935 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel -3936 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the -3937 * newly-inserted vowel to be likely to be present in every word of some sentences. -3938 * @param insertion the String to use as an additional vowel -3939 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less -3940 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3941 */ -3942 public static Modifier insertVowel(String insertion, double chance) -3943 { -3944 return new Modifier(anyVowelCluster, insertion, chance); -3945 } -3946 -3947 /** -3948 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3949 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had -3950 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you -3951 * want the newly-inserted consonant to be likely to be present in every word of some sentences. -3952 * @param insertion the String to use as an additional consonant -3953 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less -3954 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3955 */ -3956 public static Modifier insertConsonant(String insertion, double chance) -3957 { -3958 return new Modifier(anyConsonantCluster, insertion, chance); -3959 } -3960 -3961 /** -3962 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3963 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of -3964 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3965 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, -3966 * so this might not do anything. -3967 * @param insertion the String to use as an additional opening vowel -3968 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3969 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3970 */ -3971 public static Modifier insertOpeningVowel(String insertion, double chance) -3972 { -3973 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); -3974 } -3975 -3976 /** -3977 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3978 * that the language already uses; insertion will replace an existing consonant at the start of a word with a -3979 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -3980 * consonant to be likely to start every word of some sentences. Not all languages can start words with -3981 * consonants, or do that very rarely, so this might not do anything. -3982 * @param insertion the String to use as an additional opening consonant -3983 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3984 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3985 */ -3986 public static Modifier insertOpeningConsonant(String insertion, double chance) -3987 { -3988 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); -3989 } -3990 -3991 /** -3992 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3993 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of -3994 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3995 * to end every word of some sentences. Not all languages can end words with vowels, or do that very -3996 * rarely, so this might not do anything. -3997 * @param insertion the String to use as an additional closing vowel -3998 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less -3999 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4000 */ -4001 public static Modifier insertClosingVowel(String insertion, double chance) -4002 { -4003 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); -4004 } -4005 -4006 /** -4007 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -4008 * that the language already uses; insertion will replace an existing consonant at the end of a word with a -4009 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -4010 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, -4011 * or do that very rarely, so this might not do anything. -4012 * @param insertion the String to use as an additional closing consonant -4013 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less -4014 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4015 */ -4016 public static Modifier insertClosingConsonant(String insertion, double chance) -4017 { -4018 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); -4019 } -4020 -4021 /** -4022 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek -4023 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of -4024 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this -4025 * Modifier is a no-op. Its use is never needed any more. -4026 * @deprecated This Modifier doesn't do anything, and isn't needed. -4027 */ -4028 @Deprecated -4029 public static final Modifier SIMPLIFY_ARABIC = new Modifier( -4030 /* -4031 new Alteration("ţ", "th"), -4032 new Alteration("ĥ", "kh"), -4033 new Alteration("ħ", "khr"), -4034 new Alteration("đ", "dh"), -4035 new Alteration("ď", "dt"), -4036 new Alteration("š", "sh"), -4037 new Alteration("ş", "shw"), -4038 new Alteration("ť", "ch"), -4039 new Alteration("ż", "zh"), -4040 new Alteration("ξ", "khm"), -4041 new Alteration("δ", "gh"), -4042 new Alteration("ā", "aa"), -4043 new Alteration("ū", "uu"), -4044 new Alteration("ī", "ii")*/); -4045 -4046 @Override -4047 public boolean equals(Object o) { -4048 if (this == o) return true; -4049 if (o == null || getClass() != o.getClass()) return false; -4050 -4051 Modifier modifier = (Modifier) o; -4052 -4053 // Probably incorrect - comparing Object[] arrays with Arrays.equals -4054 return Arrays.equals(alterations, modifier.alterations); -4055 } -4056 -4057 @Override -4058 public int hashCode() { -4059 return CrossHash.Lightning.hash(alterations); -4060 } -4061 -4062 @Override -4063 public String toString() { -4064 return "Modifier{" + -4065 "alterations=" + Arrays.toString(alterations) + -4066 '}'; +3868 * For a language that never repeats the same letter twice in a row. +3869 */ +3870 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); +3871 +3872 /** +3873 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. +3874 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j +3875 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ +3876 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. +3877 */ +3878 public static final Modifier SIMPLIFY_NORSE = replacementTable( +3879 "á", "a", +3880 "é", "e", +3881 "í", "i", +3882 "ý", "y", +3883 "ó", "o", +3884 "ú", "u", +3885 "æ", "ae", +3886 "ö", "ou", +3887 "([^aeiou])jy", "$1yai", +3888 "([^aeiou])j(?:[aeiouy]+)", "$1yo", +3889 "s([ðþ])", "st", +3890 "\\bf[ðþ]", "fr", +3891 "[ðþ]", "th"); +3892 +3893 /** +3894 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". +3895 */ +3896 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); +3897 /** +3898 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate +3899 * for fixing a word that isn't pronounceable. +3900 */ +3901 public static final Modifier GENERAL_CLEANUP = replacementTable( +3902 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", +3903 "q([ùúûüũūŭůűųu])$", "q$1e", +3904 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", +3905 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", +3906 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", +3907 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", +3908 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", +3909 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", +3910 "qq", "q"); +3911 +3912 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy +3913 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3914 +3915 /** +3916 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and +3917 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the +3918 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3919 * +3920 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text +3921 * @param change a String containing characters that will replace occurrences of characters in initial +3922 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3923 */ +3924 public static Modifier charReplacementTable(String initial, String change) { +3925 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; +3926 for (int i = 0; i < alts.length; i++) { +3927 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, +3928 // which is slightly slower and has some odd escaping cases. +3929 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); +3930 } +3931 return new Modifier(alts); +3932 } +3933 +3934 /** +3935 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the +3936 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3937 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, +3938 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3939 * this example to replace the repeated section with only the first vowel. +3940 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced +3941 * first, possibly making the later key not match), or if an earlier replacement causes a later one to +3942 * become valid. +3943 * +3944 * @param map containing String keys to replace and String values to use instead; replacements happen in order +3945 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3946 */ +3947 public static Modifier replacementTable(OrderedMap<String, String> map) { +3948 if (map == null) +3949 return new Modifier(); +3950 Alteration[] alts = new Alteration[map.size()]; +3951 for (int i = 0; i < alts.length; i++) { +3952 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); +3953 } +3954 return new Modifier(alts); +3955 } +3956 +3957 /** +3958 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because +3959 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3960 * This overload of replacementTable allows full regex syntax for search and replacement Strings, +3961 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3962 * this example to replace the repeated section with only the first vowel. +3963 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced +3964 * first, possibly making the later search not match), or if an earlier replacement causes a later one to +3965 * become valid. +3966 * +3967 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order +3968 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3969 */ +3970 public static Modifier replacementTable(String... pairs) { +3971 int len; +3972 if (pairs == null || (len = pairs.length) <= 1) +3973 return new Modifier(); +3974 Alteration[] alts = new Alteration[len >> 1]; +3975 for (int i = 0; i < alts.length; i++) { +3976 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); +3977 } +3978 return new Modifier(alts); +3979 } +3980 +3981 /** +3982 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +3983 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel +3984 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the +3985 * newly-inserted vowel to be likely to be present in every word of some sentences. +3986 * @param insertion the String to use as an additional vowel +3987 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less +3988 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3989 */ +3990 public static Modifier insertVowel(String insertion, double chance) +3991 { +3992 return new Modifier(anyVowelCluster, insertion, chance); +3993 } +3994 +3995 /** +3996 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +3997 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had +3998 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you +3999 * want the newly-inserted consonant to be likely to be present in every word of some sentences. +4000 * @param insertion the String to use as an additional consonant +4001 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less +4002 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4003 */ +4004 public static Modifier insertConsonant(String insertion, double chance) +4005 { +4006 return new Modifier(anyConsonantCluster, insertion, chance); +4007 } +4008 +4009 /** +4010 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4011 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of +4012 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4013 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, +4014 * so this might not do anything. +4015 * @param insertion the String to use as an additional opening vowel +4016 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4017 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4018 */ +4019 public static Modifier insertOpeningVowel(String insertion, double chance) +4020 { +4021 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); +4022 } +4023 +4024 /** +4025 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4026 * that the language already uses; insertion will replace an existing consonant at the start of a word with a +4027 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4028 * consonant to be likely to start every word of some sentences. Not all languages can start words with +4029 * consonants, or do that very rarely, so this might not do anything. +4030 * @param insertion the String to use as an additional opening consonant +4031 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4032 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4033 */ +4034 public static Modifier insertOpeningConsonant(String insertion, double chance) +4035 { +4036 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); +4037 } +4038 +4039 /** +4040 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4041 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of +4042 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4043 * to end every word of some sentences. Not all languages can end words with vowels, or do that very +4044 * rarely, so this might not do anything. +4045 * @param insertion the String to use as an additional closing vowel +4046 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4047 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4048 */ +4049 public static Modifier insertClosingVowel(String insertion, double chance) +4050 { +4051 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); +4052 } +4053 +4054 /** +4055 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4056 * that the language already uses; insertion will replace an existing consonant at the end of a word with a +4057 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4058 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, +4059 * or do that very rarely, so this might not do anything. +4060 * @param insertion the String to use as an additional closing consonant +4061 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4062 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4063 */ +4064 public static Modifier insertClosingConsonant(String insertion, double chance) +4065 { +4066 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); 4067 } 4068 -4069 public String serializeToString() { -4070 if (alterations == null || alterations.length == 0) return "\6"; -4071 StringBuilder sb = new StringBuilder(32).append('\6'); -4072 for (int i = 0; i < alterations.length; i++) -4073 sb.append(alterations[i].serializeToString()).append('\6'); -4074 return sb.toString(); -4075 } -4076 -4077 public static Modifier deserializeFromString(String data) { -4078 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; -4079 while (currIdx >= 0) { -4080 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) -4081 break; -4082 matches++; -4083 } -4084 Alteration[] alts = new Alteration[matches]; -4085 for (int i = 0; i < matches; i++) { -4086 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); -4087 } -4088 return new Modifier(alts); -4089 } -4090 } -4091 -4092 public static class Alteration implements Serializable { -4093 private static final long serialVersionUID = -2138854697837563188L; -4094 public Replacer replacer; -4095 public String replacement; -4096 public double chance; -4097 -4098 public Alteration() { -4099 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -4100 } -4101 -4102 public Alteration(String pattern, String replacement) { -4103 this.replacement = replacement; -4104 replacer = Pattern.compile(pattern).replacer(replacement); -4105 chance = 1.0; -4106 } -4107 -4108 public Alteration(String pattern, String replacement, double chance) { -4109 this.replacement = replacement; -4110 replacer = Pattern.compile(pattern).replacer(replacement); -4111 this.chance = chance; -4112 } -4113 -4114 public Alteration(Pattern pattern, String replacement, double chance) { -4115 this.replacement = replacement; -4116 replacer = pattern.replacer(replacement); -4117 this.chance = chance; -4118 } -4119 -4120 @Override -4121 public boolean equals(Object o) { -4122 if (this == o) return true; -4123 if (o == null || getClass() != o.getClass()) return false; +4069 /** +4070 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek +4071 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of +4072 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this +4073 * Modifier is a no-op. Its use is never needed any more. +4074 * @deprecated This Modifier doesn't do anything, and isn't needed. +4075 */ +4076 @Deprecated +4077 public static final Modifier SIMPLIFY_ARABIC = new Modifier( +4078 /* +4079 new Alteration("ţ", "th"), +4080 new Alteration("ĥ", "kh"), +4081 new Alteration("ħ", "khr"), +4082 new Alteration("đ", "dh"), +4083 new Alteration("ď", "dt"), +4084 new Alteration("š", "sh"), +4085 new Alteration("ş", "shw"), +4086 new Alteration("ť", "ch"), +4087 new Alteration("ż", "zh"), +4088 new Alteration("ξ", "khm"), +4089 new Alteration("δ", "gh"), +4090 new Alteration("ā", "aa"), +4091 new Alteration("ū", "uu"), +4092 new Alteration("ī", "ii")*/); +4093 +4094 @Override +4095 public boolean equals(Object o) { +4096 if (this == o) return true; +4097 if (o == null || getClass() != o.getClass()) return false; +4098 +4099 Modifier modifier = (Modifier) o; +4100 +4101 // Probably incorrect - comparing Object[] arrays with Arrays.equals +4102 return Arrays.equals(alterations, modifier.alterations); +4103 } +4104 +4105 @Override +4106 public int hashCode() { +4107 return CrossHash.Lightning.hash(alterations); +4108 } +4109 +4110 @Override +4111 public String toString() { +4112 return "Modifier{" + +4113 "alterations=" + Arrays.toString(alterations) + +4114 '}'; +4115 } +4116 +4117 public String serializeToString() { +4118 if (alterations == null || alterations.length == 0) return "\6"; +4119 StringBuilder sb = new StringBuilder(32).append('\6'); +4120 for (int i = 0; i < alterations.length; i++) +4121 sb.append(alterations[i].serializeToString()).append('\6'); +4122 return sb.toString(); +4123 } 4124 -4125 Alteration that = (Alteration) o; -4126 -4127 if (Double.compare(that.chance, chance) != 0) return false; -4128 return replacer.equals(that.replacer); -4129 -4130 } -4131 -4132 @Override -4133 public int hashCode() { -4134 int result; -4135 long temp; -4136 result = replacer.hashCode(); -4137 temp = NumberTools.doubleToLongBits(chance); -4138 result = 31 * result + (int) (temp ^ (temp >>> 32)); -4139 return result; -4140 } -4141 -4142 @Override -4143 public String toString() { -4144 return "Alteration{" + -4145 "replacer=" + replacer + -4146 ", chance=" + chance + -4147 '}'; +4125 public static Modifier deserializeFromString(String data) { +4126 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; +4127 while (currIdx >= 0) { +4128 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) +4129 break; +4130 matches++; +4131 } +4132 Alteration[] alts = new Alteration[matches]; +4133 for (int i = 0; i < matches; i++) { +4134 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); +4135 } +4136 return new Modifier(alts); +4137 } +4138 } +4139 +4140 public static class Alteration implements Serializable { +4141 private static final long serialVersionUID = -2138854697837563188L; +4142 public Replacer replacer; +4143 public String replacement; +4144 public double chance; +4145 +4146 public Alteration() { +4147 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); 4148 } 4149 -4150 public String serializeToString() { -4151 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; -4152 } -4153 -4154 public static Alteration deserializeFromString(String data) { -4155 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); -4156 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), -4157 data.substring(split2 + 1, split4), -4158 Double.parseDouble(data.substring(split4 + 1))); -4159 } -4160 } +4150 public Alteration(String pattern, String replacement) { +4151 this.replacement = replacement; +4152 replacer = Pattern.compile(pattern).replacer(replacement); +4153 chance = 1.0; +4154 } +4155 +4156 public Alteration(String pattern, String replacement, double chance) { +4157 this.replacement = replacement; +4158 replacer = Pattern.compile(pattern).replacer(replacement); +4159 this.chance = chance; +4160 } 4161 -4162 /** -4163 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling -4164 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. -4165 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given -4166 * at construction. The parameters to -4167 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of -4168 * the same name, and all fields in this class are public and modifiable. -4169 */ -4170 public static class SentenceForm implements Serializable -4171 { -4172 private static final long serialVersionUID = 1246527948419533147L; -4173 public StatefulRNG rng; -4174 public int minWords, maxWords, maxChars; -4175 public String[] midPunctuation, endPunctuation; -4176 public double midPunctuationFrequency; -4177 public FakeLanguageGen language; -4178 public SentenceForm() -4179 { -4180 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, -4181 new String[]{",", ",", ",", ";", ";"}, -4182 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); -4183 } -4184 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) -4185 { -4186 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, -4187 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4162 public Alteration(Pattern pattern, String replacement, double chance) { +4163 this.replacement = replacement; +4164 replacer = pattern.replacer(replacement); +4165 this.chance = chance; +4166 } +4167 +4168 @Override +4169 public boolean equals(Object o) { +4170 if (this == o) return true; +4171 if (o == null || getClass() != o.getClass()) return false; +4172 +4173 Alteration that = (Alteration) o; +4174 +4175 if (Double.compare(that.chance, chance) != 0) return false; +4176 return replacer.equals(that.replacer); +4177 +4178 } +4179 +4180 @Override +4181 public int hashCode() { +4182 int result; +4183 long temp; +4184 result = replacer.hashCode(); +4185 temp = NumberTools.doubleToLongBits(chance); +4186 result = 31 * result + (int) (temp ^ (temp >>> 32)); +4187 return result; 4188 } -4189 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4190 String[] endPunctuation, double midPunctuationFrequency) -4191 { -4192 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4193 midPunctuationFrequency, -1); -4194 } -4195 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4196 String[] endPunctuation, double midPunctuationFrequency, int maxChars) -4197 { -4198 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4199 midPunctuationFrequency, maxChars); +4189 +4190 @Override +4191 public String toString() { +4192 return "Alteration{" + +4193 "replacer=" + replacer + +4194 ", chance=" + chance + +4195 '}'; +4196 } +4197 +4198 public String serializeToString() { +4199 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; 4200 } 4201 -4202 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, -4203 String[] midPunctuation, String[] endPunctuation, -4204 double midPunctuationFrequency, int maxChars) -4205 { -4206 this.language = language; -4207 this.rng = new StatefulRNG(rng.getState()); -4208 this.minWords = minWords; -4209 this.maxWords = maxWords; -4210 this.midPunctuation = midPunctuation; -4211 this.endPunctuation = endPunctuation; -4212 this.midPunctuationFrequency = midPunctuationFrequency; -4213 this.maxChars = maxChars; -4214 } -4215 public String sentence() -4216 { -4217 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, -4218 midPunctuationFrequency, maxChars); -4219 } -4220 -4221 public String serializeToString() { -4222 return language.serializeToString() + '℘' + -4223 rng.getState() + '℘' + -4224 minWords + '℘' + -4225 maxWords + '℘' + -4226 StringKit.join("ℙ", midPunctuation) + '℘' + -4227 StringKit.join("ℙ", endPunctuation) + '℘' + -4228 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + -4229 maxChars; -4230 } -4231 public static SentenceForm deserializeFromString(String ser) -4232 { -4233 int gap = ser.indexOf('℘'); -4234 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); -4235 StatefulRNG rng = new StatefulRNG( -4236 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4237 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4238 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4239 String[] midPunctuation = -4240 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4241 String[] endPunctuation = -4242 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4243 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4244 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); -4245 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); -4246 } -4247 } -4248} +4202 public static Alteration deserializeFromString(String data) { +4203 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); +4204 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), +4205 data.substring(split2 + 1, split4), +4206 Double.parseDouble(data.substring(split4 + 1))); +4207 } +4208 } +4209 +4210 /** +4211 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling +4212 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. +4213 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given +4214 * at construction. The parameters to +4215 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of +4216 * the same name, and all fields in this class are public and modifiable. +4217 */ +4218 public static class SentenceForm implements Serializable +4219 { +4220 private static final long serialVersionUID = 1246527948419533147L; +4221 public StatefulRNG rng; +4222 public int minWords, maxWords, maxChars; +4223 public String[] midPunctuation, endPunctuation; +4224 public double midPunctuationFrequency; +4225 public FakeLanguageGen language; +4226 public SentenceForm() +4227 { +4228 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, +4229 new String[]{",", ",", ",", ";", ";"}, +4230 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4231 } +4232 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) +4233 { +4234 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, +4235 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4236 } +4237 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4238 String[] endPunctuation, double midPunctuationFrequency) +4239 { +4240 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4241 midPunctuationFrequency, -1); +4242 } +4243 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4244 String[] endPunctuation, double midPunctuationFrequency, int maxChars) +4245 { +4246 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4247 midPunctuationFrequency, maxChars); +4248 } +4249 +4250 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, +4251 String[] midPunctuation, String[] endPunctuation, +4252 double midPunctuationFrequency, int maxChars) +4253 { +4254 this.language = language; +4255 this.rng = new StatefulRNG(rng.getState()); +4256 this.minWords = minWords; +4257 this.maxWords = maxWords; +4258 this.midPunctuation = midPunctuation; +4259 this.endPunctuation = endPunctuation; +4260 this.midPunctuationFrequency = midPunctuationFrequency; +4261 this.maxChars = maxChars; +4262 } +4263 public String sentence() +4264 { +4265 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, +4266 midPunctuationFrequency, maxChars); +4267 } +4268 +4269 public String serializeToString() { +4270 return language.serializeToString() + '℘' + +4271 rng.getState() + '℘' + +4272 minWords + '℘' + +4273 maxWords + '℘' + +4274 StringKit.join("ℙ", midPunctuation) + '℘' + +4275 StringKit.join("ℙ", endPunctuation) + '℘' + +4276 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + +4277 maxChars; +4278 } +4279 public static SentenceForm deserializeFromString(String ser) +4280 { +4281 int gap = ser.indexOf('℘'); +4282 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); +4283 StatefulRNG rng = new StatefulRNG( +4284 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4285 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4286 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4287 String[] midPunctuation = +4288 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4289 String[] endPunctuation = +4290 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4291 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4292 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); +4293 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); +4294 } +4295 } +4296} diff --git a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.html b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.html index ec9e555de4..9b8646dc36 100644 --- a/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.html +++ b/docs/squidlib-util/src-html/squidpony/FakeLanguageGen.html @@ -2059,2201 +2059,2249 @@ 2051 */ 2052 public static final FakeLanguageGen ALIEN_O = alien_o().register(); 2053 -2054 /** -2055 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages -2056 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric -2057 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this -2058 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, -2059 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null -2060 * elements in its original state, so some code may rely on the items being usable and non-null. -2061 */ -2062 public static final FakeLanguageGen[] registered; -2063 -2064 static { -2065 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. -2066 registered = new FakeLanguageGen[registry.size()-1]; -2067 for (int i = 0; i < registered.length; i++) { -2068 registered[i] = registry.getAt(i+1); -2069 } -2070 } -2071 /** -2072 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . -2073 */ -2074 public FakeLanguageGen() { -2075 this( -2076 new String[]{ -2077 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2078 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", -2079 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2080 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", -2081 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", -2082 }, -2083 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, -2084 new String[]{ -2085 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", -2086 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", -2087 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", -2088 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", -2089 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", -2090 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", -2091 "b", "d", "f", "g", "h", "l", "m", "n", -2092 "p", "r", "s", "sh", "t", "th", -2093 "b", "d", "f", "g", "h", "l", "m", "n", -2094 "p", "r", "s", "sh", "t", "th", -2095 "r", "s", "t", "l", "n", -2096 "str", "spr", "spl", "wr", "kn", "kn", "gn", -2097 }, -2098 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", -2099 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", -2100 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" -2101 }, -2102 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", -2103 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", -2104 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", -2105 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", -2106 }, -2107 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2108 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2109 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", -2110 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", -2111 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2112 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", -2113 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", -2114 }, -2115 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); -2116 } -2117 -2118 /** -2119 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2120 * class, LOVECRAFT and GREEK_ROMANIZED. -2121 * -2122 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2123 * of a word or in the middle; elements may be repeated to make them more common -2124 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2125 * middle of the word; all openingVowels are automatically copied into this internally. -2126 * Elements may be repeated to make them more common -2127 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2128 * at the start of a word; elements may be repeated to make them more common -2129 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2130 * between vowels; all closingConsonants are automatically copied into this internally. -2131 * Elements may be repeated to make them more common -2132 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2133 * at the end of a word; elements may be repeated to make them more common -2134 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2135 * whatever the word should end in; elements may be repeated to make them more common -2136 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2137 * then "a-a" may be possible; elements may be repeated to make them more common -2138 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2139 * tied to syllableFrequencies -2140 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2141 * represents how often each syllable count should appear relative to other counts; there -2142 * is no need to restrict the numbers to add up to any other number -2143 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2144 * higher numbers yield more words starting with vowels -2145 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2146 * numbers yield more words ending in vowels -2147 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2148 * often a vowel will be split into two vowels separated by one of those splitters -2149 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2150 * closingSyllables is used instead of ending normally -2151 */ -2152 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2153 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2154 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2155 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { -2156 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, -2157 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, -2158 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); -2159 } -2160 -2161 /** -2162 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this -2163 * class, LOVECRAFT and GREEK_ROMANIZED. -2164 * -2165 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start -2166 * of a word or in the middle; elements may be repeated to make them more common -2167 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the -2168 * middle of the word; all openingVowels are automatically copied into this internally. -2169 * Elements may be repeated to make them more common -2170 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear -2171 * at the start of a word; elements may be repeated to make them more common -2172 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear -2173 * between vowels; all closingConsonants are automatically copied into this internally. +2054 // àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳ +2055 // çðþñýćĉċčďđĝğġģĥħĵķĺļľŀłńņňŋŕŗřśŝşšţťŵŷÿźżžșțẁẃẅ +2056 private static FakeLanguageGen alien_u(){ +2057 return new FakeLanguageGen( +2058 new String[]{ +2059 "a", "a", "a", "a", "ä", "i", "o", "o", "o", "ö", "u", "u", "u", "u", "u", "u", "ü", "ü" +2060 }, +2061 new String[]{}, +2062 new String[]{ +2063 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2064 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2065 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2066 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2067 }, +2068 new String[]{ +2069 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", "h", "h", "h", "h", "ħ", +2070 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2071 "q", "q", "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2072 "w", "w", "w", "w", "ẃ", "y", "y", "y", "y", "ý" +2073 }, +2074 new String[]{ +2075 "b", "b", "b", "b", "d", "d", "g", "g", "ġ", +2076 "l", "l", "l", "l", "ł", "m", "m", "m", "m", "m", "n", "n", "n", "n", "ñ", "ŋ", "p", "p", "p", +2077 "r", "r", "r", "ŕ", "s", "s", "s", "s", "ś", "v", "v", "v", "v", +2078 }, +2079 new String[]{"emb", "embrid", "embraŋ", "eŋ", "eŋul", "eŋov", "eẃul", "eẃuld", "eẃulb", +2080 "eviś", "evim", "ełurn", "ełav", "egiġ", "ergiġ", "elgiġ", "eŕu", "eŕup", "eŕulm", "eŕuv", +2081 "eħul", "eħid", "eħiŋ", "eyü", "eyür", "eyürl", "eyüld", "eyüns", "eqä", "eqäp", "eqäġ", +2082 "esu", "esumb", "esulg", "esurl", "eśo", "eśold", "eśolg", "eśu", "eśur", "eśuŋ", +2083 "eñu", "eñuns", "eñurn", "eño", "eñolb", "eñols" +2084 }, +2085 new String[]{"'"}, new int[]{1, 2, 3, 4, 5}, new double[]{3, 4, 7, 5, 2}, 0.4, 0.15, 0.06, 0.5, null, true); +2086 } +2087 +2088 /** +2089 * Fantasy/sci-fi language that could be spoken by some very-non-human culture that would typically be fitting for +2090 * an alien species. This alien language is meant to have an abrupt change mid-word for many words, with the suffix +2091 * of roughly half of words using the letter "e", which is absent from the rest of the language; these suffixes can +2092 * also use consonant clusters, which are similarly absent elsewhere. The suffixes would make sense as a historical +2093 * relic or as a linguistic holdout from a historical merger. As the name would suggest, it strongly prefers +2094 * using the vowel "u", with it present in about half the groups, and can use the umlaut accent "ü" on some vowels. +2095 * The consonants completely avoid hard sounds like "t" and "k", and don't cluster; they often have special marks. +2096 * This should be relatively easy to pronounce for an alien language, though the words are rather long. +2097 * <br> +2098 * Üweħid vuŕeħid deẃul leŋul waloyeyür; äyovavü... +2099 */ +2100 public static final FakeLanguageGen ALIEN_U = alien_u().register(); +2101 +2102 /** +2103 * An array that stores all the hand-made FakeLanguageGen constants; it does not store randomly-generated languages +2104 * nor does it store modifications or mixes of languages. The order these are stored in is related to the numeric +2105 * codes for languages in the {@link #serializeToString()} output, but neither is dependent on the other if this +2106 * array is changed for some reason (which is not recommended, but not out of the question). If this is modified, +2107 * then it is probably a bad idea to assign null to any elements in registered; special care is taken to avoid null +2108 * elements in its original state, so some code may rely on the items being usable and non-null. +2109 */ +2110 public static final FakeLanguageGen[] registered; +2111 +2112 static { +2113 // the first item in registry is null so it can be a placeholder for random languages; we want to skip it. +2114 registered = new FakeLanguageGen[registry.size()-1]; +2115 for (int i = 0; i < registered.length; i++) { +2116 registered[i] = registry.getAt(i+1); +2117 } +2118 } +2119 /** +2120 * Zero-arg constructor for a FakeLanguageGen; produces a FakeLanguageGen equivalent to FakeLanguageGen.ENGLISH . +2121 */ +2122 public FakeLanguageGen() { +2123 this( +2124 new String[]{ +2125 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2126 "a", "a", "a", "a", "o", "o", "o", "e", "e", "e", "e", "e", "i", "i", "i", "i", "u", +2127 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2128 "a", "a", "a", "o", "o", "e", "e", "e", "i", "i", "i", "u", +2129 "au", "ai", "ai", "ou", "ea", "ie", "io", "ei", +2130 }, +2131 new String[]{"u", "u", "oa", "oo", "oo", "oo", "ee", "ee", "ee", "ee",}, +2132 new String[]{ +2133 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gl", "gr", "h", "j", "k", "l", "m", "n", +2134 "p", "pl", "pr", "qu", "r", "s", "sh", "sk", "st", "sp", "sl", "sm", "sn", "t", "tr", "th", "thr", "v", "w", "y", "z", +2135 "b", "bl", "br", "c", "cl", "cr", "ch", "d", "dr", "f", "fl", "fr", "g", "gr", "h", "j", "k", "l", "m", "n", +2136 "p", "pl", "pr", "r", "s", "sh", "st", "sp", "sl", "t", "tr", "th", "w", "y", +2137 "b", "br", "c", "ch", "d", "dr", "f", "g", "h", "j", "l", "m", "n", +2138 "p", "r", "s", "sh", "st", "sl", "t", "tr", "th", +2139 "b", "d", "f", "g", "h", "l", "m", "n", +2140 "p", "r", "s", "sh", "t", "th", +2141 "b", "d", "f", "g", "h", "l", "m", "n", +2142 "p", "r", "s", "sh", "t", "th", +2143 "r", "s", "t", "l", "n", +2144 "str", "spr", "spl", "wr", "kn", "kn", "gn", +2145 }, +2146 new String[]{"x", "cst", "bs", "ff", "lg", "g", "gs", +2147 "ll", "ltr", "mb", "mn", "mm", "ng", "ng", "ngl", "nt", "ns", "nn", "ps", "mbl", "mpr", +2148 "pp", "ppl", "ppr", "rr", "rr", "rr", "rl", "rtn", "ngr", "ss", "sc", "rst", "tt", "tt", "ts", "ltr", "zz" +2149 }, +2150 new String[]{"b", "rb", "bb", "c", "rc", "ld", "d", "ds", "dd", "f", "ff", "lf", "rf", "rg", "gs", "ch", "lch", "rch", "tch", +2151 "ck", "ck", "lk", "rk", "l", "ll", "lm", "m", "rm", "mp", "n", "nk", "nch", "nd", "ng", "ng", "nt", "ns", "lp", "rp", +2152 "p", "r", "rn", "rts", "s", "s", "s", "s", "ss", "ss", "st", "ls", "t", "t", "ts", "w", "wn", "x", "ly", "lly", "z", +2153 "b", "c", "d", "f", "g", "k", "l", "m", "n", "p", "r", "s", "t", "w", +2154 }, +2155 new String[]{"ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2156 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2157 "ate", "ite", "ism", "ist", "er", "er", "er", "ed", "ed", "ed", "es", "es", "ied", "y", "y", "y", "y", +2158 "ay", "ay", "ey", "oy", "ay", "ay", "ey", "oy", +2159 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2160 "ough", "aught", "ant", "ont", "oe", "ance", "ell", "eal", "oa", "urt", "ut", "iom", "ion", "ion", "ision", "ation", "ation", "ition", +2161 "ily", "ily", "ily", "adly", "owly", "oorly", "ardly", "iedly", +2162 }, +2163 new String[]{}, new int[]{1, 2, 3, 4}, new double[]{10, 11, 4, 1}, 0.22, 0.1, 0.0, 0.22, englishSanityChecks, true); +2164 } +2165 +2166 /** +2167 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2168 * class, LOVECRAFT and GREEK_ROMANIZED. +2169 * +2170 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2171 * of a word or in the middle; elements may be repeated to make them more common +2172 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2173 * middle of the word; all openingVowels are automatically copied into this internally. 2174 * Elements may be repeated to make them more common -2175 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear -2176 * at the end of a word; elements may be repeated to make them more common -2177 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in -2178 * whatever the word should end in; elements may be repeated to make them more common -2179 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, -2180 * then "a-a" may be possible; elements may be repeated to make them more common -2181 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely -2182 * tied to syllableFrequencies -2183 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and -2184 * represents how often each syllable count should appear relative to other counts; there -2185 * is no need to restrict the numbers to add up to any other number -2186 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; -2187 * higher numbers yield more words starting with vowels -2188 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher -2189 * numbers yield more words ending in vowels -2190 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how -2191 * often a vowel will be split into two vowels separated by one of those splitters -2192 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of -2193 * closingSyllables is used instead of ending normally -2194 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many -2195 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets -2196 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a -2197 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly -2198 */ -2199 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2200 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, -2201 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, -2202 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, -2203 Pattern[] sane, boolean clean) { -2204 this.openingVowels = openingVowels; -2205 this.midVowels = new String[openingVowels.length + midVowels.length]; -2206 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); -2207 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); -2208 this.openingConsonants = openingConsonants; -2209 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; -2210 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); -2211 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); -2212 this.closingConsonants = closingConsonants; -2213 this.vowelSplitters = vowelSplitters; -2214 this.closingSyllables = closingSyllables; -2215 -2216 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); -2217 -2218 totalSyllableFrequency = this.syllableFrequencies.values().sum(); -2219 if (vowelStartFrequency > 1.0) -2220 this.vowelStartFrequency = 1.0 / vowelStartFrequency; -2221 else -2222 this.vowelStartFrequency = vowelStartFrequency; -2223 if (vowelEndFrequency > 1.0) -2224 this.vowelEndFrequency = 1.0 / vowelEndFrequency; -2225 else -2226 this.vowelEndFrequency = vowelEndFrequency; -2227 if (vowelSplitters.length == 0) -2228 this.vowelSplitFrequency = 0.0; -2229 else if (vowelSplitFrequency > 1.0) -2230 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; -2231 else -2232 this.vowelSplitFrequency = vowelSplitFrequency; -2233 if (closingSyllables.length == 0) -2234 this.syllableEndFrequency = 0.0; -2235 else if (syllableEndFrequency > 1.0) -2236 this.syllableEndFrequency = 1.0 / syllableEndFrequency; -2237 else -2238 this.syllableEndFrequency = syllableEndFrequency; -2239 this.clean = clean; -2240 sanityChecks = sane; -2241 modifiers = new ArrayList<>(16); -2242 } -2243 -2244 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, -2245 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, -2246 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, -2247 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, -2248 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, -2249 List<Modifier> modifiers) { -2250 this.openingVowels = copyStrings(openingVowels); -2251 this.midVowels = copyStrings(midVowels); -2252 this.openingConsonants = copyStrings(openingConsonants); -2253 this.midConsonants = copyStrings(midConsonants); -2254 this.closingConsonants = copyStrings(closingConsonants); -2255 this.closingSyllables = copyStrings(closingSyllables); -2256 this.vowelSplitters = copyStrings(vowelSplitters); -2257 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); -2258 this.vowelStartFrequency = vowelStartFrequency; -2259 this.vowelEndFrequency = vowelEndFrequency; -2260 this.vowelSplitFrequency = vowelSplitFrequency; -2261 this.syllableEndFrequency = syllableEndFrequency; -2262 for (Double freq : this.syllableFrequencies.values()) { -2263 totalSyllableFrequency += freq; -2264 } -2265 if (sanityChecks == null) -2266 this.sanityChecks = null; -2267 else { -2268 this.sanityChecks = new Pattern[sanityChecks.length]; -2269 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); -2270 } -2271 this.clean = clean; -2272 this.modifiers = new ArrayList<>(modifiers); -2273 } -2274 -2275 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, -2276 Set<String> forbidden, RNG rng, double repeatSingleChance, -2277 int preferredLimit) { -2278 int l, sz = parts.size(); -2279 List<String> working = new ArrayList<>(sz * 24); -2280 String pair; -2281 for (int e = 0; e < parts.size(); e++) { -2282 Map.Entry<String, String> sn = parts.entryAt(e); -2283 if (missingSounds.contains(sn.getKey())) -2284 continue; -2285 for (String t : sn.getValue().split(" ")) { -2286 if (forbidden.contains(t)) -2287 continue; -2288 l = t.length(); -2289 int num; -2290 char c; -2291 switch (l) { -2292 case 0: -2293 break; -2294 case 1: -2295 working.add(t); -2296 working.add(t); -2297 working.add(t); -2298 c = t.charAt(0); -2299 num = 0; -2300 boolean repeat = true; -2301 switch (c) { -2302 case 'w': -2303 num += 2; -2304 case 'y': -2305 case 'h': -2306 num += 4; -2307 case 'q': -2308 case 'x': -2309 num += 4; -2310 repeat = false; -2311 break; -2312 case 'i': -2313 case 'u': -2314 repeat = false; -2315 num = 13; -2316 break; -2317 case 'z': -2318 case 'v': -2319 num = 4; -2320 break; -2321 case 'j': -2322 num = 7; -2323 break; -2324 default: -2325 if (e >= preferredLimit) -2326 num = 6; -2327 else -2328 num = 13; -2329 } -2330 for (int i = 0; i < num * 3; i++) { -2331 if (rng.nextDouble() < 0.75) { -2332 working.add(t); -2333 } -2334 } -2335 -2336 if (repeat && rng.nextDouble() < repeatSingleChance) { -2337 pair = t + t; -2338 if (missingSounds.contains(pair)) -2339 continue; -2340 working.add(pair); -2341 working.add(pair); -2342 working.add(pair); -2343 if (rng.nextDouble() < 0.7) { -2344 working.add(pair); -2345 working.add(pair); -2346 } -2347 if (rng.nextDouble() < 0.7) { -2348 working.add(pair); -2349 } -2350 } -2351 -2352 break; -2353 case 2: -2354 if (rng.nextDouble() < 0.65) { -2355 c = t.charAt(1); -2356 num = 0; -2357 switch (c) { -2358 case 'z': -2359 num = 1; -2360 break; -2361 case 'w': -2362 num = 3; -2363 break; -2364 case 'n': -2365 num = 4; -2366 break; -2367 default: -2368 -2369 if (e >= preferredLimit) -2370 num = 2; -2371 else -2372 num = 7; -2373 } -2374 working.add(t); -2375 for (int i = 0; i < num; i++) { -2376 if (rng.nextDouble() < 0.25) { -2377 working.add(t); -2378 } -2379 } -2380 } -2381 break; -2382 case 3: -2383 if (rng.nextDouble() < 0.5) { -2384 c = t.charAt(0); -2385 switch (c) { -2386 case 'z': -2387 num = 1; -2388 break; -2389 case 'w': -2390 num = 3; -2391 break; -2392 case 'n': -2393 num = 4; -2394 break; -2395 default: -2396 if (e >= preferredLimit) -2397 num = 2; -2398 else -2399 num = 6; -2400 } -2401 working.add(t); -2402 for (int i = 0; i < num; i++) { -2403 if (rng.nextDouble() < 0.2) { -2404 working.add(t); -2405 } -2406 } -2407 } -2408 break; -2409 default: -2410 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { -2411 working.add(t); -2412 } -2413 break; -2414 } -2415 } -2416 } -2417 return working.toArray(new String[0]); -2418 } -2419 -2420 /*private static final String[][] openVowels = new String[][]{ -2421 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, -2422 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, -2423 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, -2424 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, -2425 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, -2426 }; -2427*/ -2428 -2429 public static FakeLanguageGen randomLanguage(RNG rng) { -2430 return randomLanguage(rng.nextLong()); -2431 } -2432 -2433 public static FakeLanguageGen randomLanguage(long seed) { -2434 StatefulRNG rng = new StatefulRNG(seed); -2435 int[] lengths = new int[rng.between(3, 5)]; -2436 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); -2437 double[] chances = new double[lengths.length]; -2438 System.arraycopy(new double[]{ -2439 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) -2440 }, 0, chances, 0, chances.length); -2441 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); -2442 int sz = openCons.size(); -2443 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); -2444 OrderedMap<String, String> -2445 parts0 = new OrderedMap<>(openVowels), -2446 parts1 = new OrderedMap<>(openCons), -2447 parts2 = new OrderedMap<>(midCons), -2448 parts3 = new OrderedMap<>(closeCons); -2449 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); -2450 parts1.reorder(reordering); -2451 parts2.reorder(reordering); -2452 parts3.reorder(reordering); -2453 parts0.reorder(vOrd); -2454 int n = 0; -2455 -2456 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; -2457 -2458 for (n = 0; n < mn; n++) { -2459 missingSounds.add(parts0.keyAt(0)); -2460 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); -2461 parts0.removeFirst(); -2462 } -2463 p0s = parts0.size(); -2464 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); -2465 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; -2466 int vowelAccent = rng.between(1, 7); -2467 for (int i = 0; i < sz0; i++) { -2468 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; -2469 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; -2470 } -2471 if (rng.nextDouble() < 0.8) { -2472 for (int i = 0; i < sz0; i++) { -2473 char ac = nextAccents[i], ua = unaccented[i]; -2474 String v = "", uas = String.valueOf(ua); -2475 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); -2476 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); -2477 for (int j = 0; j < p0s; j++) { -2478 String k = parts0.keyAt(j); -2479 if (uas.equals(k)) -2480 v = parts0.getAt(j); -2481 else { -2482 String current = parts0.getAt(j); -2483 String[] splits = current.split(" "); -2484 for (int s = 0; s < splits.length; s++) { -2485 if (forbidden.contains(uas) && splits[s].contains(uas)) -2486 forbidden.add(splits[s].replace(ua, ac)); -2487 } -2488 parts0.put(k, rep.replace(current)); -2489 } -2490 } -2491 parts0.put(String.valueOf(ac), repLess.replace(v)); -2492 } -2493 } -2494 -2495 n = 0; -2496 if (rng.nextDouble() < 0.75) { -2497 missingSounds.add("z"); -2498 Collections.addAll(forbidden, parts1.get("z").split(" ")); -2499 Collections.addAll(forbidden, parts2.get("z").split(" ")); -2500 Collections.addAll(forbidden, parts3.get("z").split(" ")); -2501 n++; -2502 } -2503 if (rng.nextDouble() < 0.82) { -2504 missingSounds.add("x"); -2505 Collections.addAll(forbidden, parts1.get("x").split(" ")); -2506 Collections.addAll(forbidden, parts2.get("x").split(" ")); -2507 Collections.addAll(forbidden, parts3.get("x").split(" ")); -2508 n++; -2509 } -2510 if (rng.nextDouble() < 0.92) { -2511 missingSounds.add("qu"); -2512 Collections.addAll(forbidden, parts1.get("qu").split(" ")); -2513 Collections.addAll(forbidden, parts2.get("qu").split(" ")); -2514 Collections.addAll(forbidden, parts3.get("qu").split(" ")); -2515 n++; -2516 } -2517 if (rng.nextDouble() < 0.96) { -2518 missingSounds.add("q"); -2519 Collections.addAll(forbidden, parts1.get("q").split(" ")); -2520 Collections.addAll(forbidden, parts2.get("q").split(" ")); -2521 Collections.addAll(forbidden, parts3.get("q").split(" ")); -2522 n++; -2523 } -2524 if (rng.nextDouble() < 0.97) { -2525 missingSounds.add("tl"); -2526 Collections.addAll(forbidden, parts1.get("tl").split(" ")); -2527 Collections.addAll(forbidden, parts2.get("tl").split(" ")); -2528 Collections.addAll(forbidden, parts3.get("tl").split(" ")); -2529 n++; -2530 } -2531 if (rng.nextDouble() < 0.86) { -2532 missingSounds.add("ph"); -2533 Collections.addAll(forbidden, parts1.get("ph").split(" ")); -2534 Collections.addAll(forbidden, parts2.get("ph").split(" ")); -2535 Collections.addAll(forbidden, parts3.get("ph").split(" ")); -2536 n++; -2537 } -2538 if (rng.nextDouble() < 0.94) { -2539 missingSounds.add("kh"); -2540 Collections.addAll(forbidden, parts1.get("kh").split(" ")); -2541 Collections.addAll(forbidden, parts2.get("kh").split(" ")); -2542 Collections.addAll(forbidden, parts3.get("kh").split(" ")); -2543 n++; -2544 } -2545 if (rng.nextDouble() < 0.96) { -2546 missingSounds.add("bh"); -2547 missingSounds.add("dh"); -2548 Collections.addAll(forbidden, parts1.get("bh").split(" ")); -2549 Collections.addAll(forbidden, parts2.get("bh").split(" ")); -2550 Collections.addAll(forbidden, parts3.get("bh").split(" ")); -2551 Collections.addAll(forbidden, parts1.get("dh").split(" ")); -2552 Collections.addAll(forbidden, parts2.get("dh").split(" ")); -2553 Collections.addAll(forbidden, parts3.get("dh").split(" ")); -2554 n++; -2555 n++; -2556 } -2557 -2558 for (; n < sz * removalRate; n++) { -2559 missingSounds.add(parts1.keyAt(n)); -2560 missingSounds.add(parts2.keyAt(n)); -2561 missingSounds.add(parts3.keyAt(n)); -2562 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); -2563 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); -2564 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); -2565 } -2566 -2567 return new FakeLanguageGen( -2568 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), -2569 new String[]{"y", "y"}, -2570 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), -2571 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), -2572 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), -2573 new String[]{}, -2574 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); -2575 } -2576 -2577 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { -2578 CharSequence fixed = removeAccents(testing); -2579 for (int i = 0; i < checks.length; i++) { -2580 if (checks[i].matcher(fixed).find()) -2581 return false; -2582 } -2583 return true; -2584 } -2585 -2586 /** -2587 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text -2588 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives -2589 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers -2590 * that could look like letters. -2591 * @param testing the text, as a CharSequence such as a String, to check -2592 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't -2593 */ -2594 public static boolean checkVulgarity(CharSequence testing) -2595 { -2596 CharSequence fixed = removeAccents(testing); -2597 for (int i = 0; i < vulgarChecks.length; i++) { -2598 if (vulgarChecks[i].matcher(fixed).find()) -2599 { -2600 System.out.println(vulgarChecks[i]); -2601 return true; -2602 } -2603 } -2604 return false; -2605 } -2606 -2607 /** -2608 * Generate a word from this FakeLanguageGen, using and changing the current seed. -2609 * -2610 * @param capitalize true if the word should start with a capital letter, false otherwise -2611 * @return a word in the fake language as a String -2612 */ -2613 public String word(boolean capitalize) { -2614 return word(srng, capitalize); -2615 } -2616 -2617 /** -2618 * Generate a word from this FakeLanguageGen using the specified RNG. -2619 * -2620 * @param rng the RNG to use for the randomized string building -2621 * @param capitalize true if the word should start with a capital letter, false otherwise -2622 * @return a word in the fake language as a String -2623 */ -2624 public String word(RNG rng, boolean capitalize) { -2625 while (true) { -2626 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2627 double syllableChance = rng.nextDouble(totalSyllableFrequency); -2628 int syllables = 1, i = 0; -2629 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { -2630 if (syllableChance < kv.getDoubleValue()) { -2631 syllables = kv.getIntKey(); -2632 break; -2633 } else -2634 syllableChance -= kv.getDoubleValue(); -2635 } -2636 if (rng.nextDouble() < vowelStartFrequency) { -2637 sb.append(rng.getRandomElement(openingVowels)); -2638 if (syllables == 1) -2639 sb.append(rng.getRandomElement(closingConsonants)); -2640 else -2641 sb.append(rng.getRandomElement(midConsonants)); -2642 i++; -2643 } else { -2644 sb.append(rng.getRandomElement(openingConsonants)); -2645 } -2646 String close = ""; -2647 boolean redouble = false; -2648 if (i < syllables) { -2649 if (rng.nextDouble() < syllableEndFrequency) { -2650 close = rng.getRandomElement(closingSyllables); -2651 if (close.contains("@") && (syllables & 1) == 0) { -2652 redouble = true; -2653 syllables = (syllables | 1) >> 1; +2175 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2176 * at the start of a word; elements may be repeated to make them more common +2177 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2178 * between vowels; all closingConsonants are automatically copied into this internally. +2179 * Elements may be repeated to make them more common +2180 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2181 * at the end of a word; elements may be repeated to make them more common +2182 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2183 * whatever the word should end in; elements may be repeated to make them more common +2184 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2185 * then "a-a" may be possible; elements may be repeated to make them more common +2186 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2187 * tied to syllableFrequencies +2188 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2189 * represents how often each syllable count should appear relative to other counts; there +2190 * is no need to restrict the numbers to add up to any other number +2191 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2192 * higher numbers yield more words starting with vowels +2193 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2194 * numbers yield more words ending in vowels +2195 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2196 * often a vowel will be split into two vowels separated by one of those splitters +2197 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2198 * closingSyllables is used instead of ending normally +2199 */ +2200 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2201 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2202 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2203 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency) { +2204 this(openingVowels, midVowels, openingConsonants, midConsonants, closingConsonants, closingSyllables, +2205 vowelSplitters, syllableLengths, syllableFrequencies, vowelStartFrequency, vowelEndFrequency, +2206 vowelSplitFrequency, syllableEndFrequency, englishSanityChecks, true); +2207 } +2208 +2209 /** +2210 * This is a very complicated constructor! Maybe look at the calls to this to initialize static members of this +2211 * class, LOVECRAFT and GREEK_ROMANIZED. +2212 * +2213 * @param openingVowels String array where each element is a vowel or group of vowels that may appear at the start +2214 * of a word or in the middle; elements may be repeated to make them more common +2215 * @param midVowels String array where each element is a vowel or group of vowels that may appear in the +2216 * middle of the word; all openingVowels are automatically copied into this internally. +2217 * Elements may be repeated to make them more common +2218 * @param openingConsonants String array where each element is a consonant or consonant cluster that can appear +2219 * at the start of a word; elements may be repeated to make them more common +2220 * @param midConsonants String array where each element is a consonant or consonant cluster than can appear +2221 * between vowels; all closingConsonants are automatically copied into this internally. +2222 * Elements may be repeated to make them more common +2223 * @param closingConsonants String array where each element is a consonant or consonant cluster than can appear +2224 * at the end of a word; elements may be repeated to make them more common +2225 * @param closingSyllables String array where each element is a syllable starting with a vowel and ending in +2226 * whatever the word should end in; elements may be repeated to make them more common +2227 * @param vowelSplitters String array where each element is a mark that goes between vowels, so if "-" is in this, +2228 * then "a-a" may be possible; elements may be repeated to make them more common +2229 * @param syllableLengths int array where each element is a possible number of syllables a word can use; closely +2230 * tied to syllableFrequencies +2231 * @param syllableFrequencies double array where each element corresponds to an element in syllableLengths and +2232 * represents how often each syllable count should appear relative to other counts; there +2233 * is no need to restrict the numbers to add up to any other number +2234 * @param vowelStartFrequency a double between 0.0 and 1.0 that determines how often words start with vowels; +2235 * higher numbers yield more words starting with vowels +2236 * @param vowelEndFrequency a double between 0.0 and 1.0 that determines how often words end with vowels; higher +2237 * numbers yield more words ending in vowels +2238 * @param vowelSplitFrequency a double between 0.0 and 1.0 that, if vowelSplitters is not empty, determines how +2239 * often a vowel will be split into two vowels separated by one of those splitters +2240 * @param syllableEndFrequency a double between 0.0 and 1.0 that determines how often an element of +2241 * closingSyllables is used instead of ending normally +2242 * @param sane true to perform sanity checks for pronounce-able sounds to most English speakers, replacing many +2243 * words that are impossible to say; slows down generation slightly, irrelevant for non-Latin alphabets +2244 * @param clean true to perform vulgarity/obscenity checks on the word, replacing it if it is too close to a +2245 * common English vulgarity, obscenity, or slur/epithet; slows down generation slightly +2246 */ +2247 public FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2248 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, String[] vowelSplitters, +2249 int[] syllableLengths, double[] syllableFrequencies, double vowelStartFrequency, +2250 double vowelEndFrequency, double vowelSplitFrequency, double syllableEndFrequency, +2251 Pattern[] sane, boolean clean) { +2252 this.openingVowels = openingVowels; +2253 this.midVowels = new String[openingVowels.length + midVowels.length]; +2254 System.arraycopy(midVowels, 0, this.midVowels, 0, midVowels.length); +2255 System.arraycopy(openingVowels, 0, this.midVowels, midVowels.length, openingVowels.length); +2256 this.openingConsonants = openingConsonants; +2257 this.midConsonants = new String[midConsonants.length + closingConsonants.length]; +2258 System.arraycopy(midConsonants, 0, this.midConsonants, 0, midConsonants.length); +2259 System.arraycopy(closingConsonants, 0, this.midConsonants, midConsonants.length, closingConsonants.length); +2260 this.closingConsonants = closingConsonants; +2261 this.vowelSplitters = vowelSplitters; +2262 this.closingSyllables = closingSyllables; +2263 +2264 this.syllableFrequencies = new IntDoubleOrderedMap(syllableLengths, syllableFrequencies, 0.75f); +2265 +2266 totalSyllableFrequency = this.syllableFrequencies.values().sum(); +2267 if (vowelStartFrequency > 1.0) +2268 this.vowelStartFrequency = 1.0 / vowelStartFrequency; +2269 else +2270 this.vowelStartFrequency = vowelStartFrequency; +2271 if (vowelEndFrequency > 1.0) +2272 this.vowelEndFrequency = 1.0 / vowelEndFrequency; +2273 else +2274 this.vowelEndFrequency = vowelEndFrequency; +2275 if (vowelSplitters.length == 0) +2276 this.vowelSplitFrequency = 0.0; +2277 else if (vowelSplitFrequency > 1.0) +2278 this.vowelSplitFrequency = 1.0 / vowelSplitFrequency; +2279 else +2280 this.vowelSplitFrequency = vowelSplitFrequency; +2281 if (closingSyllables.length == 0) +2282 this.syllableEndFrequency = 0.0; +2283 else if (syllableEndFrequency > 1.0) +2284 this.syllableEndFrequency = 1.0 / syllableEndFrequency; +2285 else +2286 this.syllableEndFrequency = syllableEndFrequency; +2287 this.clean = clean; +2288 sanityChecks = sane; +2289 modifiers = new ArrayList<>(16); +2290 } +2291 +2292 private FakeLanguageGen(String[] openingVowels, String[] midVowels, String[] openingConsonants, +2293 String[] midConsonants, String[] closingConsonants, String[] closingSyllables, +2294 String[] vowelSplitters, IntDoubleOrderedMap syllableFrequencies, +2295 double vowelStartFrequency, double vowelEndFrequency, double vowelSplitFrequency, +2296 double syllableEndFrequency, Pattern[] sanityChecks, boolean clean, +2297 List<Modifier> modifiers) { +2298 this.openingVowels = copyStrings(openingVowels); +2299 this.midVowels = copyStrings(midVowels); +2300 this.openingConsonants = copyStrings(openingConsonants); +2301 this.midConsonants = copyStrings(midConsonants); +2302 this.closingConsonants = copyStrings(closingConsonants); +2303 this.closingSyllables = copyStrings(closingSyllables); +2304 this.vowelSplitters = copyStrings(vowelSplitters); +2305 this.syllableFrequencies = new IntDoubleOrderedMap(syllableFrequencies); +2306 this.vowelStartFrequency = vowelStartFrequency; +2307 this.vowelEndFrequency = vowelEndFrequency; +2308 this.vowelSplitFrequency = vowelSplitFrequency; +2309 this.syllableEndFrequency = syllableEndFrequency; +2310 for (Double freq : this.syllableFrequencies.values()) { +2311 totalSyllableFrequency += freq; +2312 } +2313 if (sanityChecks == null) +2314 this.sanityChecks = null; +2315 else { +2316 this.sanityChecks = new Pattern[sanityChecks.length]; +2317 System.arraycopy(sanityChecks, 0, this.sanityChecks, 0, sanityChecks.length); +2318 } +2319 this.clean = clean; +2320 this.modifiers = new ArrayList<>(modifiers); +2321 } +2322 +2323 private static String[] processParts(OrderedMap<String, String> parts, Set<String> missingSounds, +2324 Set<String> forbidden, RNG rng, double repeatSingleChance, +2325 int preferredLimit) { +2326 int l, sz = parts.size(); +2327 List<String> working = new ArrayList<>(sz * 24); +2328 String pair; +2329 for (int e = 0; e < parts.size(); e++) { +2330 Map.Entry<String, String> sn = parts.entryAt(e); +2331 if (missingSounds.contains(sn.getKey())) +2332 continue; +2333 for (String t : sn.getValue().split(" ")) { +2334 if (forbidden.contains(t)) +2335 continue; +2336 l = t.length(); +2337 int num; +2338 char c; +2339 switch (l) { +2340 case 0: +2341 break; +2342 case 1: +2343 working.add(t); +2344 working.add(t); +2345 working.add(t); +2346 c = t.charAt(0); +2347 num = 0; +2348 boolean repeat = true; +2349 switch (c) { +2350 case 'w': +2351 num += 2; +2352 case 'y': +2353 case 'h': +2354 num += 4; +2355 case 'q': +2356 case 'x': +2357 num += 4; +2358 repeat = false; +2359 break; +2360 case 'i': +2361 case 'u': +2362 repeat = false; +2363 num = 13; +2364 break; +2365 case 'z': +2366 case 'v': +2367 num = 4; +2368 break; +2369 case 'j': +2370 num = 7; +2371 break; +2372 default: +2373 if (e >= preferredLimit) +2374 num = 6; +2375 else +2376 num = 13; +2377 } +2378 for (int i = 0; i < num * 3; i++) { +2379 if (rng.nextDouble() < 0.75) { +2380 working.add(t); +2381 } +2382 } +2383 +2384 if (repeat && rng.nextDouble() < repeatSingleChance) { +2385 pair = t + t; +2386 if (missingSounds.contains(pair)) +2387 continue; +2388 working.add(pair); +2389 working.add(pair); +2390 working.add(pair); +2391 if (rng.nextDouble() < 0.7) { +2392 working.add(pair); +2393 working.add(pair); +2394 } +2395 if (rng.nextDouble() < 0.7) { +2396 working.add(pair); +2397 } +2398 } +2399 +2400 break; +2401 case 2: +2402 if (rng.nextDouble() < 0.65) { +2403 c = t.charAt(1); +2404 num = 0; +2405 switch (c) { +2406 case 'z': +2407 num = 1; +2408 break; +2409 case 'w': +2410 num = 3; +2411 break; +2412 case 'n': +2413 num = 4; +2414 break; +2415 default: +2416 +2417 if (e >= preferredLimit) +2418 num = 2; +2419 else +2420 num = 7; +2421 } +2422 working.add(t); +2423 for (int i = 0; i < num; i++) { +2424 if (rng.nextDouble() < 0.25) { +2425 working.add(t); +2426 } +2427 } +2428 } +2429 break; +2430 case 3: +2431 if (rng.nextDouble() < 0.5) { +2432 c = t.charAt(0); +2433 switch (c) { +2434 case 'z': +2435 num = 1; +2436 break; +2437 case 'w': +2438 num = 3; +2439 break; +2440 case 'n': +2441 num = 4; +2442 break; +2443 default: +2444 if (e >= preferredLimit) +2445 num = 2; +2446 else +2447 num = 6; +2448 } +2449 working.add(t); +2450 for (int i = 0; i < num; i++) { +2451 if (rng.nextDouble() < 0.2) { +2452 working.add(t); +2453 } +2454 } +2455 } +2456 break; +2457 default: +2458 if (rng.nextDouble() < 0.3 && (t.charAt(l - 1) != 'z' || rng.nextDouble() < 0.1)) { +2459 working.add(t); +2460 } +2461 break; +2462 } +2463 } +2464 } +2465 return working.toArray(new String[0]); +2466 } +2467 +2468 /*private static final String[][] openVowels = new String[][]{ +2469 new String[]{"a", "a", "a", "a", "aa", "ae", "ai", "au", "ea", "ia", "oa", "ua",}, +2470 new String[]{"e", "e", "e", "e", "ae", "ea", "ee", "ei", "eo", "eu", "ie", "ue",}, +2471 new String[]{"i", "i", "i", "i", "ai", "ei", "ia", "ie", "io", "iu", "oi", "ui",}, +2472 new String[]{"o", "o", "o", "o", "eo", "io", "oa", "oi", "oo", "ou",}, +2473 new String[]{"u", "u", "u", "u", "au", "eu", "iu", "ou", "ua", "ue", "ui",}, +2474 }; +2475*/ +2476 +2477 public static FakeLanguageGen randomLanguage(RNG rng) { +2478 return randomLanguage(rng.nextLong()); +2479 } +2480 +2481 public static FakeLanguageGen randomLanguage(long seed) { +2482 StatefulRNG rng = new StatefulRNG(seed); +2483 int[] lengths = new int[rng.between(3, 5)]; +2484 System.arraycopy(new int[]{1, 2, 3, 4}, 0, lengths, 0, lengths.length); +2485 double[] chances = new double[lengths.length]; +2486 System.arraycopy(new double[]{ +2487 5 + rng.nextDouble(4), 13 + rng.nextDouble(9), 3 + rng.nextDouble(3), 1 + rng.nextDouble(2) +2488 }, 0, chances, 0, chances.length); +2489 double vowelHeavy = rng.between(0.2, 0.5), removalRate = rng.between(0.15, 0.65); +2490 int sz = openCons.size(); +2491 int[] reordering = rng.randomOrdering(sz), vOrd = rng.randomOrdering(openVowels.size()); +2492 OrderedMap<String, String> +2493 parts0 = new OrderedMap<>(openVowels), +2494 parts1 = new OrderedMap<>(openCons), +2495 parts2 = new OrderedMap<>(midCons), +2496 parts3 = new OrderedMap<>(closeCons); +2497 OrderedSet<String> forbidden = new OrderedSet<>(1024, 0.25f), missingSounds = new OrderedSet<>(64, 0.875f); +2498 parts1.reorder(reordering); +2499 parts2.reorder(reordering); +2500 parts3.reorder(reordering); +2501 parts0.reorder(vOrd); +2502 int n = 0; +2503 +2504 int mn = Math.min(rng.nextInt(3), rng.nextInt(3)), sz0, p0s; +2505 +2506 for (n = 0; n < mn; n++) { +2507 missingSounds.add(parts0.keyAt(0)); +2508 Collections.addAll(forbidden, parts0.getAt(0).split(" ")); +2509 parts0.removeFirst(); +2510 } +2511 p0s = parts0.size(); +2512 sz0 = Math.max(rng.between(1, p0s + 1), rng.between(1, p0s + 1)); +2513 char[] nextAccents = new char[sz0], unaccented = new char[sz0]; +2514 int vowelAccent = rng.between(1, 7); +2515 for (int i = 0; i < sz0; i++) { +2516 nextAccents[i] = accentedVowels[vOrd[i + mn]][vowelAccent]; +2517 unaccented[i] = accentedVowels[vOrd[i + mn]][0]; +2518 } +2519 if (rng.nextDouble() < 0.8) { +2520 for (int i = 0; i < sz0; i++) { +2521 char ac = nextAccents[i], ua = unaccented[i]; +2522 String v = "", uas = String.valueOf(ua); +2523 Pattern pat = Pattern.compile("\\b([aeiou]*)(" + ua + ")([aeiou]*)\\b"); +2524 Replacer rep = pat.replacer("$1$2$3 $1" + ac + "$3"), repLess = pat.replacer("$1" + ac + "$3"); +2525 for (int j = 0; j < p0s; j++) { +2526 String k = parts0.keyAt(j); +2527 if (uas.equals(k)) +2528 v = parts0.getAt(j); +2529 else { +2530 String current = parts0.getAt(j); +2531 String[] splits = current.split(" "); +2532 for (int s = 0; s < splits.length; s++) { +2533 if (forbidden.contains(uas) && splits[s].contains(uas)) +2534 forbidden.add(splits[s].replace(ua, ac)); +2535 } +2536 parts0.put(k, rep.replace(current)); +2537 } +2538 } +2539 parts0.put(String.valueOf(ac), repLess.replace(v)); +2540 } +2541 } +2542 +2543 n = 0; +2544 if (rng.nextDouble() < 0.75) { +2545 missingSounds.add("z"); +2546 Collections.addAll(forbidden, parts1.get("z").split(" ")); +2547 Collections.addAll(forbidden, parts2.get("z").split(" ")); +2548 Collections.addAll(forbidden, parts3.get("z").split(" ")); +2549 n++; +2550 } +2551 if (rng.nextDouble() < 0.82) { +2552 missingSounds.add("x"); +2553 Collections.addAll(forbidden, parts1.get("x").split(" ")); +2554 Collections.addAll(forbidden, parts2.get("x").split(" ")); +2555 Collections.addAll(forbidden, parts3.get("x").split(" ")); +2556 n++; +2557 } +2558 if (rng.nextDouble() < 0.92) { +2559 missingSounds.add("qu"); +2560 Collections.addAll(forbidden, parts1.get("qu").split(" ")); +2561 Collections.addAll(forbidden, parts2.get("qu").split(" ")); +2562 Collections.addAll(forbidden, parts3.get("qu").split(" ")); +2563 n++; +2564 } +2565 if (rng.nextDouble() < 0.96) { +2566 missingSounds.add("q"); +2567 Collections.addAll(forbidden, parts1.get("q").split(" ")); +2568 Collections.addAll(forbidden, parts2.get("q").split(" ")); +2569 Collections.addAll(forbidden, parts3.get("q").split(" ")); +2570 n++; +2571 } +2572 if (rng.nextDouble() < 0.97) { +2573 missingSounds.add("tl"); +2574 Collections.addAll(forbidden, parts1.get("tl").split(" ")); +2575 Collections.addAll(forbidden, parts2.get("tl").split(" ")); +2576 Collections.addAll(forbidden, parts3.get("tl").split(" ")); +2577 n++; +2578 } +2579 if (rng.nextDouble() < 0.86) { +2580 missingSounds.add("ph"); +2581 Collections.addAll(forbidden, parts1.get("ph").split(" ")); +2582 Collections.addAll(forbidden, parts2.get("ph").split(" ")); +2583 Collections.addAll(forbidden, parts3.get("ph").split(" ")); +2584 n++; +2585 } +2586 if (rng.nextDouble() < 0.94) { +2587 missingSounds.add("kh"); +2588 Collections.addAll(forbidden, parts1.get("kh").split(" ")); +2589 Collections.addAll(forbidden, parts2.get("kh").split(" ")); +2590 Collections.addAll(forbidden, parts3.get("kh").split(" ")); +2591 n++; +2592 } +2593 if (rng.nextDouble() < 0.96) { +2594 missingSounds.add("bh"); +2595 missingSounds.add("dh"); +2596 Collections.addAll(forbidden, parts1.get("bh").split(" ")); +2597 Collections.addAll(forbidden, parts2.get("bh").split(" ")); +2598 Collections.addAll(forbidden, parts3.get("bh").split(" ")); +2599 Collections.addAll(forbidden, parts1.get("dh").split(" ")); +2600 Collections.addAll(forbidden, parts2.get("dh").split(" ")); +2601 Collections.addAll(forbidden, parts3.get("dh").split(" ")); +2602 n++; +2603 n++; +2604 } +2605 +2606 for (; n < sz * removalRate; n++) { +2607 missingSounds.add(parts1.keyAt(n)); +2608 missingSounds.add(parts2.keyAt(n)); +2609 missingSounds.add(parts3.keyAt(n)); +2610 Collections.addAll(forbidden, parts1.getAt(n).split(" ")); +2611 Collections.addAll(forbidden, parts2.getAt(n).split(" ")); +2612 Collections.addAll(forbidden, parts3.getAt(n).split(" ")); +2613 } +2614 +2615 return new FakeLanguageGen( +2616 processParts(parts0, missingSounds, forbidden, rng, 0.0, p0s), +2617 new String[]{"y", "y"}, +2618 processParts(openCons, missingSounds, forbidden, rng, 0.0, 4096), +2619 processParts(midCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 2.25, 4096), +2620 processParts(closeCons, missingSounds, forbidden, rng, (rng.nextDouble() * 3 - 0.75) / 3.5, 4096), +2621 new String[]{}, +2622 new String[]{}, lengths, chances, vowelHeavy, vowelHeavy * 1.8, 0.0, 0.0, genericSanityChecks, true).summarize("0#" + seed + "@1"); +2623 } +2624 +2625 protected static boolean checkAll(CharSequence testing, Pattern[] checks) { +2626 CharSequence fixed = removeAccents(testing); +2627 for (int i = 0; i < checks.length; i++) { +2628 if (checks[i].matcher(fixed).find()) +2629 return false; +2630 } +2631 return true; +2632 } +2633 +2634 /** +2635 * Checks a CharSequence, such as a String, against an overzealous vulgarity filter, returning true if the text +2636 * could contain vulgar elements or words that could seem vulgar or juvenile. The idea here is that false positives +2637 * are OK as long as there are very few false negatives (missed vulgar words). Does not check punctuation or numbers +2638 * that could look like letters. +2639 * @param testing the text, as a CharSequence such as a String, to check +2640 * @return true if the text could contain a vulgar or juvenile element; false if it probably doesn't +2641 */ +2642 public static boolean checkVulgarity(CharSequence testing) +2643 { +2644 CharSequence fixed = removeAccents(testing); +2645 for (int i = 0; i < vulgarChecks.length; i++) { +2646 if (vulgarChecks[i].matcher(fixed).find()) +2647 { +2648 System.out.println(vulgarChecks[i]); +2649 return true; +2650 } +2651 } +2652 return false; +2653 } 2654 -2655 //sb.append(close.replaceAll("@\\d", sb.toString())); -2656 } -2657 if (!close.contains("@")) -2658 ender.append(close); -2659 else if (rng.nextDouble() < vowelEndFrequency) { -2660 ender.append(rng.getRandomElement(midVowels)); -2661 if (rng.nextDouble() < vowelSplitFrequency) { -2662 ender.append(rng.getRandomElement(vowelSplitters)); -2663 ender.append(rng.getRandomElement(midVowels)); -2664 } -2665 } -2666 } else { -2667 ender.append(rng.getRandomElement(midVowels)); -2668 if (rng.nextDouble() < vowelSplitFrequency) { -2669 ender.append(rng.getRandomElement(vowelSplitters)); -2670 ender.append(rng.getRandomElement(midVowels)); -2671 } -2672 if (rng.nextDouble() >= vowelEndFrequency) { -2673 ender.append(rng.getRandomElement(closingConsonants)); -2674 if (rng.nextDouble() < syllableEndFrequency) { -2675 close = rng.getRandomElement(closingSyllables); -2676 if (close.contains("@") && (syllables & 1) == 0) { -2677 redouble = true; -2678 syllables = (syllables | 1) >> 1; -2679 -2680 //sb.append(close.replaceAll("@\\d", sb.toString())); -2681 } -2682 if (!close.contains("@")) -2683 ender.append(close); -2684 } -2685 } -2686 } -2687 i += vowelClusters.matcher(ender).findAll().count(); -2688 -2689 } -2690 -2691 for (; i < syllables; i++) { -2692 sb.append(rng.getRandomElement(midVowels)); -2693 if (rng.nextDouble() < vowelSplitFrequency) { -2694 sb.append(rng.getRandomElement(vowelSplitters)); -2695 sb.append(rng.getRandomElement(midVowels)); -2696 } -2697 sb.append(rng.getRandomElement(midConsonants)); -2698 } -2699 -2700 sb.append(ender); -2701 if (redouble && i <= syllables + 1) { -2702 sb.append(close.replaceAll("@", sb.toString())); -2703 } -2704 -2705 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2706 continue; -2707 -2708 for (Modifier mod : modifiers) { -2709 sb = mod.modify(rng, sb); -2710 } -2711 -2712 if (capitalize) -2713 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2714 -2715 if (clean && !checkAll(sb, vulgarChecks)) -2716 continue; -2717 return sb.toString(); -2718 } -2719 } -2720 -2721 /** -2722 * Generate a word from this FakeLanguageGen using the specified RNG. -2723 * -2724 * @param rng the RNG to use for the randomized string building -2725 * @param capitalize true if the word should start with a capital letter, false otherwise -2726 * @return a word in the fake language as a String -2727 */ -2728 public String word(RNG rng, boolean capitalize, int approxSyllables) { -2729 return word(rng, capitalize, approxSyllables, null); -2730 } -2731 -2732 /** -2733 * Generate a word from this FakeLanguageGen using the specified RNG. -2734 * -2735 * @param rng the RNG to use for the randomized string building -2736 * @param capitalize true if the word should start with a capital letter, false otherwise -2737 * @return a word in the fake language as a String -2738 */ -2739 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { -2740 if (approxSyllables <= 0) { -2741 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2742 for (Modifier mod : modifiers) { -2743 sb = mod.modify(rng, sb); -2744 } -2745 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2746 return sb.toString(); -2747 } -2748 while (true) { -2749 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2750 int i = 0; -2751 if (rng.nextDouble() < vowelStartFrequency) { -2752 sb.append(rng.getRandomElement(openingVowels)); -2753 if (approxSyllables == 1 && closingConsonants.length > 0) -2754 sb.append(rng.getRandomElement(closingConsonants)); -2755 else if (midConsonants.length > 0) -2756 sb.append(rng.getRandomElement(midConsonants)); -2757 i++; -2758 } else if (openingConsonants.length > 0) { -2759 sb.append(rng.getRandomElement(openingConsonants)); -2760 } -2761 String close = ""; -2762 boolean redouble = false; -2763 if (i < approxSyllables) { -2764 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { -2765 close = rng.getRandomElement(closingSyllables); -2766 if (close.contains("@") && (approxSyllables & 1) == 0) { -2767 redouble = true; -2768 approxSyllables = approxSyllables >> 1; -2769 -2770 //sb.append(close.replaceAll("@\\d", sb.toString())); -2771 } -2772 if (!close.contains("@")) -2773 ender.append(close); -2774 else if (redouble && rng.nextDouble() < vowelEndFrequency) { -2775 ender.append(rng.getRandomElement(midVowels)); -2776 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { -2777 ender.append(rng.getRandomElement(vowelSplitters)); -2778 ender.append(rng.getRandomElement(midVowels)); -2779 } -2780 } -2781 } else { -2782 ender.append(rng.getRandomElement(midVowels)); -2783 if (rng.nextDouble() < vowelSplitFrequency) { -2784 ender.append(rng.getRandomElement(vowelSplitters)); -2785 ender.append(rng.getRandomElement(midVowels)); -2786 } -2787 if (rng.nextDouble() >= vowelEndFrequency) { -2788 ender.append(rng.getRandomElement(closingConsonants)); -2789 if (rng.nextDouble() < syllableEndFrequency) { -2790 close = rng.getRandomElement(closingSyllables); -2791 if (close.contains("@") && (approxSyllables & 1) == 0) { -2792 redouble = true; -2793 approxSyllables = approxSyllables >> 1; -2794 -2795 //sb.append(close.replaceAll("@\\d", sb.toString())); -2796 } -2797 if (!close.contains("@")) -2798 ender.append(close); -2799 } -2800 } -2801 } -2802 i += vowelClusters.matcher(ender).findAll().count(); -2803 } -2804 -2805 for (; i < approxSyllables; i++) { -2806 sb.append(rng.getRandomElement(midVowels)); -2807 if (rng.nextDouble() < vowelSplitFrequency) { -2808 sb.append(rng.getRandomElement(vowelSplitters)); -2809 sb.append(rng.getRandomElement(midVowels)); -2810 } -2811 sb.append(rng.getRandomElement(midConsonants)); -2812 } -2813 -2814 sb.append(ender); -2815 if (redouble && i <= approxSyllables + 1) { -2816 sb.append(close.replaceAll("@", sb.toString())); -2817 } -2818 -2819 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2820 continue; -2821 -2822 for (Modifier mod : modifiers) { -2823 sb = mod.modify(rng, sb); -2824 } -2825 -2826 if (clean && !checkAll(sb, vulgarChecks)) -2827 continue; -2828 -2829 if (additionalChecks != null && !checkAll(sb, additionalChecks)) -2830 continue; -2831 -2832 if (capitalize) -2833 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2834 -2835 return sb.toString(); -2836 } -2837 } -2838 -2839 /** -2840 * Generate a word from this FakeLanguageGen using the specified RNG. -2841 * -2842 * @param rng the RNG to use for the randomized string building -2843 * @param capitalize true if the word should start with a capital letter, false otherwise -2844 * @return a word in the fake language as a String -2845 */ -2846 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { -2847 if (approxSyllables <= 0) { -2848 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); -2849 for (Modifier mod : modifiers) { -2850 sb = mod.modify(rng, sb); +2655 /** +2656 * Generate a word from this FakeLanguageGen, using and changing the current seed. +2657 * +2658 * @param capitalize true if the word should start with a capital letter, false otherwise +2659 * @return a word in the fake language as a String +2660 */ +2661 public String word(boolean capitalize) { +2662 return word(srng, capitalize); +2663 } +2664 +2665 /** +2666 * Generate a word from this FakeLanguageGen using the specified RNG. +2667 * +2668 * @param rng the RNG to use for the randomized string building +2669 * @param capitalize true if the word should start with a capital letter, false otherwise +2670 * @return a word in the fake language as a String +2671 */ +2672 public String word(RNG rng, boolean capitalize) { +2673 while (true) { +2674 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2675 double syllableChance = rng.nextDouble(totalSyllableFrequency); +2676 int syllables = 1, i = 0; +2677 for (IntDoubleOrderedMap.MapEntry kv : syllableFrequencies.mapEntrySet()) { +2678 if (syllableChance < kv.getDoubleValue()) { +2679 syllables = kv.getIntKey(); +2680 break; +2681 } else +2682 syllableChance -= kv.getDoubleValue(); +2683 } +2684 if (rng.nextDouble() < vowelStartFrequency) { +2685 sb.append(rng.getRandomElement(openingVowels)); +2686 if (syllables == 1) +2687 sb.append(rng.getRandomElement(closingConsonants)); +2688 else +2689 sb.append(rng.getRandomElement(midConsonants)); +2690 i++; +2691 } else { +2692 sb.append(rng.getRandomElement(openingConsonants)); +2693 } +2694 String close = ""; +2695 boolean redouble = false; +2696 if (i < syllables) { +2697 if (rng.nextDouble() < syllableEndFrequency) { +2698 close = rng.getRandomElement(closingSyllables); +2699 if (close.contains("@") && (syllables & 1) == 0) { +2700 redouble = true; +2701 syllables = (syllables | 1) >> 1; +2702 +2703 //sb.append(close.replaceAll("@\\d", sb.toString())); +2704 } +2705 if (!close.contains("@")) +2706 ender.append(close); +2707 else if (rng.nextDouble() < vowelEndFrequency) { +2708 ender.append(rng.getRandomElement(midVowels)); +2709 if (rng.nextDouble() < vowelSplitFrequency) { +2710 ender.append(rng.getRandomElement(vowelSplitters)); +2711 ender.append(rng.getRandomElement(midVowels)); +2712 } +2713 } +2714 } else { +2715 ender.append(rng.getRandomElement(midVowels)); +2716 if (rng.nextDouble() < vowelSplitFrequency) { +2717 ender.append(rng.getRandomElement(vowelSplitters)); +2718 ender.append(rng.getRandomElement(midVowels)); +2719 } +2720 if (rng.nextDouble() >= vowelEndFrequency) { +2721 ender.append(rng.getRandomElement(closingConsonants)); +2722 if (rng.nextDouble() < syllableEndFrequency) { +2723 close = rng.getRandomElement(closingSyllables); +2724 if (close.contains("@") && (syllables & 1) == 0) { +2725 redouble = true; +2726 syllables = (syllables | 1) >> 1; +2727 +2728 //sb.append(close.replaceAll("@\\d", sb.toString())); +2729 } +2730 if (!close.contains("@")) +2731 ender.append(close); +2732 } +2733 } +2734 } +2735 i += vowelClusters.matcher(ender).findAll().count(); +2736 +2737 } +2738 +2739 for (; i < syllables; i++) { +2740 sb.append(rng.getRandomElement(midVowels)); +2741 if (rng.nextDouble() < vowelSplitFrequency) { +2742 sb.append(rng.getRandomElement(vowelSplitters)); +2743 sb.append(rng.getRandomElement(midVowels)); +2744 } +2745 sb.append(rng.getRandomElement(midConsonants)); +2746 } +2747 +2748 sb.append(ender); +2749 if (redouble && i <= syllables + 1) { +2750 sb.append(close.replaceAll("@", sb.toString())); +2751 } +2752 +2753 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2754 continue; +2755 +2756 for (Modifier mod : modifiers) { +2757 sb = mod.modify(rng, sb); +2758 } +2759 +2760 if (capitalize) +2761 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2762 +2763 if (clean && !checkAll(sb, vulgarChecks)) +2764 continue; +2765 return sb.toString(); +2766 } +2767 } +2768 +2769 /** +2770 * Generate a word from this FakeLanguageGen using the specified RNG. +2771 * +2772 * @param rng the RNG to use for the randomized string building +2773 * @param capitalize true if the word should start with a capital letter, false otherwise +2774 * @return a word in the fake language as a String +2775 */ +2776 public String word(RNG rng, boolean capitalize, int approxSyllables) { +2777 return word(rng, capitalize, approxSyllables, null); +2778 } +2779 +2780 /** +2781 * Generate a word from this FakeLanguageGen using the specified RNG. +2782 * +2783 * @param rng the RNG to use for the randomized string building +2784 * @param capitalize true if the word should start with a capital letter, false otherwise +2785 * @return a word in the fake language as a String +2786 */ +2787 public String word(RNG rng, boolean capitalize, int approxSyllables, Pattern[] additionalChecks) { +2788 if (approxSyllables <= 0) { +2789 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2790 for (Modifier mod : modifiers) { +2791 sb = mod.modify(rng, sb); +2792 } +2793 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2794 return sb.toString(); +2795 } +2796 while (true) { +2797 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2798 int i = 0; +2799 if (rng.nextDouble() < vowelStartFrequency) { +2800 sb.append(rng.getRandomElement(openingVowels)); +2801 if (approxSyllables == 1 && closingConsonants.length > 0) +2802 sb.append(rng.getRandomElement(closingConsonants)); +2803 else if (midConsonants.length > 0) +2804 sb.append(rng.getRandomElement(midConsonants)); +2805 i++; +2806 } else if (openingConsonants.length > 0) { +2807 sb.append(rng.getRandomElement(openingConsonants)); +2808 } +2809 String close = ""; +2810 boolean redouble = false; +2811 if (i < approxSyllables) { +2812 if (closingSyllables.length > 0 && rng.nextDouble() < syllableEndFrequency) { +2813 close = rng.getRandomElement(closingSyllables); +2814 if (close.contains("@") && (approxSyllables & 1) == 0) { +2815 redouble = true; +2816 approxSyllables = approxSyllables >> 1; +2817 +2818 //sb.append(close.replaceAll("@\\d", sb.toString())); +2819 } +2820 if (!close.contains("@")) +2821 ender.append(close); +2822 else if (redouble && rng.nextDouble() < vowelEndFrequency) { +2823 ender.append(rng.getRandomElement(midVowels)); +2824 if (vowelSplitters.length > 0 && rng.nextDouble() < vowelSplitFrequency) { +2825 ender.append(rng.getRandomElement(vowelSplitters)); +2826 ender.append(rng.getRandomElement(midVowels)); +2827 } +2828 } +2829 } else { +2830 ender.append(rng.getRandomElement(midVowels)); +2831 if (rng.nextDouble() < vowelSplitFrequency) { +2832 ender.append(rng.getRandomElement(vowelSplitters)); +2833 ender.append(rng.getRandomElement(midVowels)); +2834 } +2835 if (rng.nextDouble() >= vowelEndFrequency) { +2836 ender.append(rng.getRandomElement(closingConsonants)); +2837 if (rng.nextDouble() < syllableEndFrequency) { +2838 close = rng.getRandomElement(closingSyllables); +2839 if (close.contains("@") && (approxSyllables & 1) == 0) { +2840 redouble = true; +2841 approxSyllables = approxSyllables >> 1; +2842 +2843 //sb.append(close.replaceAll("@\\d", sb.toString())); +2844 } +2845 if (!close.contains("@")) +2846 ender.append(close); +2847 } +2848 } +2849 } +2850 i += vowelClusters.matcher(ender).findAll().count(); 2851 } -2852 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2853 return sb.toString(); -2854 } -2855 int numSeeds, fraction = 1; -2856 if (reseeds != null) -2857 numSeeds = Math.min(reseeds.length, approxSyllables - 1); -2858 else numSeeds = 0; -2859 while (true) { -2860 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); -2861 int i = 0; -2862 if (rng.nextDouble() < vowelStartFrequency) { -2863 sb.append(rng.getRandomElement(openingVowels)); -2864 if (approxSyllables == 1) -2865 sb.append(rng.getRandomElement(closingConsonants)); -2866 else -2867 sb.append(rng.getRandomElement(midConsonants)); -2868 i++; -2869 } else { -2870 sb.append(rng.getRandomElement(openingConsonants)); -2871 } -2872 String close = ""; -2873 boolean redouble = false; -2874 if (i < approxSyllables) { -2875 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2876 rng.setState(reseeds[fraction++ - 1]); -2877 if (rng.nextDouble() < syllableEndFrequency) { -2878 close = rng.getRandomElement(closingSyllables); -2879 if (close.contains("@") && (approxSyllables & 1) == 0) { -2880 redouble = true; -2881 approxSyllables = approxSyllables >> 1; -2882 } -2883 if (!close.contains("@")) -2884 ender.append(close); -2885 else if (rng.nextDouble() < vowelEndFrequency) { -2886 ender.append(rng.getRandomElement(midVowels)); -2887 if (rng.nextDouble() < vowelSplitFrequency) { -2888 ender.append(rng.getRandomElement(vowelSplitters)); -2889 ender.append(rng.getRandomElement(midVowels)); -2890 } -2891 } -2892 } else { -2893 ender.append(rng.getRandomElement(midVowels)); -2894 if (rng.nextDouble() < vowelSplitFrequency) { -2895 ender.append(rng.getRandomElement(vowelSplitters)); -2896 ender.append(rng.getRandomElement(midVowels)); -2897 } -2898 if (rng.nextDouble() >= vowelEndFrequency) { -2899 ender.append(rng.getRandomElement(closingConsonants)); -2900 if (rng.nextDouble() < syllableEndFrequency) { -2901 close = rng.getRandomElement(closingSyllables); -2902 if (close.contains("@") && (approxSyllables & 1) == 0) { -2903 redouble = true; -2904 approxSyllables = approxSyllables >> 1; -2905 -2906 //sb.append(close.replaceAll("@\\d", sb.toString())); -2907 } -2908 if (!close.contains("@")) -2909 ender.append(close); -2910 } -2911 } -2912 } -2913 i += vowelClusters.matcher(ender).findAll().count(); -2914 } -2915 -2916 for (; i < approxSyllables; i++) { -2917 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) -2918 rng.setState(reseeds[fraction++ - 1]); -2919 sb.append(rng.getRandomElement(midVowels)); -2920 if (rng.nextDouble() < vowelSplitFrequency) { -2921 sb.append(rng.getRandomElement(vowelSplitters)); -2922 sb.append(rng.getRandomElement(midVowels)); -2923 } -2924 sb.append(rng.getRandomElement(midConsonants)); -2925 } -2926 -2927 sb.append(ender); -2928 if (redouble && i <= approxSyllables + 1) { -2929 sb.append(close.replaceAll("@", sb.toString())); -2930 } -2931 -2932 if (sanityChecks != null && !checkAll(sb, sanityChecks)) -2933 continue; -2934 -2935 for (Modifier mod : modifiers) { -2936 sb = mod.modify(rng, sb); -2937 } -2938 -2939 if (capitalize) -2940 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); -2941 -2942 if (clean && !checkAll(sb, vulgarChecks)) -2943 continue; -2944 return sb.toString(); -2945 } -2946 } -2947 -2948 /** -2949 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2950 * -2951 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2952 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2953 * @return a sentence in the gibberish language as a String -2954 */ -2955 public String sentence(int minWords, int maxWords) { -2956 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2957 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2958 } -2959 -2960 /** -2961 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2962 * -2963 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2964 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2965 * @return a sentence in the gibberish language as a String -2966 */ -2967 public String sentence(RNG rng, int minWords, int maxWords) { -2968 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, -2969 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); -2970 } -2971 -2972 /** -2973 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. -2974 * -2975 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2976 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2977 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2978 * space in the middle of a sentence -2979 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2980 * the very end of a sentence -2981 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -2982 * midPunctuation should be inserted before spaces -2983 * @return a sentence in the gibberish language as a String -2984 */ -2985 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -2986 double midPunctuationFrequency) { -2987 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -2988 } +2852 +2853 for (; i < approxSyllables; i++) { +2854 sb.append(rng.getRandomElement(midVowels)); +2855 if (rng.nextDouble() < vowelSplitFrequency) { +2856 sb.append(rng.getRandomElement(vowelSplitters)); +2857 sb.append(rng.getRandomElement(midVowels)); +2858 } +2859 sb.append(rng.getRandomElement(midConsonants)); +2860 } +2861 +2862 sb.append(ender); +2863 if (redouble && i <= approxSyllables + 1) { +2864 sb.append(close.replaceAll("@", sb.toString())); +2865 } +2866 +2867 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2868 continue; +2869 +2870 for (Modifier mod : modifiers) { +2871 sb = mod.modify(rng, sb); +2872 } +2873 +2874 if (clean && !checkAll(sb, vulgarChecks)) +2875 continue; +2876 +2877 if (additionalChecks != null && !checkAll(sb, additionalChecks)) +2878 continue; +2879 +2880 if (capitalize) +2881 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2882 +2883 return sb.toString(); +2884 } +2885 } +2886 +2887 /** +2888 * Generate a word from this FakeLanguageGen using the specified RNG. +2889 * +2890 * @param rng the RNG to use for the randomized string building +2891 * @param capitalize true if the word should start with a capital letter, false otherwise +2892 * @return a word in the fake language as a String +2893 */ +2894 public String word(StatefulRNG rng, boolean capitalize, int approxSyllables, long... reseeds) { +2895 if (approxSyllables <= 0) { +2896 StringBuilder sb = new StringBuilder(rng.getRandomElement(openingVowels)); +2897 for (Modifier mod : modifiers) { +2898 sb = mod.modify(rng, sb); +2899 } +2900 if (capitalize) sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); +2901 return sb.toString(); +2902 } +2903 int numSeeds, fraction = 1; +2904 if (reseeds != null) +2905 numSeeds = Math.min(reseeds.length, approxSyllables - 1); +2906 else numSeeds = 0; +2907 while (true) { +2908 StringBuilder sb = new StringBuilder(20), ender = new StringBuilder(12); +2909 int i = 0; +2910 if (rng.nextDouble() < vowelStartFrequency) { +2911 sb.append(rng.getRandomElement(openingVowels)); +2912 if (approxSyllables == 1) +2913 sb.append(rng.getRandomElement(closingConsonants)); +2914 else +2915 sb.append(rng.getRandomElement(midConsonants)); +2916 i++; +2917 } else { +2918 sb.append(rng.getRandomElement(openingConsonants)); +2919 } +2920 String close = ""; +2921 boolean redouble = false; +2922 if (i < approxSyllables) { +2923 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2924 rng.setState(reseeds[fraction++ - 1]); +2925 if (rng.nextDouble() < syllableEndFrequency) { +2926 close = rng.getRandomElement(closingSyllables); +2927 if (close.contains("@") && (approxSyllables & 1) == 0) { +2928 redouble = true; +2929 approxSyllables = approxSyllables >> 1; +2930 } +2931 if (!close.contains("@")) +2932 ender.append(close); +2933 else if (rng.nextDouble() < vowelEndFrequency) { +2934 ender.append(rng.getRandomElement(midVowels)); +2935 if (rng.nextDouble() < vowelSplitFrequency) { +2936 ender.append(rng.getRandomElement(vowelSplitters)); +2937 ender.append(rng.getRandomElement(midVowels)); +2938 } +2939 } +2940 } else { +2941 ender.append(rng.getRandomElement(midVowels)); +2942 if (rng.nextDouble() < vowelSplitFrequency) { +2943 ender.append(rng.getRandomElement(vowelSplitters)); +2944 ender.append(rng.getRandomElement(midVowels)); +2945 } +2946 if (rng.nextDouble() >= vowelEndFrequency) { +2947 ender.append(rng.getRandomElement(closingConsonants)); +2948 if (rng.nextDouble() < syllableEndFrequency) { +2949 close = rng.getRandomElement(closingSyllables); +2950 if (close.contains("@") && (approxSyllables & 1) == 0) { +2951 redouble = true; +2952 approxSyllables = approxSyllables >> 1; +2953 +2954 //sb.append(close.replaceAll("@\\d", sb.toString())); +2955 } +2956 if (!close.contains("@")) +2957 ender.append(close); +2958 } +2959 } +2960 } +2961 i += vowelClusters.matcher(ender).findAll().count(); +2962 } +2963 +2964 for (; i < approxSyllables; i++) { +2965 if (numSeeds > 0 && i > 0 && i == approxSyllables * fraction / (1 + numSeeds)) +2966 rng.setState(reseeds[fraction++ - 1]); +2967 sb.append(rng.getRandomElement(midVowels)); +2968 if (rng.nextDouble() < vowelSplitFrequency) { +2969 sb.append(rng.getRandomElement(vowelSplitters)); +2970 sb.append(rng.getRandomElement(midVowels)); +2971 } +2972 sb.append(rng.getRandomElement(midConsonants)); +2973 } +2974 +2975 sb.append(ender); +2976 if (redouble && i <= approxSyllables + 1) { +2977 sb.append(close.replaceAll("@", sb.toString())); +2978 } +2979 +2980 if (sanityChecks != null && !checkAll(sb, sanityChecks)) +2981 continue; +2982 +2983 for (Modifier mod : modifiers) { +2984 sb = mod.modify(rng, sb); +2985 } +2986 +2987 if (capitalize) +2988 sb.setCharAt(0, Character.toUpperCase(sb.charAt(0))); 2989 -2990 /** -2991 * Generate a sentence from this FakeLanguageGen using the specific RNG. -2992 * -2993 * @param rng the RNG to use for the randomized string building -2994 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -2995 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -2996 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -2997 * space in the middle of a sentence -2998 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -2999 * the very end of a sentence -3000 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3001 * midPunctuation should be inserted before spaces -3002 * @return a sentence in the gibberish language as a String -3003 */ -3004 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3005 double midPunctuationFrequency) { -3006 if (minWords < 1) -3007 minWords = 1; -3008 if (minWords > maxWords) -3009 maxWords = minWords; -3010 if (midPunctuationFrequency > 1.0) { -3011 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3012 } -3013 StringBuilder sb = new StringBuilder(12 * maxWords); -3014 sb.append(word(rng, true)); -3015 for (int i = 1; i < minWords; i++) { -3016 if (rng.nextDouble() < midPunctuationFrequency) { -3017 sb.append(rng.getRandomElement(midPunctuation)); -3018 } -3019 sb.append(' '); -3020 sb.append(word(rng, false)); -3021 } -3022 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { -3023 if (rng.nextDouble() < midPunctuationFrequency) { -3024 sb.append(rng.getRandomElement(midPunctuation)); -3025 } -3026 sb.append(' '); -3027 sb.append(word(rng, false)); -3028 } -3029 if (endPunctuation != null && endPunctuation.length > 0) -3030 sb.append(rng.getRandomElement(endPunctuation)); -3031 return sb.toString(); -3032 } -3033 -3034 /** -3035 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. -3036 * -3037 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3038 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3039 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3040 * space in the middle of a sentence -3041 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3042 * the very end of a sentence -3043 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3044 * midPunctuation should be inserted before spaces -3045 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3046 * @return a sentence in the gibberish language as a String -3047 */ -3048 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3049 double midPunctuationFrequency, int maxChars) { -3050 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); -3051 } -3052 -3053 /** -3054 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. -3055 * -3056 * @param rng the RNG to use for the randomized string building -3057 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 -3058 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords -3059 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a -3060 * space in the middle of a sentence -3061 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at -3062 * the very end of a sentence -3063 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from -3064 * midPunctuation should be inserted before spaces -3065 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} -3066 * @return a sentence in the gibberish language as a String -3067 */ -3068 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, -3069 double midPunctuationFrequency, int maxChars) { -3070 if(maxChars < 0) -3071 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); -3072 if (minWords < 1) -3073 minWords = 1; -3074 if (minWords > maxWords) -3075 maxWords = minWords; -3076 if (midPunctuationFrequency > 1.0) { -3077 midPunctuationFrequency = 1.0 / midPunctuationFrequency; -3078 } -3079 if (maxChars < 4) -3080 return "!"; -3081 if (maxChars <= 5 * minWords) { -3082 minWords = 1; -3083 maxWords = 1; -3084 } -3085 int frustration = 0; -3086 StringBuilder sb = new StringBuilder(maxChars); -3087 String next = word(rng, true); -3088 while (next.length() >= maxChars - 1 && frustration < 50) { -3089 next = word(rng, true); -3090 frustration++; -3091 } -3092 if (frustration >= 50) return "!"; -3093 sb.append(next); -3094 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { -3095 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3096 sb.append(rng.getRandomElement(midPunctuation)); -3097 } -3098 next = word(rng, false); -3099 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3100 next = word(rng, false); -3101 frustration++; -3102 } -3103 if (frustration >= 50) break; -3104 sb.append(' '); -3105 sb.append(next); -3106 } -3107 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { -3108 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { -3109 sb.append(rng.getRandomElement(midPunctuation)); -3110 } -3111 next = word(rng, false); -3112 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { -3113 next = word(rng, false); -3114 frustration++; -3115 } -3116 if (frustration >= 50) break; -3117 sb.append(' '); -3118 sb.append(next); -3119 } -3120 -3121 if (endPunctuation != null && endPunctuation.length > 0) { -3122 -3123 next = rng.getRandomElement(endPunctuation); -3124 if (sb.length() + next.length() >= maxChars) -3125 sb.append('.'); -3126 else -3127 sb.append(next); -3128 } -3129 -3130 if (sb.length() > maxChars) -3131 return "!"; -3132 return sb.toString(); -3133 } -3134 -3135 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { -3136 if (other.length <= 0 && me.length <= 0) -3137 return new String[]{}; -3138 String[] ret = new String[1000]; -3139 int otherCount = (int) (1000 * otherInfluence); -3140 int idx = 0; -3141 if (other.length > 0) { -3142 String[] tmp = new String[other.length]; -3143 rng.shuffle(other, tmp); -3144 for (idx = 0; idx < otherCount; idx++) { -3145 ret[idx] = tmp[idx % tmp.length]; -3146 } -3147 } -3148 if (me.length > 0) { -3149 String[] tmp = new String[me.length]; -3150 rng.shuffle(me, tmp); -3151 for (; idx < 1000; idx++) { -3152 ret[idx] = tmp[idx % tmp.length]; -3153 } -3154 } else { -3155 for (; idx < 1000; idx++) { -3156 ret[idx] = other[idx % other.length]; -3157 } -3158 } -3159 return ret; -3160 } -3161 -3162 -3163 protected String[] accentVowels(RNG rng, String[] me, double influence) { -3164 String[] ret = new String[1000]; -3165 int otherCount = (int) (1000 * influence); -3166 int idx = 0; -3167 Matcher matcher; -3168 if (me.length > 0) { -3169 String[] tmp = new String[me.length]; -3170 rng.shuffle(me, tmp); -3171 for (idx = 0; idx < otherCount; idx++) { -3172 ret[idx] = tmp[idx % tmp.length] -3173 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3174 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3175 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3176 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3177 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3178 matcher = repeats.matcher(ret[idx]); -3179 if (matcher.find()) { -3180 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3181 } -3182 } -3183 for (; idx < 1000; idx++) { -3184 ret[idx] = tmp[idx % tmp.length]; -3185 } -3186 } else -3187 return new String[]{}; -3188 return ret; -3189 } -3190 -3191 protected String[] accentConsonants(RNG rng, String[] me, double influence) { -3192 String[] ret = new String[1000]; -3193 int otherCount = (int) (1000 * influence); -3194 int idx = 0; -3195 Matcher matcher; +2990 if (clean && !checkAll(sb, vulgarChecks)) +2991 continue; +2992 return sb.toString(); +2993 } +2994 } +2995 +2996 /** +2997 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +2998 * +2999 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3000 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3001 * @return a sentence in the gibberish language as a String +3002 */ +3003 public String sentence(int minWords, int maxWords) { +3004 return sentence(srng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3005 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3006 } +3007 +3008 /** +3009 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3010 * +3011 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3012 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3013 * @return a sentence in the gibberish language as a String +3014 */ +3015 public String sentence(RNG rng, int minWords, int maxWords) { +3016 return sentence(rng, minWords, maxWords, new String[]{",", ",", ",", ";"}, +3017 new String[]{".", ".", ".", "!", "?", "..."}, 0.2); +3018 } +3019 +3020 /** +3021 * Generate a sentence from this FakeLanguageGen, using and changing the current seed. +3022 * +3023 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3024 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3025 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3026 * space in the middle of a sentence +3027 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3028 * the very end of a sentence +3029 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3030 * midPunctuation should be inserted before spaces +3031 * @return a sentence in the gibberish language as a String +3032 */ +3033 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3034 double midPunctuationFrequency) { +3035 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3036 } +3037 +3038 /** +3039 * Generate a sentence from this FakeLanguageGen using the specific RNG. +3040 * +3041 * @param rng the RNG to use for the randomized string building +3042 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3043 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3044 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3045 * space in the middle of a sentence +3046 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3047 * the very end of a sentence +3048 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3049 * midPunctuation should be inserted before spaces +3050 * @return a sentence in the gibberish language as a String +3051 */ +3052 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3053 double midPunctuationFrequency) { +3054 if (minWords < 1) +3055 minWords = 1; +3056 if (minWords > maxWords) +3057 maxWords = minWords; +3058 if (midPunctuationFrequency > 1.0) { +3059 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3060 } +3061 StringBuilder sb = new StringBuilder(12 * maxWords); +3062 sb.append(word(rng, true)); +3063 for (int i = 1; i < minWords; i++) { +3064 if (rng.nextDouble() < midPunctuationFrequency) { +3065 sb.append(rng.getRandomElement(midPunctuation)); +3066 } +3067 sb.append(' '); +3068 sb.append(word(rng, false)); +3069 } +3070 for (int i = minWords; i < maxWords && rng.nextInt(2 * maxWords) > i; i++) { +3071 if (rng.nextDouble() < midPunctuationFrequency) { +3072 sb.append(rng.getRandomElement(midPunctuation)); +3073 } +3074 sb.append(' '); +3075 sb.append(word(rng, false)); +3076 } +3077 if (endPunctuation != null && endPunctuation.length > 0) +3078 sb.append(rng.getRandomElement(endPunctuation)); +3079 return sb.toString(); +3080 } +3081 +3082 /** +3083 * Generate a sentence from this FakeLanguageGen that fits in the given length limit.. +3084 * +3085 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3086 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3087 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3088 * space in the middle of a sentence +3089 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3090 * the very end of a sentence +3091 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3092 * midPunctuation should be inserted before spaces +3093 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3094 * @return a sentence in the gibberish language as a String +3095 */ +3096 public String sentence(int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3097 double midPunctuationFrequency, int maxChars) { +3098 return sentence(srng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency, maxChars); +3099 } +3100 +3101 /** +3102 * Generate a sentence from this FakeLanguageGen using the specific RNG that fits in the given length limit. +3103 * +3104 * @param rng the RNG to use for the randomized string building +3105 * @param minWords an int for the minimum number of words in a sentence; should be at least 1 +3106 * @param maxWords an int for the maximum number of words in a sentence; should be at least equal to minWords +3107 * @param midPunctuation a String array where each element is a comma, semicolon, or the like that goes before a +3108 * space in the middle of a sentence +3109 * @param endPunctuation a String array where each element is a period, question mark, or the like that goes at +3110 * the very end of a sentence +3111 * @param midPunctuationFrequency a double between 0.0 and 1.0 that determines how often Strings from +3112 * midPunctuation should be inserted before spaces +3113 * @param maxChars the longest string length this can produce; should be at least {@code 6 * minWords} +3114 * @return a sentence in the gibberish language as a String +3115 */ +3116 public String sentence(RNG rng, int minWords, int maxWords, String[] midPunctuation, String[] endPunctuation, +3117 double midPunctuationFrequency, int maxChars) { +3118 if(maxChars < 0) +3119 return sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, midPunctuationFrequency); +3120 if (minWords < 1) +3121 minWords = 1; +3122 if (minWords > maxWords) +3123 maxWords = minWords; +3124 if (midPunctuationFrequency > 1.0) { +3125 midPunctuationFrequency = 1.0 / midPunctuationFrequency; +3126 } +3127 if (maxChars < 4) +3128 return "!"; +3129 if (maxChars <= 5 * minWords) { +3130 minWords = 1; +3131 maxWords = 1; +3132 } +3133 int frustration = 0; +3134 StringBuilder sb = new StringBuilder(maxChars); +3135 String next = word(rng, true); +3136 while (next.length() >= maxChars - 1 && frustration < 50) { +3137 next = word(rng, true); +3138 frustration++; +3139 } +3140 if (frustration >= 50) return "!"; +3141 sb.append(next); +3142 for (int i = 1; i < minWords && frustration < 50 && sb.length() < maxChars - 7; i++) { +3143 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3144 sb.append(rng.getRandomElement(midPunctuation)); +3145 } +3146 next = word(rng, false); +3147 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3148 next = word(rng, false); +3149 frustration++; +3150 } +3151 if (frustration >= 50) break; +3152 sb.append(' '); +3153 sb.append(next); +3154 } +3155 for (int i = minWords; i < maxWords && sb.length() < maxChars - 7 && rng.nextInt(2 * maxWords) > i && frustration < 50; i++) { +3156 if (rng.nextDouble() < midPunctuationFrequency && sb.length() < maxChars - 3) { +3157 sb.append(rng.getRandomElement(midPunctuation)); +3158 } +3159 next = word(rng, false); +3160 while (sb.length() + next.length() >= maxChars - 2 && frustration < 50) { +3161 next = word(rng, false); +3162 frustration++; +3163 } +3164 if (frustration >= 50) break; +3165 sb.append(' '); +3166 sb.append(next); +3167 } +3168 +3169 if (endPunctuation != null && endPunctuation.length > 0) { +3170 +3171 next = rng.getRandomElement(endPunctuation); +3172 if (sb.length() + next.length() >= maxChars) +3173 sb.append('.'); +3174 else +3175 sb.append(next); +3176 } +3177 +3178 if (sb.length() > maxChars) +3179 return "!"; +3180 return sb.toString(); +3181 } +3182 +3183 protected String[] merge1000(RNG rng, String[] me, String[] other, double otherInfluence) { +3184 if (other.length <= 0 && me.length <= 0) +3185 return new String[]{}; +3186 String[] ret = new String[1000]; +3187 int otherCount = (int) (1000 * otherInfluence); +3188 int idx = 0; +3189 if (other.length > 0) { +3190 String[] tmp = new String[other.length]; +3191 rng.shuffle(other, tmp); +3192 for (idx = 0; idx < otherCount; idx++) { +3193 ret[idx] = tmp[idx % tmp.length]; +3194 } +3195 } 3196 if (me.length > 0) { 3197 String[] tmp = new String[me.length]; 3198 rng.shuffle(me, tmp); -3199 for (idx = 0; idx < otherCount; idx++) { -3200 ret[idx] = tmp[idx % tmp.length] -3201 //0 -3202 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3203 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3204 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3205 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3206 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3207 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3208 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3209 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3210 //9 -3211 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3212 //11 -3213 //12 -3214 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3215 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3216 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3217 //16 -3218 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3219 //18 -3220 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3221 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3222 -3223 matcher = repeats.matcher(ret[idx]); -3224 if (matcher.find()) { -3225 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3226 } -3227 } -3228 for (; idx < 1000; idx++) { -3229 ret[idx] = tmp[idx % tmp.length]; +3199 for (; idx < 1000; idx++) { +3200 ret[idx] = tmp[idx % tmp.length]; +3201 } +3202 } else { +3203 for (; idx < 1000; idx++) { +3204 ret[idx] = other[idx % other.length]; +3205 } +3206 } +3207 return ret; +3208 } +3209 +3210 +3211 protected String[] accentVowels(RNG rng, String[] me, double influence) { +3212 String[] ret = new String[1000]; +3213 int otherCount = (int) (1000 * influence); +3214 int idx = 0; +3215 Matcher matcher; +3216 if (me.length > 0) { +3217 String[] tmp = new String[me.length]; +3218 rng.shuffle(me, tmp); +3219 for (idx = 0; idx < otherCount; idx++) { +3220 ret[idx] = tmp[idx % tmp.length] +3221 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3222 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3223 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3224 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3225 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3226 matcher = repeats.matcher(ret[idx]); +3227 if (matcher.find()) { +3228 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3229 } 3230 } -3231 } else -3232 return new String[]{}; -3233 return ret; -3234 } -3235 -3236 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { -3237 String[] ret = new String[1000]; -3238 int idx = 0; -3239 Matcher matcher; -3240 if (me.length > 0) { -3241 String[] tmp = new String[me.length]; -3242 rng.shuffle(me, tmp); -3243 for (idx = 0; idx < 1000; idx++) { -3244 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; -3245 if (subVowel && subCon) { -3246 ret[idx] = tmp[idx % tmp.length] -3247 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3248 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3249 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3250 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3251 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) -3252 -3253 //0 -3254 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3255 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3256 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3257 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3258 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3259 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3260 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3261 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3262 //9 -3263 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3264 //11 -3265 //12 -3266 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3267 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3268 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3269 //16 -3270 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3271 //18 -3272 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3273 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3274 -3275 matcher = repeats.matcher(ret[idx]); -3276 if (matcher.find()) { -3277 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3278 } -3279 } else if (subVowel) { -3280 ret[idx] = tmp[idx % tmp.length] -3281 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) -3282 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) -3283 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) -3284 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) -3285 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); -3286 -3287 matcher = repeats.matcher(ret[idx]); -3288 if (matcher.find()) { -3289 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3290 } -3291 } else if (subCon) { -3292 ret[idx] = tmp[idx % tmp.length] -3293 //0 -3294 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) -3295 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) -3296 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) -3297 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) -3298 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) -3299 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) -3300 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) -3301 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) -3302 //9 -3303 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) -3304 //11 -3305 //12 -3306 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) -3307 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) -3308 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) -3309 //16 -3310 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) -3311 //18 -3312 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) -3313 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); -3314 -3315 matcher = repeats.matcher(ret[idx]); -3316 if (matcher.find()) { -3317 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); -3318 } -3319 } else ret[idx] = tmp[idx % tmp.length]; -3320 -3321 } -3322 } else -3323 return new String[]{}; -3324 return ret; -3325 } -3326 -3327 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { -3328 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); -3329 double myInfluence = 1.0 - otherInfluence; -3330 -3331 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) -3332 ^ NumberTools.doubleToLongBits(otherInfluence)); -3333 -3334 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), -3335 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), -3336 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * -3337 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), -3338 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), -3339 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * -3340 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), -3341 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * -3342 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), -3343 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); -3344 -3345 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); -3346 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { -3347 if (freqs.containsKey(kv.getIntKey())) -3348 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); -3349 else -3350 freqs.put(kv.getIntKey(), kv.getDoubleValue()); -3351 } -3352 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); -3353 mods.addAll(modifiers); -3354 mods.addAll(other.modifiers); -3355 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, -3356 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, -3357 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, -3358 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, -3359 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, -3360 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); -3361 } +3231 for (; idx < 1000; idx++) { +3232 ret[idx] = tmp[idx % tmp.length]; +3233 } +3234 } else +3235 return new String[]{}; +3236 return ret; +3237 } +3238 +3239 protected String[] accentConsonants(RNG rng, String[] me, double influence) { +3240 String[] ret = new String[1000]; +3241 int otherCount = (int) (1000 * influence); +3242 int idx = 0; +3243 Matcher matcher; +3244 if (me.length > 0) { +3245 String[] tmp = new String[me.length]; +3246 rng.shuffle(me, tmp); +3247 for (idx = 0; idx < otherCount; idx++) { +3248 ret[idx] = tmp[idx % tmp.length] +3249 //0 +3250 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3251 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3252 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3253 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3254 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3255 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3256 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3257 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3258 //9 +3259 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3260 //11 +3261 //12 +3262 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3263 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3264 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3265 //16 +3266 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3267 //18 +3268 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3269 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3270 +3271 matcher = repeats.matcher(ret[idx]); +3272 if (matcher.find()) { +3273 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3274 } +3275 } +3276 for (; idx < 1000; idx++) { +3277 ret[idx] = tmp[idx % tmp.length]; +3278 } +3279 } else +3280 return new String[]{}; +3281 return ret; +3282 } +3283 +3284 protected String[] accentBoth(RNG rng, String[] me, double vowelInfluence, double consonantInfluence) { +3285 String[] ret = new String[1000]; +3286 int idx = 0; +3287 Matcher matcher; +3288 if (me.length > 0) { +3289 String[] tmp = new String[me.length]; +3290 rng.shuffle(me, tmp); +3291 for (idx = 0; idx < 1000; idx++) { +3292 boolean subVowel = rng.nextDouble() < vowelInfluence, subCon = rng.nextDouble() < consonantInfluence; +3293 if (subVowel && subCon) { +3294 ret[idx] = tmp[idx % tmp.length] +3295 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3296 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3297 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3298 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3299 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]) +3300 +3301 //0 +3302 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3303 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3304 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3305 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3306 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3307 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3308 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3309 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3310 //9 +3311 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3312 //11 +3313 //12 +3314 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3315 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3316 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3317 //16 +3318 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3319 //18 +3320 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3321 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); +3322 +3323 matcher = repeats.matcher(ret[idx]); +3324 if (matcher.find()) { +3325 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3326 } +3327 } else if (subVowel) { +3328 ret[idx] = tmp[idx % tmp.length] +3329 .replace('a', accentedVowels[0][rng.nextInt(accentedVowels[0].length)]) +3330 .replace('e', accentedVowels[1][rng.nextInt(accentedVowels[1].length)]) +3331 .replace('i', accentedVowels[2][rng.nextInt(accentedVowels[2].length)]) +3332 .replace('o', accentedVowels[3][rng.nextInt(accentedVowels[3].length)]) +3333 .replace('u', accentedVowels[4][rng.nextInt(accentedVowels[4].length)]); +3334 +3335 matcher = repeats.matcher(ret[idx]); +3336 if (matcher.find()) { +3337 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3338 } +3339 } else if (subCon) { +3340 ret[idx] = tmp[idx % tmp.length] +3341 //0 +3342 .replace('c', accentedConsonants[1][rng.nextInt(accentedConsonants[1].length)]) +3343 .replace('d', accentedConsonants[2][rng.nextInt(accentedConsonants[2].length)]) +3344 .replace('f', accentedConsonants[3][rng.nextInt(accentedConsonants[3].length)]) +3345 .replace('g', accentedConsonants[4][rng.nextInt(accentedConsonants[4].length)]) +3346 .replace('h', accentedConsonants[5][rng.nextInt(accentedConsonants[5].length)]) +3347 .replace('j', accentedConsonants[6][rng.nextInt(accentedConsonants[6].length)]) +3348 .replace('k', accentedConsonants[7][rng.nextInt(accentedConsonants[7].length)]) +3349 .replace('l', accentedConsonants[8][rng.nextInt(accentedConsonants[8].length)]) +3350 //9 +3351 .replace('n', accentedConsonants[10][rng.nextInt(accentedConsonants[10].length)]) +3352 //11 +3353 //12 +3354 .replace('r', accentedConsonants[13][rng.nextInt(accentedConsonants[13].length)]) +3355 .replace('s', accentedConsonants[14][rng.nextInt(accentedConsonants[14].length)]) +3356 .replace('t', accentedConsonants[15][rng.nextInt(accentedConsonants[15].length)]) +3357 //16 +3358 .replace('w', accentedConsonants[17][rng.nextInt(accentedConsonants[17].length)]) +3359 //18 +3360 .replace('y', accentedConsonants[19][rng.nextInt(accentedConsonants[19].length)]) +3361 .replace('z', accentedConsonants[20][rng.nextInt(accentedConsonants[20].length)]); 3362 -3363 private static double readDouble(Object o) { -3364 if (o instanceof Double) return (Double) o; -3365 else if (o instanceof Float) return (Float) o; -3366 else if (o instanceof Long) return ((Long) o).doubleValue(); -3367 else if (o instanceof Integer) return (Integer) o; -3368 else if (o instanceof Short) return (Short) o; -3369 else if (o instanceof Byte) return (Byte) o; -3370 else if (o instanceof Character) return (Character) o; -3371 return 0.0; -3372 } -3373 -3374 /** -3375 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes -3376 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of -3377 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a -3378 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this -3379 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. -3380 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type -3381 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some -3382 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and -3383 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern -3384 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on -3385 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3386 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3387 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3388 * with 0.33 . -3389 * <br> -3390 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the -3391 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for -3392 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 -3393 * the bytes used in one not-quite-simple test). -3394 * -3395 * @param myWeight the weight to assign this FakeLanguageGen in the mix -3396 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} -3397 * @param weight1 the weight to assign other1 in the mix -3398 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements -3399 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights -3400 */ -3401 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { -3402 if (other1 == null || pairs == null) -3403 return copy(); -3404 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); -3405 FakeLanguageGen mixer = removeModifiers(); -3406 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; -3407 double[] weights = new double[languages.length]; -3408 String[] summaries = new String[languages.length]; -3409 boolean summarize = true; -3410 double total = 0.0, current, weight; -3411 languages[0] = mixer; -3412 total += weights[0] = myWeight; -3413 if ((summaries[0] = mixer.summary) == null) summarize = false; -3414 mods.addAll(other1.modifiers); -3415 languages[1] = other1.removeModifiers(); -3416 total += weights[1] = weight1; -3417 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; -3418 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { -3419 if (pairs[i] == null || pairs[i - 1] == null) -3420 continue; -3421 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); -3422 total += weights[p] = readDouble(pairs[i]); -3423 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; -3424 } -3425 if (total == 0) -3426 return copy(); -3427 current = myWeight / total; -3428 for (int i = 1; i < languages.length; i++) { -3429 if ((weight = weights[i]) > 0) -3430 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); -3431 } -3432 if (summarize) { -3433 StringBuilder brief = new StringBuilder(64); -3434 String c; -3435 int idx; -3436 for (int i = 0; i < summaries.length; i++) { -3437 c = summaries[i]; -3438 idx = c.indexOf('@'); -3439 if (idx >= 0) { -3440 brief.append(c.substring(0, idx + 1)).append(weights[i]); -3441 if (i < summaries.length - 1) -3442 brief.append('~'); -3443 } -3444 } -3445 for (int i = 0; i < mods.size(); i++) { -3446 brief.append('℗').append(mods.getAt(i).serializeToString()); -3447 } -3448 return mixer.addModifiers(mods).summarize(brief.toString()); -3449 } else -3450 return mixer.addModifiers(mods); -3451 } -3452 -3453 /** -3454 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. -3455 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the -3456 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double -3457 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then -3458 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them -3459 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one -3460 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on -3461 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes -3462 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use -3463 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third -3464 * with 0.33 . -3465 * <br> -3466 * Not intended for external use, but it could be useful. Used internally in the deserialization code. -3467 * -3468 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements -3469 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights -3470 */ -3471 public static FakeLanguageGen mixAll(Object... pairs) { -3472 int len; -3473 if (pairs == null || (len = pairs.length) <= 0) -3474 return ENGLISH.copy(); -3475 if (len < 4) -3476 return ((FakeLanguageGen) pairs[0]).copy(); -3477 Object[] pairs2 = new Object[len - 4]; -3478 if (len > 4) -3479 System.arraycopy(pairs, 4, pairs2, 0, len - 4); -3480 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); -3481 } -3482 -3483 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { -3484 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); -3485 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); -3486 -3487 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ -3488 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); -3489 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), -3490 mv = accentVowels(rng, midVowels, vowelInfluence), -3491 oc = accentConsonants(rng, openingConsonants, consonantInfluence), -3492 mc = accentConsonants(rng, midConsonants, consonantInfluence), -3493 cc = accentConsonants(rng, closingConsonants, consonantInfluence), -3494 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); -3495 -3496 -3497 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3498 vowelStartFrequency, -3499 vowelEndFrequency, -3500 vowelSplitFrequency, -3501 syllableEndFrequency, sanityChecks, clean, modifiers); -3502 } -3503 -3504 static String[] copyStrings(String[] start) { -3505 String[] next = new String[start.length]; -3506 System.arraycopy(start, 0, next, 0, start.length); -3507 return next; -3508 } -3509 -3510 public FakeLanguageGen removeAccents() { -3511 -3512 String[] ov = copyStrings(openingVowels), -3513 mv = copyStrings(midVowels), -3514 oc = copyStrings(openingConsonants), -3515 mc = copyStrings(midConsonants), -3516 cc = copyStrings(closingConsonants), -3517 cs = copyStrings(closingSyllables); -3518 for (int i = 0; i < ov.length; i++) { -3519 ov[i] = removeAccents(openingVowels[i]).toString(); -3520 } -3521 for (int i = 0; i < mv.length; i++) { -3522 mv[i] = removeAccents(midVowels[i]).toString(); -3523 } -3524 for (int i = 0; i < oc.length; i++) { -3525 oc[i] = removeAccents(openingConsonants[i]).toString(); -3526 } -3527 for (int i = 0; i < mc.length; i++) { -3528 mc[i] = removeAccents(midConsonants[i]).toString(); -3529 } -3530 for (int i = 0; i < cc.length; i++) { -3531 cc[i] = removeAccents(closingConsonants[i]).toString(); -3532 } -3533 for (int i = 0; i < cs.length; i++) { -3534 cs[i] = removeAccents(closingSyllables[i]).toString(); -3535 } -3536 -3537 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, -3538 vowelStartFrequency, -3539 vowelEndFrequency, -3540 vowelSplitFrequency, -3541 syllableEndFrequency, sanityChecks, clean, modifiers); -3542 } +3363 matcher = repeats.matcher(ret[idx]); +3364 if (matcher.find()) { +3365 ret[idx] = matcher.replaceAll(rng.getRandomElement(me)); +3366 } +3367 } else ret[idx] = tmp[idx % tmp.length]; +3368 +3369 } +3370 } else +3371 return new String[]{}; +3372 return ret; +3373 } +3374 +3375 public FakeLanguageGen mix(FakeLanguageGen other, double otherInfluence) { +3376 otherInfluence = Math.max(0.0, Math.min(otherInfluence, 1.0)); +3377 double myInfluence = 1.0 - otherInfluence; +3378 +3379 RNG rng = new RNG((hashCode() & 0xffffffffL) | ((other.hashCode() & 0xffffffffL) << 32) +3380 ^ NumberTools.doubleToLongBits(otherInfluence)); +3381 +3382 String[] ov = merge1000(rng, openingVowels, other.openingVowels, otherInfluence), +3383 mv = merge1000(rng, midVowels, other.midVowels, otherInfluence), +3384 oc = merge1000(rng, openingConsonants, other.openingConsonants, otherInfluence * +3385 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelStartFrequency + vowelStartFrequency))), +3386 mc = merge1000(rng, midConsonants, other.midConsonants, otherInfluence), +3387 cc = merge1000(rng, closingConsonants, other.closingConsonants, otherInfluence * +3388 Math.max(0.0, Math.min(1.0, 1.0 - other.vowelEndFrequency + vowelEndFrequency))), +3389 cs = merge1000(rng, closingSyllables, other.closingSyllables, otherInfluence * +3390 Math.max(0.0, Math.min(1.0, other.syllableEndFrequency - syllableEndFrequency))), +3391 splitters = merge1000(rng, vowelSplitters, other.vowelSplitters, otherInfluence); +3392 +3393 IntDoubleOrderedMap freqs = new IntDoubleOrderedMap(syllableFrequencies); +3394 for (IntDoubleOrderedMap.MapEntry kv : other.syllableFrequencies.mapEntrySet()) { +3395 if (freqs.containsKey(kv.getIntKey())) +3396 freqs.put(kv.getIntKey(), kv.getDoubleValue() + freqs.get(kv.getIntKey())); +3397 else +3398 freqs.put(kv.getIntKey(), kv.getDoubleValue()); +3399 } +3400 List<Modifier> mods = new ArrayList<>(modifiers.size() + other.modifiers.size()); +3401 mods.addAll(modifiers); +3402 mods.addAll(other.modifiers); +3403 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, splitters, freqs, +3404 vowelStartFrequency * myInfluence + other.vowelStartFrequency * otherInfluence, +3405 vowelEndFrequency * myInfluence + other.vowelEndFrequency * otherInfluence, +3406 vowelSplitFrequency * myInfluence + other.vowelSplitFrequency * otherInfluence, +3407 syllableEndFrequency * myInfluence + other.syllableEndFrequency * otherInfluence, +3408 (sanityChecks == null) ? other.sanityChecks : sanityChecks, true, mods); +3409 } +3410 +3411 private static double readDouble(Object o) { +3412 if (o instanceof Double) return (Double) o; +3413 else if (o instanceof Float) return (Float) o; +3414 else if (o instanceof Long) return ((Long) o).doubleValue(); +3415 else if (o instanceof Integer) return (Integer) o; +3416 else if (o instanceof Short) return (Short) o; +3417 else if (o instanceof Byte) return (Byte) o; +3418 else if (o instanceof Character) return (Character) o; +3419 return 0.0; +3420 } +3421 +3422 /** +3423 * Produces a FakeLanguageGen by mixing this FakeLanguageGen with one or more other FakeLanguageGen objects. Takes +3424 * a weight for this, another FakeLanguageGen, a weight for that FakeLanguageGen, then a possibly-empty group of +3425 * FakeLanguageGen parameters and the weights for those parameters. If other1 is null or if pairs has been given a +3426 * value of null instead of the normal (possibly empty) array of Objects, then this simply returns a copy of this +3427 * FakeLanguageGen. Otherwise, it will at least mix this language with other1 using the given weights for each. +3428 * If pairs is not empty, it has special requirements for what types it allows and in what order, but does no type +3429 * checking. Specifically, pairs requires the first Object to be a FakeLanguageGen, the next to be a number of some +3430 * kind that will be the weight for the previous FakeLanguageGen(this method can handle non-Double weights, and +3431 * converts them to Double if needed), and every two parameters after that to follow the same order and pattern +3432 * (FakeLanguageGen, then number, then FakeLanguageGen, then number...). Weights are absolute, and don't depend on +3433 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3434 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3435 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3436 * with 0.33 . +3437 * <br> +3438 * Unlike the static method {@link #mixAll(Object...)}, this _is_ intended for external use, in part because the +3439 * technique for mixing languages by weight is so much more intuitive, but also because this assigns valid data for +3440 * serializing and deserializing this FakeLanguageGen that allows it to use significantly less space (less than 1/72 +3441 * the bytes used in one not-quite-simple test). +3442 * +3443 * @param myWeight the weight to assign this FakeLanguageGen in the mix +3444 * @param other1 another FakeLanguageGen to mix in; if null, this method will abort and return {@link #copy()} +3445 * @param weight1 the weight to assign other1 in the mix +3446 * @param pairs may be empty, not null; otherwise must alternate between FakeLanguageGen and number (weight) elements +3447 * @return a FakeLanguageGen produced by mixing this with any FakeLanguageGen arguments by the given weights +3448 */ +3449 public FakeLanguageGen mix(double myWeight, FakeLanguageGen other1, double weight1, Object... pairs) { +3450 if (other1 == null || pairs == null) +3451 return copy(); +3452 OrderedSet<Modifier> mods = new OrderedSet<>(modifiers); +3453 FakeLanguageGen mixer = removeModifiers(); +3454 FakeLanguageGen[] languages = new FakeLanguageGen[2 + (pairs.length >>> 1)]; +3455 double[] weights = new double[languages.length]; +3456 String[] summaries = new String[languages.length]; +3457 boolean summarize = true; +3458 double total = 0.0, current, weight; +3459 languages[0] = mixer; +3460 total += weights[0] = myWeight; +3461 if ((summaries[0] = mixer.summary) == null) summarize = false; +3462 mods.addAll(other1.modifiers); +3463 languages[1] = other1.removeModifiers(); +3464 total += weights[1] = weight1; +3465 if (summarize && (summaries[1] = languages[1].summary) == null) summarize = false; +3466 for (int i = 1, p = 2; i < pairs.length; i += 2, p++) { +3467 if (pairs[i] == null || pairs[i - 1] == null) +3468 continue; +3469 languages[p] = ((FakeLanguageGen) pairs[i - 1]).removeModifiers(); +3470 total += weights[p] = readDouble(pairs[i]); +3471 if (summarize && (summaries[p] = languages[p].summary) == null) summarize = false; +3472 } +3473 if (total == 0) +3474 return copy(); +3475 current = myWeight / total; +3476 for (int i = 1; i < languages.length; i++) { +3477 if ((weight = weights[i]) > 0) +3478 mixer = mixer.mix(languages[i], weight / total / (current += weight / total)); +3479 } +3480 if (summarize) { +3481 StringBuilder brief = new StringBuilder(64); +3482 String c; +3483 int idx; +3484 for (int i = 0; i < summaries.length; i++) { +3485 c = summaries[i]; +3486 idx = c.indexOf('@'); +3487 if (idx >= 0) { +3488 brief.append(c.substring(0, idx + 1)).append(weights[i]); +3489 if (i < summaries.length - 1) +3490 brief.append('~'); +3491 } +3492 } +3493 for (int i = 0; i < mods.size(); i++) { +3494 brief.append('℗').append(mods.getAt(i).serializeToString()); +3495 } +3496 return mixer.addModifiers(mods).summarize(brief.toString()); +3497 } else +3498 return mixer.addModifiers(mods); +3499 } +3500 +3501 /** +3502 * Produces a FakeLanguageGen from a group of FakeLanguageGen parameters and the weights for those parameters. +3503 * Requires the first Object in pairs to be a FakeLanguageGen, the next to be a number of some kind that will be the +3504 * weight for the previous FakeLanguageGen(this method can handle non-Double weights, and converts them to Double +3505 * if needed), and every two parameters after that to follow the same order and pattern (FakeLanguageGen, then +3506 * number, then FakeLanguageGen, then number...). There should be at least 4 elements in pairs, half of them +3507 * languages and half of them weights, for this to do any mixing, but it can produce a result with as little as one +3508 * FakeLanguageGen (returning a copy of the first FakeLanguageGen). Weights are absolute, and don't depend on +3509 * earlier weights, which is the case when chaining the {@link #mix(FakeLanguageGen, double)} method. This makes +3510 * reasoning about the ideal weights for multiple mixed languages easier; to mix 3 languages equally you can use +3511 * 3 equal weights with this, whereas with mix chaining you would need to mix the first two with 0.5 and the third +3512 * with 0.33 . +3513 * <br> +3514 * Not intended for external use, but it could be useful. Used internally in the deserialization code. +3515 * +3516 * @param pairs should have at least one item, and must alternate between FakeLanguageGen and number (weight) elements +3517 * @return a FakeLanguageGen produced by mixing any FakeLanguageGen arguments by the given weights +3518 */ +3519 public static FakeLanguageGen mixAll(Object... pairs) { +3520 int len; +3521 if (pairs == null || (len = pairs.length) <= 0) +3522 return ENGLISH.copy(); +3523 if (len < 4) +3524 return ((FakeLanguageGen) pairs[0]).copy(); +3525 Object[] pairs2 = new Object[len - 4]; +3526 if (len > 4) +3527 System.arraycopy(pairs, 4, pairs2, 0, len - 4); +3528 return ((FakeLanguageGen) pairs[0]).mix(readDouble(pairs[1]), (FakeLanguageGen) pairs[2], readDouble(pairs[3]), pairs2); +3529 } +3530 +3531 public FakeLanguageGen addAccents(double vowelInfluence, double consonantInfluence) { +3532 vowelInfluence = Math.max(0.0, Math.min(vowelInfluence, 1.0)); +3533 consonantInfluence = Math.max(0.0, Math.min(consonantInfluence, 1.0)); +3534 +3535 RNG rng = new RNG((hashCode() & 0xffffffffL) ^ +3536 ((NumberTools.doubleToLongBits(vowelInfluence) & 0xffffffffL) | (NumberTools.doubleToLongBits(consonantInfluence) << 32))); +3537 String[] ov = accentVowels(rng, openingVowels, vowelInfluence), +3538 mv = accentVowels(rng, midVowels, vowelInfluence), +3539 oc = accentConsonants(rng, openingConsonants, consonantInfluence), +3540 mc = accentConsonants(rng, midConsonants, consonantInfluence), +3541 cc = accentConsonants(rng, closingConsonants, consonantInfluence), +3542 cs = accentBoth(rng, closingSyllables, vowelInfluence, consonantInfluence); 3543 -3544 /** -3545 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. -3546 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3547 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3548 * -3549 * @param mods an array or vararg of Modifier objects -3550 * @return a copy of this with the Modifiers added -3551 */ -3552 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { -3553 FakeLanguageGen next = copy(); -3554 next.modifiers.addAll(mods); +3544 +3545 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3546 vowelStartFrequency, +3547 vowelEndFrequency, +3548 vowelSplitFrequency, +3549 syllableEndFrequency, sanityChecks, clean, modifiers); +3550 } +3551 +3552 static String[] copyStrings(String[] start) { +3553 String[] next = new String[start.length]; +3554 System.arraycopy(start, 0, next, 0, start.length); 3555 return next; 3556 } 3557 -3558 /** -3559 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. -3560 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the -3561 * FakeLanguageGen.modifier() method, or Modifier's constructor. -3562 * -3563 * @param mods an array or vararg of Modifier objects -3564 * @return a copy of this with the Modifiers added -3565 */ -3566 public FakeLanguageGen addModifiers(Modifier... mods) { -3567 FakeLanguageGen next = copy(); -3568 Collections.addAll(next.modifiers, mods); -3569 return next; -3570 } -3571 -3572 /** -3573 * Creates a copy of this FakeLanguageGen with no modifiers. -3574 * -3575 * @return a copy of this FakeLanguageGen with modifiers removed. -3576 */ -3577 public FakeLanguageGen removeModifiers() { -3578 FakeLanguageGen next = copy(); -3579 next.modifiers.clear(); -3580 return next; -3581 } -3582 -3583 public static Modifier modifier(String pattern, String replacement) { -3584 return new Modifier(pattern, replacement); -3585 } -3586 -3587 public static Modifier modifier(String pattern, String replacement, double chance) { -3588 return new Modifier(pattern, replacement, chance); -3589 } -3590 -3591 @Override -3592 public boolean equals(Object o) { -3593 if (this == o) return true; -3594 if (o == null || getClass() != o.getClass()) return false; -3595 -3596 FakeLanguageGen that = (FakeLanguageGen) o; -3597 -3598 if (clean != that.clean) return false; -3599 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; -3600 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; -3601 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; -3602 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; -3603 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; -3604 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3605 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; -3606 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3607 if (!Arrays.equals(midVowels, that.midVowels)) return false; -3608 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3609 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; -3610 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3611 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; -3612 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3613 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; -3614 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3615 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; -3616 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3617 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; -3618 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; -3619 // Probably incorrect - comparing Object[] arrays with Arrays.equals -3620 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; -3621 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; -3622 } -3623 -3624 @Override -3625 public int hashCode() { -3626 int result; -3627 long temp; -3628 result = CrossHash.Lightning.hash(openingVowels); -3629 result = 31 * result + CrossHash.Lightning.hash(midVowels); -3630 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); -3631 result = 31 * result + CrossHash.Lightning.hash(midConsonants); -3632 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); -3633 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); -3634 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); -3635 result = 31 * result + (clean ? 1 : 0); -3636 result = 31 * result + syllableFrequencies.hashCode(); -3637 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); -3638 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3639 temp = NumberTools.doubleToLongBits(vowelStartFrequency); -3640 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3641 temp = NumberTools.doubleToLongBits(vowelEndFrequency); -3642 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3643 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); -3644 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3645 temp = NumberTools.doubleToLongBits(syllableEndFrequency); -3646 result = 31 * result + (int) (temp ^ (temp >>> 32)); -3647 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); -3648 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); -3649 return result; -3650 } -3651 -3652 @Override -3653 public String toString() { -3654 return "FakeLanguageGen{" + -3655 "openingVowels=" + Arrays.toString(openingVowels) + -3656 ", midVowels=" + Arrays.toString(midVowels) + -3657 ", openingConsonants=" + Arrays.toString(openingConsonants) + -3658 ", midConsonants=" + Arrays.toString(midConsonants) + -3659 ", closingConsonants=" + Arrays.toString(closingConsonants) + -3660 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + -3661 ", closingSyllables=" + Arrays.toString(closingSyllables) + -3662 ", clean=" + clean + -3663 ", syllableFrequencies=" + syllableFrequencies + -3664 ", totalSyllableFrequency=" + totalSyllableFrequency + -3665 ", vowelStartFrequency=" + vowelStartFrequency + -3666 ", vowelEndFrequency=" + vowelEndFrequency + -3667 ", vowelSplitFrequency=" + vowelSplitFrequency + -3668 ", syllableEndFrequency=" + syllableEndFrequency + -3669 ", sanityChecks=" + Arrays.toString(sanityChecks) + -3670 ", modifiers=" + modifiers + -3671 '}'; -3672 } -3673 -3674 public FakeLanguageGen copy() { -3675 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, -3676 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, -3677 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) -3678 .summarize(summary); -3679 } -3680 -3681 -3682 public String serializeToString() { -3683 return (summary == null) ? "" : summary; -3684 } -3685 -3686 public static FakeLanguageGen deserializeFromString(String data) { -3687 if (data == null || data.equals("")) -3688 return ENGLISH.copy(); -3689 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), -3690 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, -3691 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; -3692 if (tildeIndex < 0) -3693 tildeIndex = data.length(); -3694 -3695 if (snailIndex < 0) -3696 return ENGLISH.copy(); -3697 ArrayList<Object> pairs = new ArrayList<>(4); -3698 while (snailIndex >= 0) { -3699 if (poundIndex >= 0 && poundIndex < snailIndex) // random case -3700 { -3701 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); -3702 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3703 poundIndex = -1; -3704 } else { -3705 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); -3706 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); -3707 } -3708 snailIndex = data.indexOf('@', snailIndex + 1); -3709 if (snailIndex > breakIndex) -3710 break; -3711 prevTildeIndex = tildeIndex; -3712 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); -3713 if (tildeIndex < 0) -3714 tildeIndex = data.length(); -3715 } -3716 ArrayList<Modifier> mods = new ArrayList<>(8); -3717 if (breakIndex == tempBreak) { -3718 tildeIndex = breakIndex - 1; -3719 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { -3720 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); -3721 if (tildeIndex < 0) tildeIndex = data.length(); -3722 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); -3723 } -3724 } -3725 FakeLanguageGen flg = mixAll(pairs.toArray()); -3726 flg.modifiers.addAll(mods); -3727 return flg; -3728 } +3558 public FakeLanguageGen removeAccents() { +3559 +3560 String[] ov = copyStrings(openingVowels), +3561 mv = copyStrings(midVowels), +3562 oc = copyStrings(openingConsonants), +3563 mc = copyStrings(midConsonants), +3564 cc = copyStrings(closingConsonants), +3565 cs = copyStrings(closingSyllables); +3566 for (int i = 0; i < ov.length; i++) { +3567 ov[i] = removeAccents(openingVowels[i]).toString(); +3568 } +3569 for (int i = 0; i < mv.length; i++) { +3570 mv[i] = removeAccents(midVowels[i]).toString(); +3571 } +3572 for (int i = 0; i < oc.length; i++) { +3573 oc[i] = removeAccents(openingConsonants[i]).toString(); +3574 } +3575 for (int i = 0; i < mc.length; i++) { +3576 mc[i] = removeAccents(midConsonants[i]).toString(); +3577 } +3578 for (int i = 0; i < cc.length; i++) { +3579 cc[i] = removeAccents(closingConsonants[i]).toString(); +3580 } +3581 for (int i = 0; i < cs.length; i++) { +3582 cs[i] = removeAccents(closingSyllables[i]).toString(); +3583 } +3584 +3585 return new FakeLanguageGen(ov, mv, oc, mc, cc, cs, vowelSplitters, syllableFrequencies, +3586 vowelStartFrequency, +3587 vowelEndFrequency, +3588 vowelSplitFrequency, +3589 syllableEndFrequency, sanityChecks, clean, modifiers); +3590 } +3591 +3592 /** +3593 * Adds the specified Modifier objects from a Collection to a copy of this FakeLanguageGen and returns it. +3594 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3595 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3596 * +3597 * @param mods an array or vararg of Modifier objects +3598 * @return a copy of this with the Modifiers added +3599 */ +3600 public FakeLanguageGen addModifiers(Collection<Modifier> mods) { +3601 FakeLanguageGen next = copy(); +3602 next.modifiers.addAll(mods); +3603 return next; +3604 } +3605 +3606 /** +3607 * Adds the specified Modifier objects to a copy of this FakeLanguageGen and returns it. +3608 * You can obtain a Modifier with the static constants in the FakeLanguageGen.Modifier nested class, the +3609 * FakeLanguageGen.modifier() method, or Modifier's constructor. +3610 * +3611 * @param mods an array or vararg of Modifier objects +3612 * @return a copy of this with the Modifiers added +3613 */ +3614 public FakeLanguageGen addModifiers(Modifier... mods) { +3615 FakeLanguageGen next = copy(); +3616 Collections.addAll(next.modifiers, mods); +3617 return next; +3618 } +3619 +3620 /** +3621 * Creates a copy of this FakeLanguageGen with no modifiers. +3622 * +3623 * @return a copy of this FakeLanguageGen with modifiers removed. +3624 */ +3625 public FakeLanguageGen removeModifiers() { +3626 FakeLanguageGen next = copy(); +3627 next.modifiers.clear(); +3628 return next; +3629 } +3630 +3631 public static Modifier modifier(String pattern, String replacement) { +3632 return new Modifier(pattern, replacement); +3633 } +3634 +3635 public static Modifier modifier(String pattern, String replacement, double chance) { +3636 return new Modifier(pattern, replacement, chance); +3637 } +3638 +3639 @Override +3640 public boolean equals(Object o) { +3641 if (this == o) return true; +3642 if (o == null || getClass() != o.getClass()) return false; +3643 +3644 FakeLanguageGen that = (FakeLanguageGen) o; +3645 +3646 if (clean != that.clean) return false; +3647 if (Double.compare(that.totalSyllableFrequency, totalSyllableFrequency) != 0) return false; +3648 if (Double.compare(that.vowelStartFrequency, vowelStartFrequency) != 0) return false; +3649 if (Double.compare(that.vowelEndFrequency, vowelEndFrequency) != 0) return false; +3650 if (Double.compare(that.vowelSplitFrequency, vowelSplitFrequency) != 0) return false; +3651 if (Double.compare(that.syllableEndFrequency, syllableEndFrequency) != 0) return false; +3652 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3653 if (!Arrays.equals(openingVowels, that.openingVowels)) return false; +3654 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3655 if (!Arrays.equals(midVowels, that.midVowels)) return false; +3656 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3657 if (!Arrays.equals(openingConsonants, that.openingConsonants)) return false; +3658 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3659 if (!Arrays.equals(midConsonants, that.midConsonants)) return false; +3660 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3661 if (!Arrays.equals(closingConsonants, that.closingConsonants)) return false; +3662 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3663 if (!Arrays.equals(vowelSplitters, that.vowelSplitters)) return false; +3664 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3665 if (!Arrays.equals(closingSyllables, that.closingSyllables)) return false; +3666 if (!syllableFrequencies.equals(that.syllableFrequencies)) return false; +3667 // Probably incorrect - comparing Object[] arrays with Arrays.equals +3668 if (!Arrays.equals(sanityChecks, that.sanityChecks)) return false; +3669 return modifiers != null ? modifiers.equals(that.modifiers) : that.modifiers == null; +3670 } +3671 +3672 @Override +3673 public int hashCode() { +3674 int result; +3675 long temp; +3676 result = CrossHash.Lightning.hash(openingVowels); +3677 result = 31 * result + CrossHash.Lightning.hash(midVowels); +3678 result = 31 * result + CrossHash.Lightning.hash(openingConsonants); +3679 result = 31 * result + CrossHash.Lightning.hash(midConsonants); +3680 result = 31 * result + CrossHash.Lightning.hash(closingConsonants); +3681 result = 31 * result + CrossHash.Lightning.hash(vowelSplitters); +3682 result = 31 * result + CrossHash.Lightning.hash(closingSyllables); +3683 result = 31 * result + (clean ? 1 : 0); +3684 result = 31 * result + syllableFrequencies.hashCode(); +3685 temp = NumberTools.doubleToLongBits(totalSyllableFrequency); +3686 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3687 temp = NumberTools.doubleToLongBits(vowelStartFrequency); +3688 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3689 temp = NumberTools.doubleToLongBits(vowelEndFrequency); +3690 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3691 temp = NumberTools.doubleToLongBits(vowelSplitFrequency); +3692 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3693 temp = NumberTools.doubleToLongBits(syllableEndFrequency); +3694 result = 31 * result + (int) (temp ^ (temp >>> 32)); +3695 result = 31 * result + (sanityChecks != null ? sanityChecks.length + 1 : 0); +3696 result = 31 * result + (modifiers != null ? modifiers.hashCode() : 0); +3697 return result; +3698 } +3699 +3700 @Override +3701 public String toString() { +3702 return "FakeLanguageGen{" + +3703 "openingVowels=" + Arrays.toString(openingVowels) + +3704 ", midVowels=" + Arrays.toString(midVowels) + +3705 ", openingConsonants=" + Arrays.toString(openingConsonants) + +3706 ", midConsonants=" + Arrays.toString(midConsonants) + +3707 ", closingConsonants=" + Arrays.toString(closingConsonants) + +3708 ", vowelSplitters=" + Arrays.toString(vowelSplitters) + +3709 ", closingSyllables=" + Arrays.toString(closingSyllables) + +3710 ", clean=" + clean + +3711 ", syllableFrequencies=" + syllableFrequencies + +3712 ", totalSyllableFrequency=" + totalSyllableFrequency + +3713 ", vowelStartFrequency=" + vowelStartFrequency + +3714 ", vowelEndFrequency=" + vowelEndFrequency + +3715 ", vowelSplitFrequency=" + vowelSplitFrequency + +3716 ", syllableEndFrequency=" + syllableEndFrequency + +3717 ", sanityChecks=" + Arrays.toString(sanityChecks) + +3718 ", modifiers=" + modifiers + +3719 '}'; +3720 } +3721 +3722 public FakeLanguageGen copy() { +3723 return new FakeLanguageGen(openingVowels, midVowels, openingConsonants, midConsonants, +3724 closingConsonants, closingSyllables, vowelSplitters, syllableFrequencies, vowelStartFrequency, +3725 vowelEndFrequency, vowelSplitFrequency, syllableEndFrequency, sanityChecks, clean, modifiers) +3726 .summarize(summary); +3727 } +3728 3729 -3730 public static class Modifier implements Serializable { -3731 private static final long serialVersionUID = 1734863678490422371L; -3732 public final Alteration[] alterations; +3730 public String serializeToString() { +3731 return (summary == null) ? "" : summary; +3732 } 3733 -3734 public Modifier() { -3735 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -3736 } -3737 -3738 public Modifier(String pattern, String replacement) { -3739 alterations = new Alteration[]{new Alteration(pattern, replacement)}; -3740 } -3741 -3742 public Modifier(String pattern, String replacement, double chance) { -3743 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; -3744 } -3745 -3746 public Modifier(Alteration... alts) { -3747 alterations = (alts == null) ? new Alteration[0] : alts; -3748 } -3749 -3750 public StringBuilder modify(RNG rng, StringBuilder sb) { -3751 Matcher m; -3752 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); -3753 String tmp; -3754 boolean found; -3755 Alteration alt; -3756 for (int a = 0; a < alterations.length; a++) { -3757 alt = alterations[a]; -3758 tmp = working.toString(); -3759 tb = Replacer.wrap(new StringBuilder(tmp.length())); -3760 m = alt.replacer.getPattern().matcher(tmp); -3761 -3762 found = false; -3763 while (true) { -3764 if (rng.nextDouble() < alt.chance) { -3765 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) -3766 break; -3767 found = true; -3768 } else { -3769 if (!m.find()) -3770 break; -3771 found = true; -3772 m.getGroup(MatchResult.PREFIX, tb); -3773 m.getGroup(MatchResult.MATCH, tb); -3774 m.setTarget(m, MatchResult.SUFFIX); -3775 } -3776 } -3777 if (found) { -3778 m.getGroup(MatchResult.TARGET, tb); -3779 working = tb; -3780 } -3781 } -3782 return working.toStringBuilder(); -3783 } -3784 -3785 /** -3786 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. -3787 */ -3788 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3734 public static FakeLanguageGen deserializeFromString(String data) { +3735 if (data == null || data.equals("")) +3736 return ENGLISH.copy(); +3737 int poundIndex = data.indexOf('#'), snailIndex = data.indexOf('@'), tempBreak = data.indexOf('℗'), +3738 breakIndex = (tempBreak < 0) ? data.length() : tempBreak, +3739 tildeIndex = Math.min(data.indexOf('~'), breakIndex), prevTildeIndex = -1; +3740 if (tildeIndex < 0) +3741 tildeIndex = data.length(); +3742 +3743 if (snailIndex < 0) +3744 return ENGLISH.copy(); +3745 ArrayList<Object> pairs = new ArrayList<>(4); +3746 while (snailIndex >= 0) { +3747 if (poundIndex >= 0 && poundIndex < snailIndex) // random case +3748 { +3749 pairs.add(randomLanguage(Long.parseLong(data.substring(poundIndex + 1, snailIndex)))); +3750 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3751 poundIndex = -1; +3752 } else { +3753 pairs.add(registry.getAt(Integer.parseInt(data.substring(prevTildeIndex + 1, snailIndex)))); +3754 pairs.add(Double.valueOf(data.substring(snailIndex + 1, tildeIndex))); +3755 } +3756 snailIndex = data.indexOf('@', snailIndex + 1); +3757 if (snailIndex > breakIndex) +3758 break; +3759 prevTildeIndex = tildeIndex; +3760 tildeIndex = Math.min(data.indexOf('~', tildeIndex + 1), breakIndex); +3761 if (tildeIndex < 0) +3762 tildeIndex = data.length(); +3763 } +3764 ArrayList<Modifier> mods = new ArrayList<>(8); +3765 if (breakIndex == tempBreak) { +3766 tildeIndex = breakIndex - 1; +3767 while ((prevTildeIndex = data.indexOf('℗', tildeIndex + 1)) >= 0) { +3768 tildeIndex = data.indexOf('℗', prevTildeIndex + 1); +3769 if (tildeIndex < 0) tildeIndex = data.length(); +3770 mods.add(Modifier.deserializeFromString(data.substring(prevTildeIndex, tildeIndex))); +3771 } +3772 } +3773 FakeLanguageGen flg = mixAll(pairs.toArray()); +3774 flg.modifiers.addAll(mods); +3775 return flg; +3776 } +3777 +3778 public static class Modifier implements Serializable { +3779 private static final long serialVersionUID = 1734863678490422371L; +3780 public final Alteration[] alterations; +3781 +3782 public Modifier() { +3783 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3784 } +3785 +3786 public Modifier(String pattern, String replacement) { +3787 alterations = new Alteration[]{new Alteration(pattern, replacement)}; +3788 } 3789 -3790 /** -3791 * For a character who always lengthens 's' and 'z' sounds not starting a word. -3792 */ -3793 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); -3794 -3795 /** -3796 * For a character who has a 20% chance to repeat a starting consonant or vowel. -3797 */ -3798 public static final Modifier STUTTER = new Modifier( -3799 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), -3800 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); -3801 -3802 /** -3803 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them -3804 * like å or ö, but not merged letters like æ and œ). -3805 */ -3806 public static final Modifier DOUBLE_VOWELS = new Modifier( -3807 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" -3808 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" -3809 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); -3810 -3811 -3812 /** -3813 * For a language that has a 50% chance to repeat a single consonant. -3814 */ -3815 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + -3816 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + -3817 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); -3818 -3819 /** -3820 * For a language that never repeats the same letter twice in a row. -3821 */ -3822 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); -3823 -3824 /** -3825 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. -3826 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j -3827 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ -3828 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. -3829 */ -3830 public static final Modifier SIMPLIFY_NORSE = replacementTable( -3831 "á", "a", -3832 "é", "e", -3833 "í", "i", -3834 "ý", "y", -3835 "ó", "o", -3836 "ú", "u", -3837 "æ", "ae", -3838 "ö", "ou", -3839 "([^aeiou])jy", "$1yai", -3840 "([^aeiou])j(?:[aeiouy]+)", "$1yo", -3841 "s([ðþ])", "st", -3842 "\\bf[ðþ]", "fr", -3843 "[ðþ]", "th"); -3844 -3845 /** -3846 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". -3847 */ -3848 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); -3849 /** -3850 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate -3851 * for fixing a word that isn't pronounceable. -3852 */ -3853 public static final Modifier GENERAL_CLEANUP = replacementTable( -3854 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", -3855 "q([ùúûüũūŭůűųu])$", "q$1e", -3856 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", -3857 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", -3858 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", -3859 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", -3860 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", -3861 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", -3862 "qq", "q"); -3863 -3864 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy -3865 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3790 public Modifier(String pattern, String replacement, double chance) { +3791 alterations = new Alteration[]{new Alteration(pattern, replacement, chance)}; +3792 } +3793 +3794 public Modifier(Alteration... alts) { +3795 alterations = (alts == null) ? new Alteration[0] : alts; +3796 } +3797 +3798 public StringBuilder modify(RNG rng, StringBuilder sb) { +3799 Matcher m; +3800 Replacer.StringBuilderBuffer tb, working = Replacer.wrap(sb); +3801 String tmp; +3802 boolean found; +3803 Alteration alt; +3804 for (int a = 0; a < alterations.length; a++) { +3805 alt = alterations[a]; +3806 tmp = working.toString(); +3807 tb = Replacer.wrap(new StringBuilder(tmp.length())); +3808 m = alt.replacer.getPattern().matcher(tmp); +3809 +3810 found = false; +3811 while (true) { +3812 if (rng.nextDouble() < alt.chance) { +3813 if (!Replacer.replaceStep(m, alt.replacer.getSubstitution(), tb)) +3814 break; +3815 found = true; +3816 } else { +3817 if (!m.find()) +3818 break; +3819 found = true; +3820 m.getGroup(MatchResult.PREFIX, tb); +3821 m.getGroup(MatchResult.MATCH, tb); +3822 m.setTarget(m, MatchResult.SUFFIX); +3823 } +3824 } +3825 if (found) { +3826 m.getGroup(MatchResult.TARGET, tb); +3827 working = tb; +3828 } +3829 } +3830 return working.toStringBuilder(); +3831 } +3832 +3833 /** +3834 * For a character who always pronounces 's', 'ss', and 'sh' as 'th'. +3835 */ +3836 public static final Modifier LISP = new Modifier("[tţťțṭ]?[sśŝşšș]+h?", "th"); +3837 +3838 /** +3839 * For a character who always lengthens 's' and 'z' sounds not starting a word. +3840 */ +3841 public static final Modifier HISS = new Modifier("(.)([sśŝşšșzźżž])+", "$1$2$2$2"); +3842 +3843 /** +3844 * For a character who has a 20% chance to repeat a starting consonant or vowel. +3845 */ +3846 public static final Modifier STUTTER = new Modifier( +3847 new Alteration("^([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2), +3848 new Alteration("^([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųαοειυаеёийъыэюяоу]+)", "$1-$1", 0.2)); +3849 +3850 /** +3851 * For a language that has a 40% chance to repeat a single Latin vowel (a, e, o, or a variant on one of them +3852 * like å or ö, but not merged letters like æ and œ). +3853 */ +3854 public static final Modifier DOUBLE_VOWELS = new Modifier( +3855 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|^)" +3856 + "([aàáâãäåāăąǻeèéêëēĕėęěòóôõöøōŏőǿ])" +3857 + "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳ]|$)", "$1$2$2$3", 0.4); +3858 +3859 +3860 /** +3861 * For a language that has a 50% chance to repeat a single consonant. +3862 */ +3863 public static final Modifier DOUBLE_CONSONANTS = new Modifier("([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу])" + +3864 "([^aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоуqwhjx])" + +3865 "([aàáâãäåæāăąǻǽeèéêëēĕėęěiìíîïĩīĭįıoòóôõöøōŏőœǿuùúûüũūŭůűųyýÿŷỳαοειυаеёийъыэюяоу]|$)", "$1$2$2$3", 0.5); 3866 3867 /** -3868 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and -3869 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the -3870 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3871 * -3872 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text -3873 * @param change a String containing characters that will replace occurrences of characters in initial -3874 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3875 */ -3876 public static Modifier charReplacementTable(String initial, String change) { -3877 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; -3878 for (int i = 0; i < alts.length; i++) { -3879 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, -3880 // which is slightly slower and has some odd escaping cases. -3881 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); -3882 } -3883 return new Modifier(alts); -3884 } -3885 -3886 /** -3887 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the -3888 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3889 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, -3890 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3891 * this example to replace the repeated section with only the first vowel. -3892 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced -3893 * first, possibly making the later key not match), or if an earlier replacement causes a later one to -3894 * become valid. -3895 * -3896 * @param map containing String keys to replace and String values to use instead; replacements happen in order -3897 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3898 */ -3899 public static Modifier replacementTable(OrderedMap<String, String> map) { -3900 if (map == null) -3901 return new Modifier(); -3902 Alteration[] alts = new Alteration[map.size()]; -3903 for (int i = 0; i < alts.length; i++) { -3904 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); -3905 } -3906 return new Modifier(alts); -3907 } -3908 -3909 /** -3910 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because -3911 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. -3912 * This overload of replacementTable allows full regex syntax for search and replacement Strings, -3913 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in -3914 * this example to replace the repeated section with only the first vowel. -3915 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced -3916 * first, possibly making the later search not match), or if an earlier replacement causes a later one to -3917 * become valid. -3918 * -3919 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order -3920 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3921 */ -3922 public static Modifier replacementTable(String... pairs) { -3923 int len; -3924 if (pairs == null || (len = pairs.length) <= 1) -3925 return new Modifier(); -3926 Alteration[] alts = new Alteration[len >> 1]; -3927 for (int i = 0; i < alts.length; i++) { -3928 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); -3929 } -3930 return new Modifier(alts); -3931 } -3932 -3933 /** -3934 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3935 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel -3936 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the -3937 * newly-inserted vowel to be likely to be present in every word of some sentences. -3938 * @param insertion the String to use as an additional vowel -3939 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less -3940 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3941 */ -3942 public static Modifier insertVowel(String insertion, double chance) -3943 { -3944 return new Modifier(anyVowelCluster, insertion, chance); -3945 } -3946 -3947 /** -3948 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3949 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had -3950 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you -3951 * want the newly-inserted consonant to be likely to be present in every word of some sentences. -3952 * @param insertion the String to use as an additional consonant -3953 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less -3954 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3955 */ -3956 public static Modifier insertConsonant(String insertion, double chance) -3957 { -3958 return new Modifier(anyConsonantCluster, insertion, chance); -3959 } -3960 -3961 /** -3962 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3963 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of -3964 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3965 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, -3966 * so this might not do anything. -3967 * @param insertion the String to use as an additional opening vowel -3968 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3969 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3970 */ -3971 public static Modifier insertOpeningVowel(String insertion, double chance) -3972 { -3973 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); -3974 } -3975 -3976 /** -3977 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -3978 * that the language already uses; insertion will replace an existing consonant at the start of a word with a -3979 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -3980 * consonant to be likely to start every word of some sentences. Not all languages can start words with -3981 * consonants, or do that very rarely, so this might not do anything. -3982 * @param insertion the String to use as an additional opening consonant -3983 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less -3984 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -3985 */ -3986 public static Modifier insertOpeningConsonant(String insertion, double chance) -3987 { -3988 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); -3989 } -3990 -3991 /** -3992 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the -3993 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of -3994 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely -3995 * to end every word of some sentences. Not all languages can end words with vowels, or do that very -3996 * rarely, so this might not do anything. -3997 * @param insertion the String to use as an additional closing vowel -3998 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less -3999 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4000 */ -4001 public static Modifier insertClosingVowel(String insertion, double chance) -4002 { -4003 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); -4004 } -4005 -4006 /** -4007 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants -4008 * that the language already uses; insertion will replace an existing consonant at the end of a word with a -4009 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted -4010 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, -4011 * or do that very rarely, so this might not do anything. -4012 * @param insertion the String to use as an additional closing consonant -4013 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less -4014 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method -4015 */ -4016 public static Modifier insertClosingConsonant(String insertion, double chance) -4017 { -4018 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); -4019 } -4020 -4021 /** -4022 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek -4023 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of -4024 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this -4025 * Modifier is a no-op. Its use is never needed any more. -4026 * @deprecated This Modifier doesn't do anything, and isn't needed. -4027 */ -4028 @Deprecated -4029 public static final Modifier SIMPLIFY_ARABIC = new Modifier( -4030 /* -4031 new Alteration("ţ", "th"), -4032 new Alteration("ĥ", "kh"), -4033 new Alteration("ħ", "khr"), -4034 new Alteration("đ", "dh"), -4035 new Alteration("ď", "dt"), -4036 new Alteration("š", "sh"), -4037 new Alteration("ş", "shw"), -4038 new Alteration("ť", "ch"), -4039 new Alteration("ż", "zh"), -4040 new Alteration("ξ", "khm"), -4041 new Alteration("δ", "gh"), -4042 new Alteration("ā", "aa"), -4043 new Alteration("ū", "uu"), -4044 new Alteration("ī", "ii")*/); -4045 -4046 @Override -4047 public boolean equals(Object o) { -4048 if (this == o) return true; -4049 if (o == null || getClass() != o.getClass()) return false; -4050 -4051 Modifier modifier = (Modifier) o; -4052 -4053 // Probably incorrect - comparing Object[] arrays with Arrays.equals -4054 return Arrays.equals(alterations, modifier.alterations); -4055 } -4056 -4057 @Override -4058 public int hashCode() { -4059 return CrossHash.Lightning.hash(alterations); -4060 } -4061 -4062 @Override -4063 public String toString() { -4064 return "Modifier{" + -4065 "alterations=" + Arrays.toString(alterations) + -4066 '}'; +3868 * For a language that never repeats the same letter twice in a row. +3869 */ +3870 public static final Modifier NO_DOUBLES = new Modifier("(.)\\1", "$1"); +3871 +3872 /** +3873 * Removes accented letters and the two non-English consonants from text generated with {@link #NORSE}. +3874 * Replaces á, é, í, ý, ó, æ, ú, and ö with a, e, i, y, o, ae, and ou. In some instances, replaces j +3875 * with y. Replaces ð and þ with th and th, except for when preceded by s (then it replaces sð or sþ +3876 * with st or st) or when the start of a word is fð or fþ, where it replaces with fr or fr. +3877 */ +3878 public static final Modifier SIMPLIFY_NORSE = replacementTable( +3879 "á", "a", +3880 "é", "e", +3881 "í", "i", +3882 "ý", "y", +3883 "ó", "o", +3884 "ú", "u", +3885 "æ", "ae", +3886 "ö", "ou", +3887 "([^aeiou])jy", "$1yai", +3888 "([^aeiou])j(?:[aeiouy]+)", "$1yo", +3889 "s([ðþ])", "st", +3890 "\\bf[ðþ]", "fr", +3891 "[ðþ]", "th"); +3892 +3893 /** +3894 * Simple changes to merge "ae" into "æ", "oe" into "œ", and any of "aé", "áe", or "áé" into "ǽ". +3895 */ +3896 public static final Modifier LIGATURES = replacementTable("ae", "æ", "oe", "œ", "[aá][eé]", "ǽ"); +3897 /** +3898 * Some changes that can be applied when sanity checks (which force re-generating a new word) aren't appropriate +3899 * for fixing a word that isn't pronounceable. +3900 */ +3901 public static final Modifier GENERAL_CLEANUP = replacementTable( +3902 "[æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy]([æǽœýÿŷỳy])", "$1", +3903 "q([ùúûüũūŭůűųu])$", "q$1e", +3904 "([ìíîïĩīĭįıi])[ìíîïĩīĭįıi]", "$1", +3905 "([æǽœìíîïĩīĭįıiùúûüũūŭůűųuýÿŷỳy])[wŵẁẃẅ]$", "$1", +3906 "([ùúûüũūŭůűųu])([òóôõöøōŏőǿo])", "$2$1", +3907 "[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]([æǽœ])", "$1", +3908 "([æǽœ])[àáâãäåāăąǻaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőǿoùúûüũūŭůűųuýÿŷỳy]", "$1", +3909 "([wŵẁẃẅ])[wŵẁẃẅ]", "$1", +3910 "qq", "q"); +3911 +3912 //àáâãäåāăąǻæǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳy +3913 //bcçćĉċčdþðďđḍfgĝğġģhĥħḥjĵȷkķlĺļľŀłḷḹmṃnñńņňŋṅṇpqrŕŗřṛṝsśŝşšșṣtţťțṭvwŵẁẃẅxyýÿŷỳzźżž +3914 +3915 /** +3916 * Creates a Modifier that will replace the nth char in initial with the nth char in change. Expects initial and +3917 * change to be the same length, but will use the lesser length if they are not equal-length. Because of the +3918 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3919 * +3920 * @param initial a String containing lower-case letters or other symbols to be swapped out of a text +3921 * @param change a String containing characters that will replace occurrences of characters in initial +3922 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3923 */ +3924 public static Modifier charReplacementTable(String initial, String change) { +3925 Alteration[] alts = new Alteration[Math.min(initial.length(), change.length())]; +3926 for (int i = 0; i < alts.length; i++) { +3927 //literal string syntax; avoids sensitive escaping issues and also doesn't need a character class, +3928 // which is slightly slower and has some odd escaping cases. +3929 alts[i] = new Alteration("\\Q" + initial.charAt(i), change.substring(i, i + 1)); +3930 } +3931 return new Modifier(alts); +3932 } +3933 +3934 /** +3935 * Creates a Modifier that will replace the nth String key in map with the nth value. Because of the +3936 * state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3937 * This overload of replacementTable allows full regex pattern strings as keys and replacement syntax, +3938 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3939 * this example to replace the repeated section with only the first vowel. +3940 * The ordering of map matters if a later key contains an earlier key (the earlier one will be replaced +3941 * first, possibly making the later key not match), or if an earlier replacement causes a later one to +3942 * become valid. +3943 * +3944 * @param map containing String keys to replace and String values to use instead; replacements happen in order +3945 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3946 */ +3947 public static Modifier replacementTable(OrderedMap<String, String> map) { +3948 if (map == null) +3949 return new Modifier(); +3950 Alteration[] alts = new Alteration[map.size()]; +3951 for (int i = 0; i < alts.length; i++) { +3952 alts[i] = new Alteration(map.keyAt(i), map.getAt(i)); +3953 } +3954 return new Modifier(alts); +3955 } +3956 +3957 /** +3958 * Creates a Modifier that will replace the (n*2)th String in pairs with the (n*2+1)th value in pairs. Because +3959 * of the state of the text at the time modifiers are run, only lower-case letters need to be searched for. +3960 * This overload of replacementTable allows full regex syntax for search and replacement Strings, +3961 * such as searching for "([aeiou])\\1+" to find repeated occurrences of the same vowel, and "$1" in +3962 * this example to replace the repeated section with only the first vowel. +3963 * The ordering of pairs matters if a later search contains an earlier search (the earlier one will be replaced +3964 * first, possibly making the later search not match), or if an earlier replacement causes a later one to +3965 * become valid. +3966 * +3967 * @param pairs array or vararg of alternating Strings to search for and Strings to replace with; replacements happen in order +3968 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3969 */ +3970 public static Modifier replacementTable(String... pairs) { +3971 int len; +3972 if (pairs == null || (len = pairs.length) <= 1) +3973 return new Modifier(); +3974 Alteration[] alts = new Alteration[len >> 1]; +3975 for (int i = 0; i < alts.length; i++) { +3976 alts[i] = new Alteration(pairs[i<< 1], pairs[i<<1|1]); +3977 } +3978 return new Modifier(alts); +3979 } +3980 +3981 /** +3982 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +3983 * language already uses; insertion will replace an existing vowel (at any point in a word that had a vowel +3984 * generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you want the +3985 * newly-inserted vowel to be likely to be present in every word of some sentences. +3986 * @param insertion the String to use as an additional vowel +3987 * @param chance the chance for a vowel cluster to be replaced with insertion; normally 0.1 or less +3988 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +3989 */ +3990 public static Modifier insertVowel(String insertion, double chance) +3991 { +3992 return new Modifier(anyVowelCluster, insertion, chance); +3993 } +3994 +3995 /** +3996 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +3997 * that the language already uses; insertion will replace an existing consonant (at any point in a word that had +3998 * a consonant generated) with a probability of {@code chance}, so chance should be low (0.1 at most) unless you +3999 * want the newly-inserted consonant to be likely to be present in every word of some sentences. +4000 * @param insertion the String to use as an additional consonant +4001 * @param chance the chance for a consonant cluster to be replaced with insertion; normally 0.1 or less +4002 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4003 */ +4004 public static Modifier insertConsonant(String insertion, double chance) +4005 { +4006 return new Modifier(anyConsonantCluster, insertion, chance); +4007 } +4008 +4009 /** +4010 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4011 * language already uses; insertion will replace an existing vowel at the start of a word with a probability of +4012 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4013 * to start every word of some sentences. Not all languages can start words with vowels, or do that very rarely, +4014 * so this might not do anything. +4015 * @param insertion the String to use as an additional opening vowel +4016 * @param chance the chance for a vowel cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4017 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4018 */ +4019 public static Modifier insertOpeningVowel(String insertion, double chance) +4020 { +4021 return new Modifier("\\b[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+", insertion, chance); +4022 } +4023 +4024 /** +4025 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4026 * that the language already uses; insertion will replace an existing consonant at the start of a word with a +4027 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4028 * consonant to be likely to start every word of some sentences. Not all languages can start words with +4029 * consonants, or do that very rarely, so this might not do anything. +4030 * @param insertion the String to use as an additional opening consonant +4031 * @param chance the chance for a consonant cluster at the start of a word to be replaced with insertion; normally 0.2 or less +4032 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4033 */ +4034 public static Modifier insertOpeningConsonant(String insertion, double chance) +4035 { +4036 return new Modifier("\\b[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+", insertion, chance); +4037 } +4038 +4039 /** +4040 * Adds the potential for the String {@code insertion} to be used as a vowel in addition to the vowels that the +4041 * language already uses; insertion will replace an existing vowel at the end of a word with a probability of +4042 * {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted vowel to be likely +4043 * to end every word of some sentences. Not all languages can end words with vowels, or do that very +4044 * rarely, so this might not do anything. +4045 * @param insertion the String to use as an additional closing vowel +4046 * @param chance the chance for a vowel cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4047 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4048 */ +4049 public static Modifier insertClosingVowel(String insertion, double chance) +4050 { +4051 return new Modifier("[àáâãäåæāăąǻǽaèéêëēĕėęěeìíîïĩīĭįıiòóôõöøōŏőœǿoùúûüũūŭůűųuýÿŷỳyαοειυаеёийоуъыэюя]+\\b", insertion, chance); +4052 } +4053 +4054 /** +4055 * Adds the potential for the String {@code insertion} to be used as a consonant in addition to the consonants +4056 * that the language already uses; insertion will replace an existing consonant at the end of a word with a +4057 * probability of {@code chance}, so chance should be low (0.2 at most) unless you want the newly-inserted +4058 * consonant to be likely to end every word of some sentences. Not all languages can end words with consonants, +4059 * or do that very rarely, so this might not do anything. +4060 * @param insertion the String to use as an additional closing consonant +4061 * @param chance the chance for a consonant cluster at the end of a word to be replaced with insertion; normally 0.2 or less +4062 * @return a Modifier that can be added to a FakeLanguageGen with its addModifiers() method +4063 */ +4064 public static Modifier insertClosingConsonant(String insertion, double chance) +4065 { +4066 return new Modifier("[bcçćĉċčdþðďđfgĝğġģhĥħjĵȷkķlĺļľŀłmnñńņňŋpqrŕŗřsśŝşšștţťțvwŵẁẃẅxyýÿŷỳzźżžṛṝḷḹḍṭṅṇṣṃḥρσζτκχνθμπψβλγφξςбвгдклпрстфхцжмнзчшщ]+\\b", insertion, chance); 4067 } 4068 -4069 public String serializeToString() { -4070 if (alterations == null || alterations.length == 0) return "\6"; -4071 StringBuilder sb = new StringBuilder(32).append('\6'); -4072 for (int i = 0; i < alterations.length; i++) -4073 sb.append(alterations[i].serializeToString()).append('\6'); -4074 return sb.toString(); -4075 } -4076 -4077 public static Modifier deserializeFromString(String data) { -4078 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; -4079 while (currIdx >= 0) { -4080 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) -4081 break; -4082 matches++; -4083 } -4084 Alteration[] alts = new Alteration[matches]; -4085 for (int i = 0; i < matches; i++) { -4086 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); -4087 } -4088 return new Modifier(alts); -4089 } -4090 } -4091 -4092 public static class Alteration implements Serializable { -4093 private static final long serialVersionUID = -2138854697837563188L; -4094 public Replacer replacer; -4095 public String replacement; -4096 public double chance; -4097 -4098 public Alteration() { -4099 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); -4100 } -4101 -4102 public Alteration(String pattern, String replacement) { -4103 this.replacement = replacement; -4104 replacer = Pattern.compile(pattern).replacer(replacement); -4105 chance = 1.0; -4106 } -4107 -4108 public Alteration(String pattern, String replacement, double chance) { -4109 this.replacement = replacement; -4110 replacer = Pattern.compile(pattern).replacer(replacement); -4111 this.chance = chance; -4112 } -4113 -4114 public Alteration(Pattern pattern, String replacement, double chance) { -4115 this.replacement = replacement; -4116 replacer = pattern.replacer(replacement); -4117 this.chance = chance; -4118 } -4119 -4120 @Override -4121 public boolean equals(Object o) { -4122 if (this == o) return true; -4123 if (o == null || getClass() != o.getClass()) return false; +4069 /** +4070 * This was used in an earlier version, which attempted to use a Romanization technique that would use Greek +4071 * letters and several accented Latin letters to try to accurately represent some of the complex orthography of +4072 * Arabic, but because FakeLanguageGen doesn't use that technique any more (it was effectively unreadable), this +4073 * Modifier is a no-op. Its use is never needed any more. +4074 * @deprecated This Modifier doesn't do anything, and isn't needed. +4075 */ +4076 @Deprecated +4077 public static final Modifier SIMPLIFY_ARABIC = new Modifier( +4078 /* +4079 new Alteration("ţ", "th"), +4080 new Alteration("ĥ", "kh"), +4081 new Alteration("ħ", "khr"), +4082 new Alteration("đ", "dh"), +4083 new Alteration("ď", "dt"), +4084 new Alteration("š", "sh"), +4085 new Alteration("ş", "shw"), +4086 new Alteration("ť", "ch"), +4087 new Alteration("ż", "zh"), +4088 new Alteration("ξ", "khm"), +4089 new Alteration("δ", "gh"), +4090 new Alteration("ā", "aa"), +4091 new Alteration("ū", "uu"), +4092 new Alteration("ī", "ii")*/); +4093 +4094 @Override +4095 public boolean equals(Object o) { +4096 if (this == o) return true; +4097 if (o == null || getClass() != o.getClass()) return false; +4098 +4099 Modifier modifier = (Modifier) o; +4100 +4101 // Probably incorrect - comparing Object[] arrays with Arrays.equals +4102 return Arrays.equals(alterations, modifier.alterations); +4103 } +4104 +4105 @Override +4106 public int hashCode() { +4107 return CrossHash.Lightning.hash(alterations); +4108 } +4109 +4110 @Override +4111 public String toString() { +4112 return "Modifier{" + +4113 "alterations=" + Arrays.toString(alterations) + +4114 '}'; +4115 } +4116 +4117 public String serializeToString() { +4118 if (alterations == null || alterations.length == 0) return "\6"; +4119 StringBuilder sb = new StringBuilder(32).append('\6'); +4120 for (int i = 0; i < alterations.length; i++) +4121 sb.append(alterations[i].serializeToString()).append('\6'); +4122 return sb.toString(); +4123 } 4124 -4125 Alteration that = (Alteration) o; -4126 -4127 if (Double.compare(that.chance, chance) != 0) return false; -4128 return replacer.equals(that.replacer); -4129 -4130 } -4131 -4132 @Override -4133 public int hashCode() { -4134 int result; -4135 long temp; -4136 result = replacer.hashCode(); -4137 temp = NumberTools.doubleToLongBits(chance); -4138 result = 31 * result + (int) (temp ^ (temp >>> 32)); -4139 return result; -4140 } -4141 -4142 @Override -4143 public String toString() { -4144 return "Alteration{" + -4145 "replacer=" + replacer + -4146 ", chance=" + chance + -4147 '}'; +4125 public static Modifier deserializeFromString(String data) { +4126 int currIdx = data.indexOf(6), altIdx = currIdx, matches = 0; +4127 while (currIdx >= 0) { +4128 if ((currIdx = data.indexOf(6, currIdx + 1)) < 0) +4129 break; +4130 matches++; +4131 } +4132 Alteration[] alts = new Alteration[matches]; +4133 for (int i = 0; i < matches; i++) { +4134 alts[i] = Alteration.deserializeFromString(data.substring(altIdx + 1, altIdx = data.indexOf(6, altIdx + 1))); +4135 } +4136 return new Modifier(alts); +4137 } +4138 } +4139 +4140 public static class Alteration implements Serializable { +4141 private static final long serialVersionUID = -2138854697837563188L; +4142 public Replacer replacer; +4143 public String replacement; +4144 public double chance; +4145 +4146 public Alteration() { +4147 this("[tţťțṭ]?[sśŝşšș]+h?", "th"); 4148 } 4149 -4150 public String serializeToString() { -4151 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; -4152 } -4153 -4154 public static Alteration deserializeFromString(String data) { -4155 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); -4156 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), -4157 data.substring(split2 + 1, split4), -4158 Double.parseDouble(data.substring(split4 + 1))); -4159 } -4160 } +4150 public Alteration(String pattern, String replacement) { +4151 this.replacement = replacement; +4152 replacer = Pattern.compile(pattern).replacer(replacement); +4153 chance = 1.0; +4154 } +4155 +4156 public Alteration(String pattern, String replacement, double chance) { +4157 this.replacement = replacement; +4158 replacer = Pattern.compile(pattern).replacer(replacement); +4159 this.chance = chance; +4160 } 4161 -4162 /** -4163 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling -4164 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. -4165 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given -4166 * at construction. The parameters to -4167 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of -4168 * the same name, and all fields in this class are public and modifiable. -4169 */ -4170 public static class SentenceForm implements Serializable -4171 { -4172 private static final long serialVersionUID = 1246527948419533147L; -4173 public StatefulRNG rng; -4174 public int minWords, maxWords, maxChars; -4175 public String[] midPunctuation, endPunctuation; -4176 public double midPunctuationFrequency; -4177 public FakeLanguageGen language; -4178 public SentenceForm() -4179 { -4180 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, -4181 new String[]{",", ",", ",", ";", ";"}, -4182 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); -4183 } -4184 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) -4185 { -4186 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, -4187 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4162 public Alteration(Pattern pattern, String replacement, double chance) { +4163 this.replacement = replacement; +4164 replacer = pattern.replacer(replacement); +4165 this.chance = chance; +4166 } +4167 +4168 @Override +4169 public boolean equals(Object o) { +4170 if (this == o) return true; +4171 if (o == null || getClass() != o.getClass()) return false; +4172 +4173 Alteration that = (Alteration) o; +4174 +4175 if (Double.compare(that.chance, chance) != 0) return false; +4176 return replacer.equals(that.replacer); +4177 +4178 } +4179 +4180 @Override +4181 public int hashCode() { +4182 int result; +4183 long temp; +4184 result = replacer.hashCode(); +4185 temp = NumberTools.doubleToLongBits(chance); +4186 result = 31 * result + (int) (temp ^ (temp >>> 32)); +4187 return result; 4188 } -4189 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4190 String[] endPunctuation, double midPunctuationFrequency) -4191 { -4192 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4193 midPunctuationFrequency, -1); -4194 } -4195 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, -4196 String[] endPunctuation, double midPunctuationFrequency, int maxChars) -4197 { -4198 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, -4199 midPunctuationFrequency, maxChars); +4189 +4190 @Override +4191 public String toString() { +4192 return "Alteration{" + +4193 "replacer=" + replacer + +4194 ", chance=" + chance + +4195 '}'; +4196 } +4197 +4198 public String serializeToString() { +4199 return replacer.getPattern().serializeToString() + '\2' + replacement + '\4' + chance; 4200 } 4201 -4202 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, -4203 String[] midPunctuation, String[] endPunctuation, -4204 double midPunctuationFrequency, int maxChars) -4205 { -4206 this.language = language; -4207 this.rng = new StatefulRNG(rng.getState()); -4208 this.minWords = minWords; -4209 this.maxWords = maxWords; -4210 this.midPunctuation = midPunctuation; -4211 this.endPunctuation = endPunctuation; -4212 this.midPunctuationFrequency = midPunctuationFrequency; -4213 this.maxChars = maxChars; -4214 } -4215 public String sentence() -4216 { -4217 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, -4218 midPunctuationFrequency, maxChars); -4219 } -4220 -4221 public String serializeToString() { -4222 return language.serializeToString() + '℘' + -4223 rng.getState() + '℘' + -4224 minWords + '℘' + -4225 maxWords + '℘' + -4226 StringKit.join("ℙ", midPunctuation) + '℘' + -4227 StringKit.join("ℙ", endPunctuation) + '℘' + -4228 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + -4229 maxChars; -4230 } -4231 public static SentenceForm deserializeFromString(String ser) -4232 { -4233 int gap = ser.indexOf('℘'); -4234 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); -4235 StatefulRNG rng = new StatefulRNG( -4236 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4237 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4238 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); -4239 String[] midPunctuation = -4240 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4241 String[] endPunctuation = -4242 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); -4243 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); -4244 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); -4245 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); -4246 } -4247 } -4248} +4202 public static Alteration deserializeFromString(String data) { +4203 int split2 = data.indexOf('\2'), split4 = data.indexOf('\4'); +4204 return new Alteration(Pattern.deserializeFromString(data.substring(0, split2)), +4205 data.substring(split2 + 1, split4), +4206 Double.parseDouble(data.substring(split4 + 1))); +4207 } +4208 } +4209 +4210 /** +4211 * A simple way to bundle a FakeLanguageGen with the arguments that would be passed to it when calling +4212 * {@link FakeLanguageGen#sentence(RNG, int, int, String[], String[], double, int)} or one of its overloads. +4213 * You can call {@link #sentence()} on this to produce another String sentence with the parameters it was given +4214 * at construction. The parameters to +4215 * {@link FakeLanguageGen.SentenceForm#SentenceForm(FakeLanguageGen, StatefulRNG, int, int, String[], String[], double, int)} are stored in fields of +4216 * the same name, and all fields in this class are public and modifiable. +4217 */ +4218 public static class SentenceForm implements Serializable +4219 { +4220 private static final long serialVersionUID = 1246527948419533147L; +4221 public StatefulRNG rng; +4222 public int minWords, maxWords, maxChars; +4223 public String[] midPunctuation, endPunctuation; +4224 public double midPunctuationFrequency; +4225 public FakeLanguageGen language; +4226 public SentenceForm() +4227 { +4228 this(FakeLanguageGen.FANTASY_NAME, FakeLanguageGen.srng, 1, 9, +4229 new String[]{",", ",", ",", ";", ";"}, +4230 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4231 } +4232 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords) +4233 { +4234 this(language, FakeLanguageGen.srng, minWords, maxWords, new String[]{",", ",", ",", ";", ";"}, +4235 new String[]{".", ".", ".", "!", "?", "..."}, 0.18, -1); +4236 } +4237 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4238 String[] endPunctuation, double midPunctuationFrequency) +4239 { +4240 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4241 midPunctuationFrequency, -1); +4242 } +4243 public SentenceForm(FakeLanguageGen language, int minWords, int maxWords, String[] midPunctuation, +4244 String[] endPunctuation, double midPunctuationFrequency, int maxChars) +4245 { +4246 this(language, FakeLanguageGen.srng, minWords, maxWords, midPunctuation, endPunctuation, +4247 midPunctuationFrequency, maxChars); +4248 } +4249 +4250 public SentenceForm(FakeLanguageGen language, StatefulRNG rng, int minWords, int maxWords, +4251 String[] midPunctuation, String[] endPunctuation, +4252 double midPunctuationFrequency, int maxChars) +4253 { +4254 this.language = language; +4255 this.rng = new StatefulRNG(rng.getState()); +4256 this.minWords = minWords; +4257 this.maxWords = maxWords; +4258 this.midPunctuation = midPunctuation; +4259 this.endPunctuation = endPunctuation; +4260 this.midPunctuationFrequency = midPunctuationFrequency; +4261 this.maxChars = maxChars; +4262 } +4263 public String sentence() +4264 { +4265 return language.sentence(rng, minWords, maxWords, midPunctuation, endPunctuation, +4266 midPunctuationFrequency, maxChars); +4267 } +4268 +4269 public String serializeToString() { +4270 return language.serializeToString() + '℘' + +4271 rng.getState() + '℘' + +4272 minWords + '℘' + +4273 maxWords + '℘' + +4274 StringKit.join("ℙ", midPunctuation) + '℘' + +4275 StringKit.join("ℙ", endPunctuation) + '℘' + +4276 NumberTools.doubleToLongBits(midPunctuationFrequency) + '℘' + +4277 maxChars; +4278 } +4279 public static SentenceForm deserializeFromString(String ser) +4280 { +4281 int gap = ser.indexOf('℘'); +4282 FakeLanguageGen lang = FakeLanguageGen.deserializeFromString(ser.substring(0, gap)); +4283 StatefulRNG rng = new StatefulRNG( +4284 StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4285 int minWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4286 int maxWords = StringKit.intFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1)); +4287 String[] midPunctuation = +4288 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4289 String[] endPunctuation = +4290 StringKit.split(ser.substring(gap + 1, gap = ser.indexOf('℘', gap + 1)), "ℙ"); +4291 double midFreq = NumberTools.longBitsToDouble(StringKit.longFromDec(ser,gap + 1, gap = ser.indexOf('℘', gap + 1))); +4292 int maxChars = StringKit.intFromDec(ser,gap + 1, ser.length()); +4293 return new SentenceForm(lang, rng, minWords, maxWords, midPunctuation, endPunctuation, midFreq, maxChars); +4294 } +4295 } +4296} diff --git a/docs/squidlib-util/src-html/squidpony/StringKit.html b/docs/squidlib-util/src-html/squidpony/StringKit.html index e6262687bd..e201afabdd 100644 --- a/docs/squidlib-util/src-html/squidpony/StringKit.html +++ b/docs/squidlib-util/src-html/squidpony/StringKit.html @@ -1403,7 +1403,7 @@ 1395 public static final String LATIN_EXTENDED_LETTERS_UPPER = 1396 "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞĀĂĄĆĈĊČĎĐĒĔĖĘĚĜĞĠĢĤĦĨĪĬĮİĴĶĹĻĽĿŁŃŅŇŊŌŎŐŒŔŖŘŚŜŞŠŢŤŨŪŬŮŰŲŴŶŸŹŻŽǺǼǾȘȚẀẂẄỲßSFJ"; 1397 public static final String LATIN_EXTENDED_LETTERS_LOWER = -1398 "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįi̇ĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťũūŭůűųŵŷÿźżžǻǽǿșțẁẃẅỳßſƒȷ"; +1398 "àáâãäåæçèéêëìíîïðñòóôõöøùúûüýþāăąćĉċčďđēĕėęěĝğġģĥħĩīĭįıĵķĺļľŀłńņňŋōŏőœŕŗřśŝşšţťũūŭůűųŵŷÿźżžǻǽǿșțẁẃẅỳßſƒȷ"; 1399 public static final String LATIN_EXTENDED_LETTERS = LATIN_EXTENDED_LETTERS_UPPER + LATIN_EXTENDED_LETTERS_LOWER; 1400 1401 public static final String LATIN_LETTERS_UPPER = ENGLISH_LETTERS_UPPER + LATIN_EXTENDED_LETTERS_UPPER; diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/CriticalRNG.html b/docs/squidlib-util/src-html/squidpony/squidmath/CriticalRNG.html new file mode 100644 index 0000000000..afb9daaa19 --- /dev/null +++ b/docs/squidlib-util/src-html/squidpony/squidmath/CriticalRNG.html @@ -0,0 +1,268 @@ + + + +Source code + + + +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  001package squidpony.squidmath;
                                                                                                                                                                                                                                                                                                                  +002
                                                                                                                                                                                                                                                                                                                  +003import java.util.*;
                                                                                                                                                                                                                                                                                                                  +004
                                                                                                                                                                                                                                                                                                                  +005/**
                                                                                                                                                                                                                                                                                                                  +006 * A type of RNG that can generate values larger or smaller than the normal maximum or minimum, based on a modifier.
                                                                                                                                                                                                                                                                                                                  +007 * You should not use this as a general-purpose substitute for {@link RNG}; it is meant for cases where there is no hard
                                                                                                                                                                                                                                                                                                                  +008 * maximum or minimum for a random value, so it is a poor fit for getting random items from collections or shuffling.
                                                                                                                                                                                                                                                                                                                  +009 * It also uses a curved distribution (almost Gaussian, but slightly more shallow), which makes its results to be most
                                                                                                                                                                                                                                                                                                                  +010 * often near the center of the range they can fall into. The {@link #luck} field affects the distribution simply, and
                                                                                                                                                                                                                                                                                                                  +011 * should generally be between -0.5f and 0.5f except in cases where a character or event routinely defies all odds.
                                                                                                                                                                                                                                                                                                                  +012 * There is no value for luck that will prevent this from sometimes producing values outside the requested range, though
                                                                                                                                                                                                                                                                                                                  +013 * at luck = 0 it is somewhat rare for the bounds to be significantly exceeded.
                                                                                                                                                                                                                                                                                                                  +014 * <br>
                                                                                                                                                                                                                                                                                                                  +015 * The name comes from "critical hit," the rare but potentially very significant strike in many role-playing games.
                                                                                                                                                                                                                                                                                                                  +016 * <br>
                                                                                                                                                                                                                                                                                                                  +017 * Created by Tommy Ettinger on 9/20/2017.
                                                                                                                                                                                                                                                                                                                  +018 */
                                                                                                                                                                                                                                                                                                                  +019public class CriticalRNG extends RNG {
                                                                                                                                                                                                                                                                                                                  +020    /**
                                                                                                                                                                                                                                                                                                                  +021     * Positive for higher results, negative for lower results; usually this is small, between -0.5f and 0.5f .
                                                                                                                                                                                                                                                                                                                  +022     */
                                                                                                                                                                                                                                                                                                                  +023    public float luck = 0f;
                                                                                                                                                                                                                                                                                                                  +024
                                                                                                                                                                                                                                                                                                                  +025    /**
                                                                                                                                                                                                                                                                                                                  +026     * Makes a CriticalRNG with a luck factor of 0 and a randomly-seeded ThrustRNG for its RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +027     */
                                                                                                                                                                                                                                                                                                                  +028    public CriticalRNG() {
                                                                                                                                                                                                                                                                                                                  +029        super(new ThrustRNG());
                                                                                                                                                                                                                                                                                                                  +030    }
                                                                                                                                                                                                                                                                                                                  +031
                                                                                                                                                                                                                                                                                                                  +032    /**
                                                                                                                                                                                                                                                                                                                  +033     * Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +034     * @param seed any long
                                                                                                                                                                                                                                                                                                                  +035     */
                                                                                                                                                                                                                                                                                                                  +036    public CriticalRNG(long seed) {
                                                                                                                                                                                                                                                                                                                  +037        super(new ThrustRNG(seed));
                                                                                                                                                                                                                                                                                                                  +038    }
                                                                                                                                                                                                                                                                                                                  +039    /**
                                                                                                                                                                                                                                                                                                                  +040     * Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource (this
                                                                                                                                                                                                                                                                                                                  +041     * will hash seedString using {@link CrossHash#hash64(CharSequence)} and use the result to seed the ThrustRNG).
                                                                                                                                                                                                                                                                                                                  +042     * @param seedString any String
                                                                                                                                                                                                                                                                                                                  +043     */
                                                                                                                                                                                                                                                                                                                  +044    public CriticalRNG(CharSequence seedString) {
                                                                                                                                                                                                                                                                                                                  +045        super(new ThrustRNG(CrossHash.hash64(seedString)));
                                                                                                                                                                                                                                                                                                                  +046    }
                                                                                                                                                                                                                                                                                                                  +047
                                                                                                                                                                                                                                                                                                                  +048    /**
                                                                                                                                                                                                                                                                                                                  +049     * Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +050     * @param random a RandomnessSource, such as a {@link LongPeriodRNG} or {@link LightRNG}
                                                                                                                                                                                                                                                                                                                  +051     */
                                                                                                                                                                                                                                                                                                                  +052    public CriticalRNG(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +053        super(random);
                                                                                                                                                                                                                                                                                                                  +054    }
                                                                                                                                                                                                                                                                                                                  +055
                                                                                                                                                                                                                                                                                                                  +056    /**
                                                                                                                                                                                                                                                                                                                  +057     * Makes a CriticalRNG with the given luck factor and a randomly-seeded ThrustRNG for its RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +058     * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns
                                                                                                                                                                                                                                                                                                                  +059     */
                                                                                                                                                                                                                                                                                                                  +060    public CriticalRNG(float luck) {
                                                                                                                                                                                                                                                                                                                  +061        super(new ThrustRNG());
                                                                                                                                                                                                                                                                                                                  +062        this.luck = luck;
                                                                                                                                                                                                                                                                                                                  +063    }
                                                                                                                                                                                                                                                                                                                  +064
                                                                                                                                                                                                                                                                                                                  +065    /**
                                                                                                                                                                                                                                                                                                                  +066     * Makes a CriticalRNG with the given luck factor and a ThrustRNG with the given seed for its RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +067     * @param seed any long
                                                                                                                                                                                                                                                                                                                  +068     * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns
                                                                                                                                                                                                                                                                                                                  +069     */
                                                                                                                                                                                                                                                                                                                  +070    public CriticalRNG(long seed, float luck) {
                                                                                                                                                                                                                                                                                                                  +071        super(new ThrustRNG(seed));
                                                                                                                                                                                                                                                                                                                  +072        this.luck = luck;
                                                                                                                                                                                                                                                                                                                  +073    }
                                                                                                                                                                                                                                                                                                                  +074
                                                                                                                                                                                                                                                                                                                  +075    /**
                                                                                                                                                                                                                                                                                                                  +076     * Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource (this
                                                                                                                                                                                                                                                                                                                  +077     * will hash seedString using {@link CrossHash#hash64(CharSequence)} and use the result to seed the ThrustRNG).
                                                                                                                                                                                                                                                                                                                  +078     * @param seedString any String
                                                                                                                                                                                                                                                                                                                  +079     * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns
                                                                                                                                                                                                                                                                                                                  +080     */
                                                                                                                                                                                                                                                                                                                  +081    public CriticalRNG(CharSequence seedString, float luck) {
                                                                                                                                                                                                                                                                                                                  +082        super(new ThrustRNG(CrossHash.hash64(seedString)));
                                                                                                                                                                                                                                                                                                                  +083        this.luck = luck;
                                                                                                                                                                                                                                                                                                                  +084    }
                                                                                                                                                                                                                                                                                                                  +085
                                                                                                                                                                                                                                                                                                                  +086    /**
                                                                                                                                                                                                                                                                                                                  +087     * Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +088     * @param random a RandomnessSource, such as a {@link LongPeriodRNG} or {@link LightRNG}
                                                                                                                                                                                                                                                                                                                  +089     * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns
                                                                                                                                                                                                                                                                                                                  +090     */
                                                                                                                                                                                                                                                                                                                  +091    public CriticalRNG(RandomnessSource random, float luck) {
                                                                                                                                                                                                                                                                                                                  +092        super(random);
                                                                                                                                                                                                                                                                                                                  +093        this.luck = luck;
                                                                                                                                                                                                                                                                                                                  +094    }
                                                                                                                                                                                                                                                                                                                  +095
                                                                                                                                                                                                                                                                                                                  +096    @Override
                                                                                                                                                                                                                                                                                                                  +097    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  +098        return NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck;
                                                                                                                                                                                                                                                                                                                  +099    }
                                                                                                                                                                                                                                                                                                                  +100
                                                                                                                                                                                                                                                                                                                  +101    @Override
                                                                                                                                                                                                                                                                                                                  +102    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  +103        return (NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * max;
                                                                                                                                                                                                                                                                                                                  +104    }
                                                                                                                                                                                                                                                                                                                  +105
                                                                                                                                                                                                                                                                                                                  +106    @Override
                                                                                                                                                                                                                                                                                                                  +107    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  +108        return NumberTools.formCurvedFloat(random.nextLong()) * 0.875f + 0.5f + luck;
                                                                                                                                                                                                                                                                                                                  +109    }
                                                                                                                                                                                                                                                                                                                  +110
                                                                                                                                                                                                                                                                                                                  +111    @Override
                                                                                                                                                                                                                                                                                                                  +112    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  +113        return NumberTools.formCurvedFloat(random.nextLong()) * 0.875f + 0.5f + luck >= 0f;
                                                                                                                                                                                                                                                                                                                  +114    }
                                                                                                                                                                                                                                                                                                                  +115
                                                                                                                                                                                                                                                                                                                  +116    private static int intify(final double t) {
                                                                                                                                                                                                                                                                                                                  +117        return t >= 0.0 ? (int) (t + 0.5) : (int) (t - 0.5);
                                                                                                                                                                                                                                                                                                                  +118    }
                                                                                                                                                                                                                                                                                                                  +119    private static long longify(final double t) {
                                                                                                                                                                                                                                                                                                                  +120        return t >= 0.0 ? (long) (t + 0.5) : (long) (t - 0.5);
                                                                                                                                                                                                                                                                                                                  +121    }
                                                                                                                                                                                                                                                                                                                  +122
                                                                                                                                                                                                                                                                                                                  +123    @Override
                                                                                                                                                                                                                                                                                                                  +124    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  +125        return longify((NumberTools.formCurvedFloat(random.nextLong()) + luck * -2.0) * 0x8000000000000000L);
                                                                                                                                                                                                                                                                                                                  +126    }
                                                                                                                                                                                                                                                                                                                  +127
                                                                                                                                                                                                                                                                                                                  +128    @Override
                                                                                                                                                                                                                                                                                                                  +129    public long nextLong(long bound) {
                                                                                                                                                                                                                                                                                                                  +130        return longify((NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * bound);
                                                                                                                                                                                                                                                                                                                  +131    }
                                                                                                                                                                                                                                                                                                                  +132
                                                                                                                                                                                                                                                                                                                  +133    @Override
                                                                                                                                                                                                                                                                                                                  +134    public int nextInt(int bound) {
                                                                                                                                                                                                                                                                                                                  +135        return intify((NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * bound);
                                                                                                                                                                                                                                                                                                                  +136    }
                                                                                                                                                                                                                                                                                                                  +137
                                                                                                                                                                                                                                                                                                                  +138    @Override
                                                                                                                                                                                                                                                                                                                  +139    public int nextIntHasty(int bound) {
                                                                                                                                                                                                                                                                                                                  +140        return intify((NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * bound);
                                                                                                                                                                                                                                                                                                                  +141    }
                                                                                                                                                                                                                                                                                                                  +142
                                                                                                                                                                                                                                                                                                                  +143    @Override
                                                                                                                                                                                                                                                                                                                  +144    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  +145        return intify((NumberTools.formCurvedFloat(random.nextLong()) + luck * -2.0) * 0x80000000);
                                                                                                                                                                                                                                                                                                                  +146    }
                                                                                                                                                                                                                                                                                                                  +147
                                                                                                                                                                                                                                                                                                                  +148    @Override
                                                                                                                                                                                                                                                                                                                  +149    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  +150        if (array.length < 1) {
                                                                                                                                                                                                                                                                                                                  +151            return null;
                                                                                                                                                                                                                                                                                                                  +152        }
                                                                                                                                                                                                                                                                                                                  +153        return array[super.nextIntHasty(array.length)];
                                                                                                                                                                                                                                                                                                                  +154    }
                                                                                                                                                                                                                                                                                                                  +155
                                                                                                                                                                                                                                                                                                                  +156    @Override
                                                                                                                                                                                                                                                                                                                  +157    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  +158        if (list.isEmpty()) {
                                                                                                                                                                                                                                                                                                                  +159            return null;
                                                                                                                                                                                                                                                                                                                  +160        }
                                                                                                                                                                                                                                                                                                                  +161        return list.get(super.nextIntHasty(list.size()));
                                                                                                                                                                                                                                                                                                                  +162    }
                                                                                                                                                                                                                                                                                                                  +163
                                                                                                                                                                                                                                                                                                                  +164    @Override
                                                                                                                                                                                                                                                                                                                  +165    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  +166        if (set.size <= 0) {
                                                                                                                                                                                                                                                                                                                  +167            throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element");
                                                                                                                                                                                                                                                                                                                  +168        }
                                                                                                                                                                                                                                                                                                                  +169        int n = super.nextIntHasty(set.size);
                                                                                                                                                                                                                                                                                                                  +170        short s = 0;
                                                                                                                                                                                                                                                                                                                  +171        ShortSet.ShortSetIterator ssi = set.iterator();
                                                                                                                                                                                                                                                                                                                  +172        while (n-- >= 0 && ssi.hasNext)
                                                                                                                                                                                                                                                                                                                  +173            s = ssi.next();
                                                                                                                                                                                                                                                                                                                  +174        ssi.reset();
                                                                                                                                                                                                                                                                                                                  +175        return s;
                                                                                                                                                                                                                                                                                                                  +176    }
                                                                                                                                                                                                                                                                                                                  +177
                                                                                                                                                                                                                                                                                                                  +178    @Override
                                                                                                                                                                                                                                                                                                                  +179    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  +180        int n;
                                                                                                                                                                                                                                                                                                                  +181        if ((n = coll.size()) <= 0) {
                                                                                                                                                                                                                                                                                                                  +182            return null;
                                                                                                                                                                                                                                                                                                                  +183        }
                                                                                                                                                                                                                                                                                                                  +184        n = super.nextIntHasty(n);
                                                                                                                                                                                                                                                                                                                  +185        T t = null;
                                                                                                                                                                                                                                                                                                                  +186        Iterator<T> it = coll.iterator();
                                                                                                                                                                                                                                                                                                                  +187        while (n-- >= 0 && it.hasNext())
                                                                                                                                                                                                                                                                                                                  +188            t = it.next();
                                                                                                                                                                                                                                                                                                                  +189        return t;
                                                                                                                                                                                                                                                                                                                  +190    }
                                                                                                                                                                                                                                                                                                                  +191
                                                                                                                                                                                                                                                                                                                  +192    @Override
                                                                                                                                                                                                                                                                                                                  +193    public double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  +194        return NumberTools.formCurvedFloat(random.nextLong()) * 1.75 + luck * 2;
                                                                                                                                                                                                                                                                                                                  +195    }
                                                                                                                                                                                                                                                                                                                  +196}
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  + + diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/DeckRNG.html b/docs/squidlib-util/src-html/squidpony/squidmath/DeckRNG.html index 8185255b0e..491e8f5be8 100644 --- a/docs/squidlib-util/src-html/squidpony/squidmath/DeckRNG.html +++ b/docs/squidlib-util/src-html/squidpony/squidmath/DeckRNG.html @@ -9,604 +9,578 @@
                                                                                                                                                                                                                                                                                                                  001package squidpony.squidmath;
                                                                                                                                                                                                                                                                                                                   002
                                                                                                                                                                                                                                                                                                                   003import squidpony.StringKit;
                                                                                                                                                                                                                                                                                                                  -004import squidpony.annotation.GwtIncompatible;
                                                                                                                                                                                                                                                                                                                  -005
                                                                                                                                                                                                                                                                                                                  -006import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  -007import java.util.*;
                                                                                                                                                                                                                                                                                                                  -008
                                                                                                                                                                                                                                                                                                                  -009/**
                                                                                                                                                                                                                                                                                                                  -010 * An RNG variant that has 16 possible grades of value it can produce and shuffles them like a deck of cards.
                                                                                                                                                                                                                                                                                                                  -011 * It repeats grades of value, but not exact values, every 16 numbers requested from it. Grades go in increments of
                                                                                                                                                                                                                                                                                                                  -012 * 0.0625 from 0.0 to 0.9375, and are added to a random double less than 0.0625 to get the random number for that
                                                                                                                                                                                                                                                                                                                  -013 * grade.
                                                                                                                                                                                                                                                                                                                  -014 * <p>
                                                                                                                                                                                                                                                                                                                  -015 * You can get values from this generator with: {@link #nextDouble()}, {@link #nextInt()},
                                                                                                                                                                                                                                                                                                                  -016 *   {@link #nextLong()}, and the bounded variants on each of those.
                                                                                                                                                                                                                                                                                                                  -017 *
                                                                                                                                                                                                                                                                                                                  -018 * Created by Tommy Ettinger on 5/2/2015.
                                                                                                                                                                                                                                                                                                                  -019 */
                                                                                                                                                                                                                                                                                                                  -020public class DeckRNG extends StatefulRNG implements Serializable {
                                                                                                                                                                                                                                                                                                                  -021        private static final long serialVersionUID = 7828346657944720807L;
                                                                                                                                                                                                                                                                                                                  -022    private int step;
                                                                                                                                                                                                                                                                                                                  -023    private long lastShuffledState;
                                                                                                                                                                                                                                                                                                                  -024    private static final double[] baseDeck = new double[]{0.0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375,
                                                                                                                                                                                                                                                                                                                  -025                                             0.5, 0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375},
                                                                                                                                                                                                                                                                                                                  -026            deck = new double[16];
                                                                                                                                                                                                                                                                                                                  -027
                                                                                                                                                                                                                                                                                                                  -028    /**
                                                                                                                                                                                                                                                                                                                  -029     * Constructs a DeckRNG with a pseudo-random seed from Math.random().
                                                                                                                                                                                                                                                                                                                  -030     */
                                                                                                                                                                                                                                                                                                                  -031    public DeckRNG()
                                                                                                                                                                                                                                                                                                                  -032    {
                                                                                                                                                                                                                                                                                                                  -033        this((long)(Math.random() * ((1L << 50) - 1)));
                                                                                                                                                                                                                                                                                                                  -034    }
                                                                                                                                                                                                                                                                                                                  -035    /**
                                                                                                                                                                                                                                                                                                                  -036     * Construct a new DeckRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -037     *
                                                                                                                                                                                                                                                                                                                  -038     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -039     */
                                                                                                                                                                                                                                                                                                                  -040    public DeckRNG(final long seed) {
                                                                                                                                                                                                                                                                                                                  -041        lastShuffledState = seed;
                                                                                                                                                                                                                                                                                                                  -042        random = new LightRNG(seed);
                                                                                                                                                                                                                                                                                                                  -043        step = 0;
                                                                                                                                                                                                                                                                                                                  -044    }
                                                                                                                                                                                                                                                                                                                  -045
                                                                                                                                                                                                                                                                                                                  -046    /**
                                                                                                                                                                                                                                                                                                                  -047     * String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low
                                                                                                                                                                                                                                                                                                                  -048     * period (which rarely matters for games), and has good speed and tiny state size.
                                                                                                                                                                                                                                                                                                                  -049     *
                                                                                                                                                                                                                                                                                                                  -050     * @param seedString a String to use as a seed; will be hashed in a uniform way across platforms.
                                                                                                                                                                                                                                                                                                                  -051     */
                                                                                                                                                                                                                                                                                                                  -052    public DeckRNG(String seedString) {
                                                                                                                                                                                                                                                                                                                  -053        this(CrossHash.hash(seedString));
                                                                                                                                                                                                                                                                                                                  -054    }
                                                                                                                                                                                                                                                                                                                  -055    /**
                                                                                                                                                                                                                                                                                                                  -056     * Seeds this DeckRNG using the RandomnessSource it is given. Does not assign the RandomnessSource to any fields
                                                                                                                                                                                                                                                                                                                  -057     * that would affect future pseudo-random number generation.
                                                                                                                                                                                                                                                                                                                  -058     * @param random will be used to generate a new seed, but will not be assigned as this object's RandomnessSource
                                                                                                                                                                                                                                                                                                                  -059     */
                                                                                                                                                                                                                                                                                                                  -060    public DeckRNG(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -061        this(random.nextLong());
                                                                                                                                                                                                                                                                                                                  -062
                                                                                                                                                                                                                                                                                                                  -063    }
                                                                                                                                                                                                                                                                                                                  -064
                                                                                                                                                                                                                                                                                                                  -065    /**
                                                                                                                                                                                                                                                                                                                  -066     * Generate a random double, altering the result if recently generated results have been leaning
                                                                                                                                                                                                                                                                                                                  -067     * away from this class' fairness value.
                                                                                                                                                                                                                                                                                                                  -068     * @return a double between 0.0 (inclusive) and 1.0 (exclusive)
                                                                                                                                                                                                                                                                                                                  -069     */
                                                                                                                                                                                                                                                                                                                  -070    @Override
                                                                                                                                                                                                                                                                                                                  -071    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  -072        if(step == 0)
                                                                                                                                                                                                                                                                                                                  -073            shuffleInPlace(deck);
                                                                                                                                                                                                                                                                                                                  -074        double gen = deck[step++];
                                                                                                                                                                                                                                                                                                                  -075        step %= 16;
                                                                                                                                                                                                                                                                                                                  -076        return gen;
                                                                                                                                                                                                                                                                                                                  -077    }
                                                                                                                                                                                                                                                                                                                  -078
                                                                                                                                                                                                                                                                                                                  -079    /**
                                                                                                                                                                                                                                                                                                                  -080     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -081     *
                                                                                                                                                                                                                                                                                                                  -082     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  -083     */
                                                                                                                                                                                                                                                                                                                  -084    @Override
                                                                                                                                                                                                                                                                                                                  -085    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  -086        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  -087    }
                                                                                                                                                                                                                                                                                                                  -088
                                                                                                                                                                                                                                                                                                                  -089    /**
                                                                                                                                                                                                                                                                                                                  -090     * Returns a value from a even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  -091     * (exclusive).
                                                                                                                                                                                                                                                                                                                  -092     *
                                                                                                                                                                                                                                                                                                                  -093     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -094     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -095     * @return the found value
                                                                                                                                                                                                                                                                                                                  -096     */
                                                                                                                                                                                                                                                                                                                  -097    @Override
                                                                                                                                                                                                                                                                                                                  -098    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  -099        return min + (max - min) * nextDouble();
                                                                                                                                                                                                                                                                                                                  -100    }
                                                                                                                                                                                                                                                                                                                  -101
                                                                                                                                                                                                                                                                                                                  -102    /**
                                                                                                                                                                                                                                                                                                                  -103     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -104     *
                                                                                                                                                                                                                                                                                                                  -105     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -106     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -107     *
                                                                                                                                                                                                                                                                                                                  -108     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -109     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -110     * @return the found value
                                                                                                                                                                                                                                                                                                                  -111     */
                                                                                                                                                                                                                                                                                                                  -112    @Override
                                                                                                                                                                                                                                                                                                                  -113    public int between(int min, int max) {
                                                                                                                                                                                                                                                                                                                  -114        return nextInt(max - min) + min;
                                                                                                                                                                                                                                                                                                                  -115    }
                                                                                                                                                                                                                                                                                                                  -116
                                                                                                                                                                                                                                                                                                                  -117    /**
                                                                                                                                                                                                                                                                                                                  -118     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  -119     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  -120     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  -121     *
                                                                                                                                                                                                                                                                                                                  -122     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -123     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -124     *
                                                                                                                                                                                                                                                                                                                  -125     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  -126     *
                                                                                                                                                                                                                                                                                                                  -127     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -128     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -129     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  -130     * @return the found value
                                                                                                                                                                                                                                                                                                                  -131     */
                                                                                                                                                                                                                                                                                                                  -132    @Override
                                                                                                                                                                                                                                                                                                                  -133    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  -134        int sum = 0;
                                                                                                                                                                                                                                                                                                                  -135        for (int i = 0; i < samples; i++) {
                                                                                                                                                                                                                                                                                                                  -136            sum += between(min, max);
                                                                                                                                                                                                                                                                                                                  -137        }
                                                                                                                                                                                                                                                                                                                  -138
                                                                                                                                                                                                                                                                                                                  -139        return Math.round((float) sum / samples);
                                                                                                                                                                                                                                                                                                                  -140    }
                                                                                                                                                                                                                                                                                                                  -141
                                                                                                                                                                                                                                                                                                                  -142    /**
                                                                                                                                                                                                                                                                                                                  -143     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  -144     * type.
                                                                                                                                                                                                                                                                                                                  -145     *
                                                                                                                                                                                                                                                                                                                  -146     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -147     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  -148     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -149     */
                                                                                                                                                                                                                                                                                                                  -150    @Override
                                                                                                                                                                                                                                                                                                                  -151    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  -152        if (array.length < 1) {
                                                                                                                                                                                                                                                                                                                  -153            return null;
                                                                                                                                                                                                                                                                                                                  -154        }
                                                                                                                                                                                                                                                                                                                  -155        return array[nextInt(array.length)];
                                                                                                                                                                                                                                                                                                                  -156    }
                                                                                                                                                                                                                                                                                                                  -157
                                                                                                                                                                                                                                                                                                                  -158    /**
                                                                                                                                                                                                                                                                                                                  -159     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  -160     * then null is returned.
                                                                                                                                                                                                                                                                                                                  -161     *
                                                                                                                                                                                                                                                                                                                  -162     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -163     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  -164     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -165     */
                                                                                                                                                                                                                                                                                                                  -166    @Override
                                                                                                                                                                                                                                                                                                                  -167    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -168        if (list.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  -169            return null;
                                                                                                                                                                                                                                                                                                                  -170        }
                                                                                                                                                                                                                                                                                                                  -171        return list.get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  -172    }
                                                                                                                                                                                                                                                                                                                  -173
                                                                                                                                                                                                                                                                                                                  -174    /**
                                                                                                                                                                                                                                                                                                                  -175     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  -176     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  -177     *
                                                                                                                                                                                                                                                                                                                  -178     * <p>
                                                                                                                                                                                                                                                                                                                  -179     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  -180     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  -181     * </p>
                                                                                                                                                                                                                                                                                                                  -182     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  -183     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -184     */
                                                                                                                                                                                                                                                                                                                  -185    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  -186        if (set.size <= 0) {
                                                                                                                                                                                                                                                                                                                  -187            throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element");
                                                                                                                                                                                                                                                                                                                  -188        }
                                                                                                                                                                                                                                                                                                                  -189        int n = nextInt(set.size);
                                                                                                                                                                                                                                                                                                                  -190        short s = 0;
                                                                                                                                                                                                                                                                                                                  -191        ShortSet.ShortSetIterator ssi = set.iterator();
                                                                                                                                                                                                                                                                                                                  -192        while (n-- >= 0 && ssi.hasNext)
                                                                                                                                                                                                                                                                                                                  -193            s = ssi.next();
                                                                                                                                                                                                                                                                                                                  -194        ssi.reset();
                                                                                                                                                                                                                                                                                                                  -195        return s;
                                                                                                                                                                                                                                                                                                                  -196    }
                                                                                                                                                                                                                                                                                                                  -197
                                                                                                                                                                                                                                                                                                                  -198    /**
                                                                                                                                                                                                                                                                                                                  -199     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  -200     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  -201     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  -202     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  -203     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  -204     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  -205     *
                                                                                                                                                                                                                                                                                                                  -206     * <p>
                                                                                                                                                                                                                                                                                                                  -207     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  -208     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  -209     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  -210     * </p>
                                                                                                                                                                                                                                                                                                                  -211     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -212     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  -213     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -214     */
                                                                                                                                                                                                                                                                                                                  -215    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  -216        if (coll.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  -217            return null;
                                                                                                                                                                                                                                                                                                                  -218        }
                                                                                                                                                                                                                                                                                                                  -219        int n = nextInt(coll.size());
                                                                                                                                                                                                                                                                                                                  -220        T t = null;
                                                                                                                                                                                                                                                                                                                  -221        Iterator<T> it = coll.iterator();
                                                                                                                                                                                                                                                                                                                  -222        while (n-- >= 0 && it.hasNext())
                                                                                                                                                                                                                                                                                                                  -223            t = it.next();
                                                                                                                                                                                                                                                                                                                  -224        return t;
                                                                                                                                                                                                                                                                                                                  -225    }
                                                                                                                                                                                                                                                                                                                  +004
                                                                                                                                                                                                                                                                                                                  +005import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  +006import java.util.*;
                                                                                                                                                                                                                                                                                                                  +007
                                                                                                                                                                                                                                                                                                                  +008/**
                                                                                                                                                                                                                                                                                                                  +009 * An RNG variant that has 16 possible grades of value it can produce and shuffles them like a deck of cards.
                                                                                                                                                                                                                                                                                                                  +010 * It repeats grades of value, but not exact values, every 16 numbers requested from it. Grades go in increments of
                                                                                                                                                                                                                                                                                                                  +011 * 0.0625 from 0.0 to 0.9375, and are added to a random double less than 0.0625 to get the random number for that
                                                                                                                                                                                                                                                                                                                  +012 * grade.
                                                                                                                                                                                                                                                                                                                  +013 * <p>
                                                                                                                                                                                                                                                                                                                  +014 * You can get values from this generator with: {@link #nextDouble()}, {@link #nextInt()},
                                                                                                                                                                                                                                                                                                                  +015 *   {@link #nextLong()}, and the bounded variants on each of those.
                                                                                                                                                                                                                                                                                                                  +016 *
                                                                                                                                                                                                                                                                                                                  +017 * Created by Tommy Ettinger on 5/2/2015.
                                                                                                                                                                                                                                                                                                                  +018 */
                                                                                                                                                                                                                                                                                                                  +019public class DeckRNG extends StatefulRNG implements Serializable {
                                                                                                                                                                                                                                                                                                                  +020        private static final long serialVersionUID = 7828346657944720807L;
                                                                                                                                                                                                                                                                                                                  +021    private int step;
                                                                                                                                                                                                                                                                                                                  +022    private long lastShuffledState;
                                                                                                                                                                                                                                                                                                                  +023    private static final double[] baseDeck = new double[]{0.0, 0.0625, 0.125, 0.1875, 0.25, 0.3125, 0.375, 0.4375,
                                                                                                                                                                                                                                                                                                                  +024                                             0.5, 0.5625, 0.625, 0.6875, 0.75, 0.8125, 0.875, 0.9375},
                                                                                                                                                                                                                                                                                                                  +025            deck = new double[16];
                                                                                                                                                                                                                                                                                                                  +026
                                                                                                                                                                                                                                                                                                                  +027    /**
                                                                                                                                                                                                                                                                                                                  +028     * Constructs a DeckRNG with a pseudo-random seed from Math.random().
                                                                                                                                                                                                                                                                                                                  +029     */
                                                                                                                                                                                                                                                                                                                  +030    public DeckRNG()
                                                                                                                                                                                                                                                                                                                  +031    {
                                                                                                                                                                                                                                                                                                                  +032        this((long)(Math.random() * ((1L << 50) - 1)));
                                                                                                                                                                                                                                                                                                                  +033    }
                                                                                                                                                                                                                                                                                                                  +034    /**
                                                                                                                                                                                                                                                                                                                  +035     * Construct a new DeckRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +036     *
                                                                                                                                                                                                                                                                                                                  +037     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +038     */
                                                                                                                                                                                                                                                                                                                  +039    public DeckRNG(final long seed) {
                                                                                                                                                                                                                                                                                                                  +040        lastShuffledState = seed;
                                                                                                                                                                                                                                                                                                                  +041        random = new LightRNG(seed);
                                                                                                                                                                                                                                                                                                                  +042        step = 0;
                                                                                                                                                                                                                                                                                                                  +043    }
                                                                                                                                                                                                                                                                                                                  +044
                                                                                                                                                                                                                                                                                                                  +045    /**
                                                                                                                                                                                                                                                                                                                  +046     * String-seeded constructor uses the hash of the String as a seed for LightRNG, which is of high quality, but low
                                                                                                                                                                                                                                                                                                                  +047     * period (which rarely matters for games), and has good speed and tiny state size.
                                                                                                                                                                                                                                                                                                                  +048     *
                                                                                                                                                                                                                                                                                                                  +049     * @param seedString a String to use as a seed; will be hashed in a uniform way across platforms.
                                                                                                                                                                                                                                                                                                                  +050     */
                                                                                                                                                                                                                                                                                                                  +051    public DeckRNG(CharSequence seedString) {
                                                                                                                                                                                                                                                                                                                  +052        this(CrossHash.hash64(seedString));
                                                                                                                                                                                                                                                                                                                  +053    }
                                                                                                                                                                                                                                                                                                                  +054    /**
                                                                                                                                                                                                                                                                                                                  +055     * Seeds this DeckRNG using the RandomnessSource it is given. Does not assign the RandomnessSource to any fields
                                                                                                                                                                                                                                                                                                                  +056     * that would affect future pseudo-random number generation.
                                                                                                                                                                                                                                                                                                                  +057     * @param random will be used to generate a new seed, but will not be assigned as this object's RandomnessSource
                                                                                                                                                                                                                                                                                                                  +058     */
                                                                                                                                                                                                                                                                                                                  +059    public DeckRNG(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +060        this(random.nextLong());
                                                                                                                                                                                                                                                                                                                  +061
                                                                                                                                                                                                                                                                                                                  +062    }
                                                                                                                                                                                                                                                                                                                  +063
                                                                                                                                                                                                                                                                                                                  +064    /**
                                                                                                                                                                                                                                                                                                                  +065     * Generate a random double, altering the result if recently generated results have been leaning
                                                                                                                                                                                                                                                                                                                  +066     * away from this class' fairness value.
                                                                                                                                                                                                                                                                                                                  +067     * @return a double between 0.0 (inclusive) and 1.0 (exclusive)
                                                                                                                                                                                                                                                                                                                  +068     */
                                                                                                                                                                                                                                                                                                                  +069    @Override
                                                                                                                                                                                                                                                                                                                  +070    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  +071        if(step == 0)
                                                                                                                                                                                                                                                                                                                  +072            shuffleInPlace(deck);
                                                                                                                                                                                                                                                                                                                  +073        double gen = deck[step++];
                                                                                                                                                                                                                                                                                                                  +074        step %= 16;
                                                                                                                                                                                                                                                                                                                  +075        return gen;
                                                                                                                                                                                                                                                                                                                  +076    }
                                                                                                                                                                                                                                                                                                                  +077
                                                                                                                                                                                                                                                                                                                  +078    /**
                                                                                                                                                                                                                                                                                                                  +079     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +080     *
                                                                                                                                                                                                                                                                                                                  +081     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  +082     */
                                                                                                                                                                                                                                                                                                                  +083    @Override
                                                                                                                                                                                                                                                                                                                  +084    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  +085        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  +086    }
                                                                                                                                                                                                                                                                                                                  +087
                                                                                                                                                                                                                                                                                                                  +088    /**
                                                                                                                                                                                                                                                                                                                  +089     * Returns a value from a even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  +090     * (exclusive).
                                                                                                                                                                                                                                                                                                                  +091     *
                                                                                                                                                                                                                                                                                                                  +092     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +093     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +094     * @return the found value
                                                                                                                                                                                                                                                                                                                  +095     */
                                                                                                                                                                                                                                                                                                                  +096    @Override
                                                                                                                                                                                                                                                                                                                  +097    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  +098        return min + (max - min) * nextDouble();
                                                                                                                                                                                                                                                                                                                  +099    }
                                                                                                                                                                                                                                                                                                                  +100
                                                                                                                                                                                                                                                                                                                  +101    /**
                                                                                                                                                                                                                                                                                                                  +102     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +103     *
                                                                                                                                                                                                                                                                                                                  +104     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +105     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +106     *
                                                                                                                                                                                                                                                                                                                  +107     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +108     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +109     * @return the found value
                                                                                                                                                                                                                                                                                                                  +110     */
                                                                                                                                                                                                                                                                                                                  +111    @Override
                                                                                                                                                                                                                                                                                                                  +112    public int between(int min, int max) {
                                                                                                                                                                                                                                                                                                                  +113        return nextInt(max - min) + min;
                                                                                                                                                                                                                                                                                                                  +114    }
                                                                                                                                                                                                                                                                                                                  +115
                                                                                                                                                                                                                                                                                                                  +116    /**
                                                                                                                                                                                                                                                                                                                  +117     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  +118     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  +119     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  +120     *
                                                                                                                                                                                                                                                                                                                  +121     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +122     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +123     *
                                                                                                                                                                                                                                                                                                                  +124     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  +125     *
                                                                                                                                                                                                                                                                                                                  +126     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +127     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +128     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  +129     * @return the found value
                                                                                                                                                                                                                                                                                                                  +130     */
                                                                                                                                                                                                                                                                                                                  +131    @Override
                                                                                                                                                                                                                                                                                                                  +132    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  +133        int sum = 0;
                                                                                                                                                                                                                                                                                                                  +134        for (int i = 0; i < samples; i++) {
                                                                                                                                                                                                                                                                                                                  +135            sum += between(min, max);
                                                                                                                                                                                                                                                                                                                  +136        }
                                                                                                                                                                                                                                                                                                                  +137
                                                                                                                                                                                                                                                                                                                  +138        return Math.round((float) sum / samples);
                                                                                                                                                                                                                                                                                                                  +139    }
                                                                                                                                                                                                                                                                                                                  +140
                                                                                                                                                                                                                                                                                                                  +141    /**
                                                                                                                                                                                                                                                                                                                  +142     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  +143     * type.
                                                                                                                                                                                                                                                                                                                  +144     *
                                                                                                                                                                                                                                                                                                                  +145     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +146     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  +147     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +148     */
                                                                                                                                                                                                                                                                                                                  +149    @Override
                                                                                                                                                                                                                                                                                                                  +150    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  +151        if (array.length < 1) {
                                                                                                                                                                                                                                                                                                                  +152            return null;
                                                                                                                                                                                                                                                                                                                  +153        }
                                                                                                                                                                                                                                                                                                                  +154        return array[nextInt(array.length)];
                                                                                                                                                                                                                                                                                                                  +155    }
                                                                                                                                                                                                                                                                                                                  +156
                                                                                                                                                                                                                                                                                                                  +157    /**
                                                                                                                                                                                                                                                                                                                  +158     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  +159     * then null is returned.
                                                                                                                                                                                                                                                                                                                  +160     *
                                                                                                                                                                                                                                                                                                                  +161     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +162     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  +163     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +164     */
                                                                                                                                                                                                                                                                                                                  +165    @Override
                                                                                                                                                                                                                                                                                                                  +166    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  +167        if (list.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  +168            return null;
                                                                                                                                                                                                                                                                                                                  +169        }
                                                                                                                                                                                                                                                                                                                  +170        return list.get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  +171    }
                                                                                                                                                                                                                                                                                                                  +172
                                                                                                                                                                                                                                                                                                                  +173    /**
                                                                                                                                                                                                                                                                                                                  +174     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  +175     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  +176     *
                                                                                                                                                                                                                                                                                                                  +177     * <p>
                                                                                                                                                                                                                                                                                                                  +178     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  +179     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  +180     * </p>
                                                                                                                                                                                                                                                                                                                  +181     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  +182     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +183     */
                                                                                                                                                                                                                                                                                                                  +184    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  +185        if (set.size <= 0) {
                                                                                                                                                                                                                                                                                                                  +186            throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element");
                                                                                                                                                                                                                                                                                                                  +187        }
                                                                                                                                                                                                                                                                                                                  +188        int n = nextInt(set.size);
                                                                                                                                                                                                                                                                                                                  +189        short s = 0;
                                                                                                                                                                                                                                                                                                                  +190        ShortSet.ShortSetIterator ssi = set.iterator();
                                                                                                                                                                                                                                                                                                                  +191        while (n-- >= 0 && ssi.hasNext)
                                                                                                                                                                                                                                                                                                                  +192            s = ssi.next();
                                                                                                                                                                                                                                                                                                                  +193        ssi.reset();
                                                                                                                                                                                                                                                                                                                  +194        return s;
                                                                                                                                                                                                                                                                                                                  +195    }
                                                                                                                                                                                                                                                                                                                  +196
                                                                                                                                                                                                                                                                                                                  +197    /**
                                                                                                                                                                                                                                                                                                                  +198     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  +199     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  +200     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  +201     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  +202     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  +203     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  +204     *
                                                                                                                                                                                                                                                                                                                  +205     * <p>
                                                                                                                                                                                                                                                                                                                  +206     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  +207     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  +208     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  +209     * </p>
                                                                                                                                                                                                                                                                                                                  +210     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +211     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  +212     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +213     */
                                                                                                                                                                                                                                                                                                                  +214    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  +215        if (coll.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  +216            return null;
                                                                                                                                                                                                                                                                                                                  +217        }
                                                                                                                                                                                                                                                                                                                  +218        int n = nextInt(coll.size());
                                                                                                                                                                                                                                                                                                                  +219        T t = null;
                                                                                                                                                                                                                                                                                                                  +220        Iterator<T> it = coll.iterator();
                                                                                                                                                                                                                                                                                                                  +221        while (n-- >= 0 && it.hasNext())
                                                                                                                                                                                                                                                                                                                  +222            t = it.next();
                                                                                                                                                                                                                                                                                                                  +223        return t;
                                                                                                                                                                                                                                                                                                                  +224    }
                                                                                                                                                                                                                                                                                                                  +225
                                                                                                                                                                                                                                                                                                                   226
                                                                                                                                                                                                                                                                                                                  -227
                                                                                                                                                                                                                                                                                                                  -228    /**
                                                                                                                                                                                                                                                                                                                  -229     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  -230     */
                                                                                                                                                                                                                                                                                                                  -231    @Override
                                                                                                                                                                                                                                                                                                                  -232    public synchronized double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  -233        if (haveNextNextGaussian) {
                                                                                                                                                                                                                                                                                                                  -234            haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  -235            return nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  -236        } else {
                                                                                                                                                                                                                                                                                                                  -237            double v1, v2, s;
                                                                                                                                                                                                                                                                                                                  -238            do {
                                                                                                                                                                                                                                                                                                                  -239                v1 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  -240                v2 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  -241                s = v1 * v1 + v2 * v2;
                                                                                                                                                                                                                                                                                                                  -242            } while (s >= 1 || s == 0);
                                                                                                                                                                                                                                                                                                                  -243            double multiplier = Math.sqrt(-2 * Math.log(s) / s);
                                                                                                                                                                                                                                                                                                                  -244            nextNextGaussian = v2 * multiplier;
                                                                                                                                                                                                                                                                                                                  -245            haveNextNextGaussian = true;
                                                                                                                                                                                                                                                                                                                  -246            return v1 * multiplier;
                                                                                                                                                                                                                                                                                                                  -247        }
                                                                                                                                                                                                                                                                                                                  -248    }
                                                                                                                                                                                                                                                                                                                  -249    /**
                                                                                                                                                                                                                                                                                                                  -250     * Returns a random integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -251     * negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  -252     *
                                                                                                                                                                                                                                                                                                                  -253     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -254     * @return the found number
                                                                                                                                                                                                                                                                                                                  -255     */
                                                                                                                                                                                                                                                                                                                  -256    @Override
                                                                                                                                                                                                                                                                                                                  -257    public int nextInt(int bound) {
                                                                                                                                                                                                                                                                                                                  -258        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  -259            return 0;
                                                                                                                                                                                                                                                                                                                  -260        }
                                                                                                                                                                                                                                                                                                                  -261
                                                                                                                                                                                                                                                                                                                  -262        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -263    }
                                                                                                                                                                                                                                                                                                                  -264
                                                                                                                                                                                                                                                                                                                  -265    /**
                                                                                                                                                                                                                                                                                                                  -266     * Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays.
                                                                                                                                                                                                                                                                                                                  -267     * <br>
                                                                                                                                                                                                                                                                                                                  -268     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -269     *
                                                                                                                                                                                                                                                                                                                  -270     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -271     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  -272     */
                                                                                                                                                                                                                                                                                                                  -273    @Override
                                                                                                                                                                                                                                                                                                                  -274    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -275    public <T> T[] shuffle(T[] elements)
                                                                                                                                                                                                                                                                                                                  -276    {
                                                                                                                                                                                                                                                                                                                  -277        int n = elements.length;
                                                                                                                                                                                                                                                                                                                  -278        T[] array = Arrays.copyOf(elements, n);
                                                                                                                                                                                                                                                                                                                  -279        for (int i = 0; i < n; i++)
                                                                                                                                                                                                                                                                                                                  -280        {
                                                                                                                                                                                                                                                                                                                  -281            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  -282            T t = array[r];
                                                                                                                                                                                                                                                                                                                  -283            array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  -284            array[i] = t;
                                                                                                                                                                                                                                                                                                                  -285        }
                                                                                                                                                                                                                                                                                                                  -286        return array;
                                                                                                                                                                                                                                                                                                                  -287    }
                                                                                                                                                                                                                                                                                                                  -288
                                                                                                                                                                                                                                                                                                                  -289
                                                                                                                                                                                                                                                                                                                  -290    /**
                                                                                                                                                                                                                                                                                                                  -291     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  -292     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  -293     *
                                                                                                                                                                                                                                                                                                                  -294     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  -295     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  -296     */
                                                                                                                                                                                                                                                                                                                  -297    @Override
                                                                                                                                                                                                                                                                                                                  -298    public int[] randomOrdering(int length)
                                                                                                                                                                                                                                                                                                                  -299    {
                                                                                                                                                                                                                                                                                                                  -300        int[] dest = new int[length];
                                                                                                                                                                                                                                                                                                                  -301        for (int i = 0; i < length; i++)
                                                                                                                                                                                                                                                                                                                  -302        {
                                                                                                                                                                                                                                                                                                                  -303            int r = nextIntHasty(i + 1);
                                                                                                                                                                                                                                                                                                                  -304            if(r != i)
                                                                                                                                                                                                                                                                                                                  -305                dest[i] = dest[r];
                                                                                                                                                                                                                                                                                                                  -306            dest[r] = i;
                                                                                                                                                                                                                                                                                                                  -307        }
                                                                                                                                                                                                                                                                                                                  -308        return dest;
                                                                                                                                                                                                                                                                                                                  -309    }
                                                                                                                                                                                                                                                                                                                  -310
                                                                                                                                                                                                                                                                                                                  -311    /**
                                                                                                                                                                                                                                                                                                                  -312     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  -313     * Uses a slightly optimized technique. This method is considered "hasty" since
                                                                                                                                                                                                                                                                                                                  -314     * it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also
                                                                                                                                                                                                                                                                                                                  -315     * has undefined behavior if bound is negative, though it will probably produce a negative
                                                                                                                                                                                                                                                                                                                  -316     * number (just how negative is an open question).
                                                                                                                                                                                                                                                                                                                  -317     *
                                                                                                                                                                                                                                                                                                                  -318     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  -319     * @return the found number
                                                                                                                                                                                                                                                                                                                  -320     */
                                                                                                                                                                                                                                                                                                                  -321    @Override
                                                                                                                                                                                                                                                                                                                  -322    public int nextIntHasty(int bound) {
                                                                                                                                                                                                                                                                                                                  -323        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -324    }
                                                                                                                                                                                                                                                                                                                  -325
                                                                                                                                                                                                                                                                                                                  -326    /**
                                                                                                                                                                                                                                                                                                                  -327     * Returns a random integer, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  -328     * @return A random int
                                                                                                                                                                                                                                                                                                                  -329     */
                                                                                                                                                                                                                                                                                                                  -330    @Override
                                                                                                                                                                                                                                                                                                                  -331    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  -332        return (int)((nextDouble() * 2.0 - 1.0) * 0x7FFFFFFF);
                                                                                                                                                                                                                                                                                                                  -333    }
                                                                                                                                                                                                                                                                                                                  -334
                                                                                                                                                                                                                                                                                                                  -335    /**
                                                                                                                                                                                                                                                                                                                  -336     * Returns a random long, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  -337     * @return A random long
                                                                                                                                                                                                                                                                                                                  -338     */
                                                                                                                                                                                                                                                                                                                  -339    @Override
                                                                                                                                                                                                                                                                                                                  -340    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  -341        double nx = nextDouble();
                                                                                                                                                                                                                                                                                                                  -342        return (long)((nx * 2.0 - 1.0) * 0x7FFFFFFFFFFFFFFFL);
                                                                                                                                                                                                                                                                                                                  -343    }
                                                                                                                                                                                                                                                                                                                  -344
                                                                                                                                                                                                                                                                                                                  -345    /**
                                                                                                                                                                                                                                                                                                                  -346     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -347     * negative.
                                                                                                                                                                                                                                                                                                                  -348     *
                                                                                                                                                                                                                                                                                                                  -349     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -350     * @return the found number
                                                                                                                                                                                                                                                                                                                  -351     */
                                                                                                                                                                                                                                                                                                                  -352    @Override
                                                                                                                                                                                                                                                                                                                  -353        public long nextLong(long bound) {
                                                                                                                                                                                                                                                                                                                  -354        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  -355            return 0;
                                                                                                                                                                                                                                                                                                                  -356        }
                                                                                                                                                                                                                                                                                                                  -357        double nx = nextDouble();
                                                                                                                                                                                                                                                                                                                  -358        return (long)(nx * bound);
                                                                                                                                                                                                                                                                                                                  -359        //return ((long)(nx * bound)) ^ (long)((nx * 0xFFFFFL) % bound) ^ (long)((nx * 0xFFFFF00000L) % bound);
                                                                                                                                                                                                                                                                                                                  -360    }
                                                                                                                                                                                                                                                                                                                  -361    /**
                                                                                                                                                                                                                                                                                                                  -362     *
                                                                                                                                                                                                                                                                                                                  -363     * @param bits the number of bits to be returned
                                                                                                                                                                                                                                                                                                                  -364     * @return a random int of the number of bits specified.
                                                                                                                                                                                                                                                                                                                  -365     */
                                                                                                                                                                                                                                                                                                                  -366    @Override
                                                                                                                                                                                                                                                                                                                  -367    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  -368        if(bits <= 0)
                                                                                                                                                                                                                                                                                                                  -369            return 0;
                                                                                                                                                                                                                                                                                                                  -370        if(bits > 32)
                                                                                                                                                                                                                                                                                                                  -371            bits = 32;
                                                                                                                                                                                                                                                                                                                  -372        return (int)(nextDouble() * (1L << bits));
                                                                                                                                                                                                                                                                                                                  +227    /**
                                                                                                                                                                                                                                                                                                                  +228     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  +229     */
                                                                                                                                                                                                                                                                                                                  +230    @Override
                                                                                                                                                                                                                                                                                                                  +231    public synchronized double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  +232        if (haveNextNextGaussian) {
                                                                                                                                                                                                                                                                                                                  +233            haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  +234            return nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  +235        } else {
                                                                                                                                                                                                                                                                                                                  +236            double v1, v2, s;
                                                                                                                                                                                                                                                                                                                  +237            do {
                                                                                                                                                                                                                                                                                                                  +238                v1 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  +239                v2 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  +240                s = v1 * v1 + v2 * v2;
                                                                                                                                                                                                                                                                                                                  +241            } while (s >= 1 || s == 0);
                                                                                                                                                                                                                                                                                                                  +242            double multiplier = Math.sqrt(-2 * Math.log(s) / s);
                                                                                                                                                                                                                                                                                                                  +243            nextNextGaussian = v2 * multiplier;
                                                                                                                                                                                                                                                                                                                  +244            haveNextNextGaussian = true;
                                                                                                                                                                                                                                                                                                                  +245            return v1 * multiplier;
                                                                                                                                                                                                                                                                                                                  +246        }
                                                                                                                                                                                                                                                                                                                  +247    }
                                                                                                                                                                                                                                                                                                                  +248    /**
                                                                                                                                                                                                                                                                                                                  +249     * Returns a random integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +250     * negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  +251     *
                                                                                                                                                                                                                                                                                                                  +252     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +253     * @return the found number
                                                                                                                                                                                                                                                                                                                  +254     */
                                                                                                                                                                                                                                                                                                                  +255    @Override
                                                                                                                                                                                                                                                                                                                  +256    public int nextInt(int bound) {
                                                                                                                                                                                                                                                                                                                  +257        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  +258            return 0;
                                                                                                                                                                                                                                                                                                                  +259        }
                                                                                                                                                                                                                                                                                                                  +260
                                                                                                                                                                                                                                                                                                                  +261        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +262    }
                                                                                                                                                                                                                                                                                                                  +263
                                                                                                                                                                                                                                                                                                                  +264    /**
                                                                                                                                                                                                                                                                                                                  +265     * Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays.
                                                                                                                                                                                                                                                                                                                  +266     * <br>
                                                                                                                                                                                                                                                                                                                  +267     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  +268     *
                                                                                                                                                                                                                                                                                                                  +269     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +270     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  +271     */
                                                                                                                                                                                                                                                                                                                  +272    @Override
                                                                                                                                                                                                                                                                                                                  +273    public <T> T[] shuffle(T[] elements)
                                                                                                                                                                                                                                                                                                                  +274    {
                                                                                                                                                                                                                                                                                                                  +275        int n = elements.length;
                                                                                                                                                                                                                                                                                                                  +276        T[] array = Arrays.copyOf(elements, n);
                                                                                                                                                                                                                                                                                                                  +277        for (int i = 0; i < n; i++)
                                                                                                                                                                                                                                                                                                                  +278        {
                                                                                                                                                                                                                                                                                                                  +279            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  +280            T t = array[r];
                                                                                                                                                                                                                                                                                                                  +281            array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  +282            array[i] = t;
                                                                                                                                                                                                                                                                                                                  +283        }
                                                                                                                                                                                                                                                                                                                  +284        return array;
                                                                                                                                                                                                                                                                                                                  +285    }
                                                                                                                                                                                                                                                                                                                  +286
                                                                                                                                                                                                                                                                                                                  +287
                                                                                                                                                                                                                                                                                                                  +288    /**
                                                                                                                                                                                                                                                                                                                  +289     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  +290     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  +291     *
                                                                                                                                                                                                                                                                                                                  +292     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  +293     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  +294     */
                                                                                                                                                                                                                                                                                                                  +295    @Override
                                                                                                                                                                                                                                                                                                                  +296    public int[] randomOrdering(int length)
                                                                                                                                                                                                                                                                                                                  +297    {
                                                                                                                                                                                                                                                                                                                  +298        int[] dest = new int[length];
                                                                                                                                                                                                                                                                                                                  +299        for (int i = 0; i < length; i++)
                                                                                                                                                                                                                                                                                                                  +300        {
                                                                                                                                                                                                                                                                                                                  +301            int r = nextIntHasty(i + 1);
                                                                                                                                                                                                                                                                                                                  +302            if(r != i)
                                                                                                                                                                                                                                                                                                                  +303                dest[i] = dest[r];
                                                                                                                                                                                                                                                                                                                  +304            dest[r] = i;
                                                                                                                                                                                                                                                                                                                  +305        }
                                                                                                                                                                                                                                                                                                                  +306        return dest;
                                                                                                                                                                                                                                                                                                                  +307    }
                                                                                                                                                                                                                                                                                                                  +308
                                                                                                                                                                                                                                                                                                                  +309    /**
                                                                                                                                                                                                                                                                                                                  +310     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  +311     * Uses a slightly optimized technique. This method is considered "hasty" since
                                                                                                                                                                                                                                                                                                                  +312     * it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also
                                                                                                                                                                                                                                                                                                                  +313     * has undefined behavior if bound is negative, though it will probably produce a negative
                                                                                                                                                                                                                                                                                                                  +314     * number (just how negative is an open question).
                                                                                                                                                                                                                                                                                                                  +315     *
                                                                                                                                                                                                                                                                                                                  +316     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  +317     * @return the found number
                                                                                                                                                                                                                                                                                                                  +318     */
                                                                                                                                                                                                                                                                                                                  +319    @Override
                                                                                                                                                                                                                                                                                                                  +320    public int nextIntHasty(int bound) {
                                                                                                                                                                                                                                                                                                                  +321        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +322    }
                                                                                                                                                                                                                                                                                                                  +323
                                                                                                                                                                                                                                                                                                                  +324    /**
                                                                                                                                                                                                                                                                                                                  +325     * Returns a random integer, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  +326     * @return A random int
                                                                                                                                                                                                                                                                                                                  +327     */
                                                                                                                                                                                                                                                                                                                  +328    @Override
                                                                                                                                                                                                                                                                                                                  +329    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  +330        return (int)((nextDouble() * 2.0 - 1.0) * 0x7FFFFFFF);
                                                                                                                                                                                                                                                                                                                  +331    }
                                                                                                                                                                                                                                                                                                                  +332
                                                                                                                                                                                                                                                                                                                  +333    /**
                                                                                                                                                                                                                                                                                                                  +334     * Returns a random long, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  +335     * @return A random long
                                                                                                                                                                                                                                                                                                                  +336     */
                                                                                                                                                                                                                                                                                                                  +337    @Override
                                                                                                                                                                                                                                                                                                                  +338    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  +339        double nx = nextDouble();
                                                                                                                                                                                                                                                                                                                  +340        return (long)((nx * 2.0 - 1.0) * 0x7FFFFFFFFFFFFFFFL);
                                                                                                                                                                                                                                                                                                                  +341    }
                                                                                                                                                                                                                                                                                                                  +342
                                                                                                                                                                                                                                                                                                                  +343    /**
                                                                                                                                                                                                                                                                                                                  +344     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +345     * negative.
                                                                                                                                                                                                                                                                                                                  +346     *
                                                                                                                                                                                                                                                                                                                  +347     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +348     * @return the found number
                                                                                                                                                                                                                                                                                                                  +349     */
                                                                                                                                                                                                                                                                                                                  +350    @Override
                                                                                                                                                                                                                                                                                                                  +351        public long nextLong(long bound) {
                                                                                                                                                                                                                                                                                                                  +352        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  +353            return 0;
                                                                                                                                                                                                                                                                                                                  +354        }
                                                                                                                                                                                                                                                                                                                  +355        double nx = nextDouble();
                                                                                                                                                                                                                                                                                                                  +356        return (long)(nx * bound);
                                                                                                                                                                                                                                                                                                                  +357        //return ((long)(nx * bound)) ^ (long)((nx * 0xFFFFFL) % bound) ^ (long)((nx * 0xFFFFF00000L) % bound);
                                                                                                                                                                                                                                                                                                                  +358    }
                                                                                                                                                                                                                                                                                                                  +359    /**
                                                                                                                                                                                                                                                                                                                  +360     *
                                                                                                                                                                                                                                                                                                                  +361     * @param bits the number of bits to be returned
                                                                                                                                                                                                                                                                                                                  +362     * @return a random int of the number of bits specified.
                                                                                                                                                                                                                                                                                                                  +363     */
                                                                                                                                                                                                                                                                                                                  +364    @Override
                                                                                                                                                                                                                                                                                                                  +365    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  +366        if(bits <= 0)
                                                                                                                                                                                                                                                                                                                  +367            return 0;
                                                                                                                                                                                                                                                                                                                  +368        if(bits > 32)
                                                                                                                                                                                                                                                                                                                  +369            bits = 32;
                                                                                                                                                                                                                                                                                                                  +370        return (int)(nextDouble() * (1L << bits));
                                                                                                                                                                                                                                                                                                                  +371
                                                                                                                                                                                                                                                                                                                  +372    }
                                                                                                                                                                                                                                                                                                                   373
                                                                                                                                                                                                                                                                                                                  -374    }
                                                                                                                                                                                                                                                                                                                  -375
                                                                                                                                                                                                                                                                                                                  -376    @Override
                                                                                                                                                                                                                                                                                                                  -377    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  -378        if(ran == null)
                                                                                                                                                                                                                                                                                                                  -379        {
                                                                                                                                                                                                                                                                                                                  -380            ran = new CustomRandom(new LightRNG(getState()));
                                                                                                                                                                                                                                                                                                                  -381        }
                                                                                                                                                                                                                                                                                                                  -382        return ran;
                                                                                                                                                                                                                                                                                                                  -383    }
                                                                                                                                                                                                                                                                                                                  -384
                                                                                                                                                                                                                                                                                                                  -385    @Override
                                                                                                                                                                                                                                                                                                                  -386    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -387    public <T> List<T> randomRotation(List<T> l) {
                                                                                                                                                                                                                                                                                                                  -388        return super.randomRotation(l);
                                                                                                                                                                                                                                                                                                                  -389    }
                                                                                                                                                                                                                                                                                                                  -390
                                                                                                                                                                                                                                                                                                                  -391    @Override
                                                                                                                                                                                                                                                                                                                  -392    public <T> Iterable<T> getRandomStartIterable(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -393        return super.getRandomStartIterable(list);
                                                                                                                                                                                                                                                                                                                  -394    }
                                                                                                                                                                                                                                                                                                                  -395
                                                                                                                                                                                                                                                                                                                  -396
                                                                                                                                                                                                                                                                                                                  -397    /**
                                                                                                                                                                                                                                                                                                                  -398     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -399     * <p/>
                                                                                                                                                                                                                                                                                                                  -400     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -401     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -402     *
                                                                                                                                                                                                                                                                                                                  -403     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -404     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -405     * @return the found value
                                                                                                                                                                                                                                                                                                                  -406     */
                                                                                                                                                                                                                                                                                                                  -407    @Override
                                                                                                                                                                                                                                                                                                                  -408    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  -409        return nextLong(max - min) + min;
                                                                                                                                                                                                                                                                                                                  -410    }
                                                                                                                                                                                                                                                                                                                  -411
                                                                                                                                                                                                                                                                                                                  -412    /*
                                                                                                                                                                                                                                                                                                                  -413     * Shuffle an array using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  -414     *
                                                                                                                                                                                                                                                                                                                  -415     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -416     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  -417     * /
                                                                                                                                                                                                                                                                                                                  -418    @Override
                                                                                                                                                                                                                                                                                                                  -419    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -420    public <T> T[] shuffle(T[] elements) {
                                                                                                                                                                                                                                                                                                                  -421        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  -422    }
                                                                                                                                                                                                                                                                                                                  -423*/
                                                                                                                                                                                                                                                                                                                  -424    /**
                                                                                                                                                                                                                                                                                                                  -425     * Shuffle an array using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  -426     *
                                                                                                                                                                                                                                                                                                                  -427     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -428     * @param dest     Where to put the shuffle. It MUST have the same length as {@code elements}
                                                                                                                                                                                                                                                                                                                  -429     * @return {@code dest}
                                                                                                                                                                                                                                                                                                                  -430     * @throws IllegalStateException If {@code dest.length != elements.length}
                                                                                                                                                                                                                                                                                                                  -431     */
                                                                                                                                                                                                                                                                                                                  -432    @Override
                                                                                                                                                                                                                                                                                                                  -433    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  -434        return super.shuffle(elements, dest);
                                                                                                                                                                                                                                                                                                                  -435    }
                                                                                                                                                                                                                                                                                                                  -436
                                                                                                                                                                                                                                                                                                                  -437    @Override
                                                                                                                                                                                                                                                                                                                  -438    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  -439        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  +374    @Override
                                                                                                                                                                                                                                                                                                                  +375    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  +376        if(ran == null)
                                                                                                                                                                                                                                                                                                                  +377        {
                                                                                                                                                                                                                                                                                                                  +378            ran = new CustomRandom(new LightRNG(getState()));
                                                                                                                                                                                                                                                                                                                  +379        }
                                                                                                                                                                                                                                                                                                                  +380        return ran;
                                                                                                                                                                                                                                                                                                                  +381    }
                                                                                                                                                                                                                                                                                                                  +382
                                                                                                                                                                                                                                                                                                                  +383    /**
                                                                                                                                                                                                                                                                                                                  +384     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +385     * <p/>
                                                                                                                                                                                                                                                                                                                  +386     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +387     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +388     *
                                                                                                                                                                                                                                                                                                                  +389     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +390     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +391     * @return the found value
                                                                                                                                                                                                                                                                                                                  +392     */
                                                                                                                                                                                                                                                                                                                  +393    @Override
                                                                                                                                                                                                                                                                                                                  +394    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  +395        return nextLong(max - min) + min;
                                                                                                                                                                                                                                                                                                                  +396    }
                                                                                                                                                                                                                                                                                                                  +397
                                                                                                                                                                                                                                                                                                                  +398    /**
                                                                                                                                                                                                                                                                                                                  +399     * Shuffle an array using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  +400     *
                                                                                                                                                                                                                                                                                                                  +401     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +402     * @param dest     Where to put the shuffle. It MUST have the same length as {@code elements}
                                                                                                                                                                                                                                                                                                                  +403     * @return {@code dest}
                                                                                                                                                                                                                                                                                                                  +404     * @throws IllegalStateException If {@code dest.length != elements.length}
                                                                                                                                                                                                                                                                                                                  +405     */
                                                                                                                                                                                                                                                                                                                  +406    @Override
                                                                                                                                                                                                                                                                                                                  +407    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  +408        return super.shuffle(elements, dest);
                                                                                                                                                                                                                                                                                                                  +409    }
                                                                                                                                                                                                                                                                                                                  +410
                                                                                                                                                                                                                                                                                                                  +411    @Override
                                                                                                                                                                                                                                                                                                                  +412    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  +413        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  +414    }
                                                                                                                                                                                                                                                                                                                  +415
                                                                                                                                                                                                                                                                                                                  +416    @Override
                                                                                                                                                                                                                                                                                                                  +417    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  +418        return (float)nextDouble();
                                                                                                                                                                                                                                                                                                                  +419    }
                                                                                                                                                                                                                                                                                                                  +420
                                                                                                                                                                                                                                                                                                                  +421    @Override
                                                                                                                                                                                                                                                                                                                  +422    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  +423        return nextDouble() >= 0.5;
                                                                                                                                                                                                                                                                                                                  +424    }
                                                                                                                                                                                                                                                                                                                  +425
                                                                                                                                                                                                                                                                                                                  +426    @Override
                                                                                                                                                                                                                                                                                                                  +427    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  +428        return random;
                                                                                                                                                                                                                                                                                                                  +429    }
                                                                                                                                                                                                                                                                                                                  +430
                                                                                                                                                                                                                                                                                                                  +431    /**
                                                                                                                                                                                                                                                                                                                  +432     * Reseeds this DeckRNG using the RandomnessSource it is given. Does not assign the RandomnessSource to any fields
                                                                                                                                                                                                                                                                                                                  +433     * that would affect future pseudo-random number generation.
                                                                                                                                                                                                                                                                                                                  +434     * @param random will be used to generate a new seed, but will not be assigned as this object's RandomnessSource
                                                                                                                                                                                                                                                                                                                  +435     */
                                                                                                                                                                                                                                                                                                                  +436    @Override
                                                                                                                                                                                                                                                                                                                  +437    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +438        setState(((long)random.next(32) << 32) | random.next(32));
                                                                                                                                                                                                                                                                                                                  +439
                                                                                                                                                                                                                                                                                                                   440    }
                                                                                                                                                                                                                                                                                                                   441
                                                                                                                                                                                                                                                                                                                  -442    @Override
                                                                                                                                                                                                                                                                                                                  -443    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  -444        return (float)nextDouble();
                                                                                                                                                                                                                                                                                                                  -445    }
                                                                                                                                                                                                                                                                                                                  -446
                                                                                                                                                                                                                                                                                                                  -447    @Override
                                                                                                                                                                                                                                                                                                                  -448    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  -449        return nextDouble() >= 0.5;
                                                                                                                                                                                                                                                                                                                  -450    }
                                                                                                                                                                                                                                                                                                                  -451
                                                                                                                                                                                                                                                                                                                  -452    @Override
                                                                                                                                                                                                                                                                                                                  -453    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  -454        return random;
                                                                                                                                                                                                                                                                                                                  +442    /**
                                                                                                                                                                                                                                                                                                                  +443     * Creates a copy of this DeckRNG; it will generate the same random numbers, given the same calls in order, as
                                                                                                                                                                                                                                                                                                                  +444     * this DeckRNG at the point copy() is called. The copy will not share references with this DeckRNG.
                                                                                                                                                                                                                                                                                                                  +445     *
                                                                                                                                                                                                                                                                                                                  +446     * @return a copy of this DeckRNG
                                                                                                                                                                                                                                                                                                                  +447     */
                                                                                                                                                                                                                                                                                                                  +448    public RNG copy()
                                                                                                                                                                                                                                                                                                                  +449    {
                                                                                                                                                                                                                                                                                                                  +450        DeckRNG next = new DeckRNG(lastShuffledState);
                                                                                                                                                                                                                                                                                                                  +451        next.random = random.copy();
                                                                                                                                                                                                                                                                                                                  +452        System.arraycopy(deck, 0, next.deck, 0, deck.length);
                                                                                                                                                                                                                                                                                                                  +453        next.step = step;
                                                                                                                                                                                                                                                                                                                  +454        return next;
                                                                                                                                                                                                                                                                                                                   455    }
                                                                                                                                                                                                                                                                                                                   456
                                                                                                                                                                                                                                                                                                                   457    /**
                                                                                                                                                                                                                                                                                                                  -458     * Reseeds this DeckRNG using the RandomnessSource it is given. Does not assign the RandomnessSource to any fields
                                                                                                                                                                                                                                                                                                                  -459     * that would affect future pseudo-random number generation.
                                                                                                                                                                                                                                                                                                                  -460     * @param random will be used to generate a new seed, but will not be assigned as this object's RandomnessSource
                                                                                                                                                                                                                                                                                                                  -461     */
                                                                                                                                                                                                                                                                                                                  -462    @Override
                                                                                                                                                                                                                                                                                                                  -463    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -464        setState(((long)random.next(32) << 32) | random.next(32));
                                                                                                                                                                                                                                                                                                                  -465
                                                                                                                                                                                                                                                                                                                  -466    }
                                                                                                                                                                                                                                                                                                                  -467
                                                                                                                                                                                                                                                                                                                  -468    /**
                                                                                                                                                                                                                                                                                                                  -469     * Creates a copy of this DeckRNG; it will generate the same random numbers, given the same calls in order, as
                                                                                                                                                                                                                                                                                                                  -470     * this DeckRNG at the point copy() is called. The copy will not share references with this DeckRNG.
                                                                                                                                                                                                                                                                                                                  -471     *
                                                                                                                                                                                                                                                                                                                  -472     * @return a copy of this DeckRNG
                                                                                                                                                                                                                                                                                                                  -473     */
                                                                                                                                                                                                                                                                                                                  -474    public RNG copy()
                                                                                                                                                                                                                                                                                                                  -475    {
                                                                                                                                                                                                                                                                                                                  -476        DeckRNG next = new DeckRNG(lastShuffledState);
                                                                                                                                                                                                                                                                                                                  -477        next.random = random.copy();
                                                                                                                                                                                                                                                                                                                  -478        System.arraycopy(deck, 0, next.deck, 0, deck.length);
                                                                                                                                                                                                                                                                                                                  -479        next.step = step;
                                                                                                                                                                                                                                                                                                                  -480        return next;
                                                                                                                                                                                                                                                                                                                  -481    }
                                                                                                                                                                                                                                                                                                                  -482
                                                                                                                                                                                                                                                                                                                  -483    /**
                                                                                                                                                                                                                                                                                                                  -484     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  -485     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  -486     * shuffling a copy of data and getting a section of it that matches the length of output.
                                                                                                                                                                                                                                                                                                                  -487     *
                                                                                                                                                                                                                                                                                                                  -488     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  -489     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  -490     * @param data an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -491     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  -492     * @param <T> can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -493     * @return an array of T that has length equal to output's length and may contain null elements if output is shorter
                                                                                                                                                                                                                                                                                                                  -494     * than data
                                                                                                                                                                                                                                                                                                                  -495     */
                                                                                                                                                                                                                                                                                                                  -496    @Override
                                                                                                                                                                                                                                                                                                                  -497    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  -498        return super.randomPortion(data, output);
                                                                                                                                                                                                                                                                                                                  -499    }
                                                                                                                                                                                                                                                                                                                  -500
                                                                                                                                                                                                                                                                                                                  -501    /**
                                                                                                                                                                                                                                                                                                                  -502     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  -503     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  -504     *
                                                                                                                                                                                                                                                                                                                  -505     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -506     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  -507     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  -508     */
                                                                                                                                                                                                                                                                                                                  -509    @Override
                                                                                                                                                                                                                                                                                                                  -510    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  -511        return super.randomPortion(data, count);
                                                                                                                                                                                                                                                                                                                  -512    }
                                                                                                                                                                                                                                                                                                                  -513
                                                                                                                                                                                                                                                                                                                  -514    /**
                                                                                                                                                                                                                                                                                                                  -515     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  -516     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  -517     *
                                                                                                                                                                                                                                                                                                                  -518     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  -519     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  -520     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  -521     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  -522     */
                                                                                                                                                                                                                                                                                                                  -523    @Override
                                                                                                                                                                                                                                                                                                                  -524    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  -525        return super.randomRange(start, end, count);
                                                                                                                                                                                                                                                                                                                  -526    }
                                                                                                                                                                                                                                                                                                                  -527
                                                                                                                                                                                                                                                                                                                  -528    /**
                                                                                                                                                                                                                                                                                                                  -529     * Shuffle an array using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  -530     * @param array an array of double; WILL be modified
                                                                                                                                                                                                                                                                                                                  -531     */
                                                                                                                                                                                                                                                                                                                  -532    private void shuffleInPlace(double[] array)
                                                                                                                                                                                                                                                                                                                  -533    {
                                                                                                                                                                                                                                                                                                                  -534        lastShuffledState = ((LightRNG)random).getState();
                                                                                                                                                                                                                                                                                                                  -535        int n = array.length;
                                                                                                                                                                                                                                                                                                                  -536        System.arraycopy(baseDeck, 0, array, 0, n);
                                                                                                                                                                                                                                                                                                                  -537        for (int i = 0; i < n; i++)
                                                                                                                                                                                                                                                                                                                  -538        {
                                                                                                                                                                                                                                                                                                                  -539            int r = i + ((LightRNG)random).nextInt(n - i);
                                                                                                                                                                                                                                                                                                                  -540            double t = array[r];
                                                                                                                                                                                                                                                                                                                  -541            array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  -542            array[i] =((LightRNG)random).nextDouble(0.0625) + t;
                                                                                                                                                                                                                                                                                                                  -543        }
                                                                                                                                                                                                                                                                                                                  -544    }
                                                                                                                                                                                                                                                                                                                  -545
                                                                                                                                                                                                                                                                                                                  -546    /**
                                                                                                                                                                                                                                                                                                                  -547     * Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                                                                                                                                                                                                                                                                  -548     *
                                                                                                                                                                                                                                                                                                                  -549     * @return a long that can be used as state.
                                                                                                                                                                                                                                                                                                                  -550     */
                                                                                                                                                                                                                                                                                                                  -551    @Override
                                                                                                                                                                                                                                                                                                                  -552    public long getState() {
                                                                                                                                                                                                                                                                                                                  -553        return lastShuffledState;
                                                                                                                                                                                                                                                                                                                  -554    }
                                                                                                                                                                                                                                                                                                                  +458     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  +459     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  +460     * shuffling a copy of data and getting a section of it that matches the length of output.
                                                                                                                                                                                                                                                                                                                  +461     *
                                                                                                                                                                                                                                                                                                                  +462     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  +463     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  +464     * @param data an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +465     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  +466     * @param <T> can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +467     * @return an array of T that has length equal to output's length and may contain null elements if output is shorter
                                                                                                                                                                                                                                                                                                                  +468     * than data
                                                                                                                                                                                                                                                                                                                  +469     */
                                                                                                                                                                                                                                                                                                                  +470    @Override
                                                                                                                                                                                                                                                                                                                  +471    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  +472        return super.randomPortion(data, output);
                                                                                                                                                                                                                                                                                                                  +473    }
                                                                                                                                                                                                                                                                                                                  +474
                                                                                                                                                                                                                                                                                                                  +475    /**
                                                                                                                                                                                                                                                                                                                  +476     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  +477     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  +478     *
                                                                                                                                                                                                                                                                                                                  +479     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +480     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  +481     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  +482     */
                                                                                                                                                                                                                                                                                                                  +483    @Override
                                                                                                                                                                                                                                                                                                                  +484    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  +485        return super.randomPortion(data, count);
                                                                                                                                                                                                                                                                                                                  +486    }
                                                                                                                                                                                                                                                                                                                  +487
                                                                                                                                                                                                                                                                                                                  +488    /**
                                                                                                                                                                                                                                                                                                                  +489     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  +490     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  +491     *
                                                                                                                                                                                                                                                                                                                  +492     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  +493     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  +494     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  +495     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  +496     */
                                                                                                                                                                                                                                                                                                                  +497    @Override
                                                                                                                                                                                                                                                                                                                  +498    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  +499        return super.randomRange(start, end, count);
                                                                                                                                                                                                                                                                                                                  +500    }
                                                                                                                                                                                                                                                                                                                  +501
                                                                                                                                                                                                                                                                                                                  +502    /**
                                                                                                                                                                                                                                                                                                                  +503     * Shuffle an array using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  +504     * @param array an array of double; WILL be modified
                                                                                                                                                                                                                                                                                                                  +505     */
                                                                                                                                                                                                                                                                                                                  +506    private void shuffleInPlace(double[] array)
                                                                                                                                                                                                                                                                                                                  +507    {
                                                                                                                                                                                                                                                                                                                  +508        lastShuffledState = ((LightRNG)random).getState();
                                                                                                                                                                                                                                                                                                                  +509        int n = array.length;
                                                                                                                                                                                                                                                                                                                  +510        System.arraycopy(baseDeck, 0, array, 0, n);
                                                                                                                                                                                                                                                                                                                  +511        for (int i = 0; i < n; i++)
                                                                                                                                                                                                                                                                                                                  +512        {
                                                                                                                                                                                                                                                                                                                  +513            int r = i + ((LightRNG)random).nextInt(n - i);
                                                                                                                                                                                                                                                                                                                  +514            double t = array[r];
                                                                                                                                                                                                                                                                                                                  +515            array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  +516            array[i] =((LightRNG)random).nextDouble(0.0625) + t;
                                                                                                                                                                                                                                                                                                                  +517        }
                                                                                                                                                                                                                                                                                                                  +518    }
                                                                                                                                                                                                                                                                                                                  +519
                                                                                                                                                                                                                                                                                                                  +520    /**
                                                                                                                                                                                                                                                                                                                  +521     * Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                                                                                                                                                                                                                                                                  +522     *
                                                                                                                                                                                                                                                                                                                  +523     * @return a long that can be used as state.
                                                                                                                                                                                                                                                                                                                  +524     */
                                                                                                                                                                                                                                                                                                                  +525    @Override
                                                                                                                                                                                                                                                                                                                  +526    public long getState() {
                                                                                                                                                                                                                                                                                                                  +527        return lastShuffledState;
                                                                                                                                                                                                                                                                                                                  +528    }
                                                                                                                                                                                                                                                                                                                  +529
                                                                                                                                                                                                                                                                                                                  +530    /**
                                                                                                                                                                                                                                                                                                                  +531     * Sets the state of the random number generator to a given long, which will alter future random numbers this
                                                                                                                                                                                                                                                                                                                  +532     * produces based on the state. Setting the state always causes the "deck" of random grades to be shuffled.
                                                                                                                                                                                                                                                                                                                  +533     *
                                                                                                                                                                                                                                                                                                                  +534     * @param state any long (this can tolerate states of 0)
                                                                                                                                                                                                                                                                                                                  +535     */
                                                                                                                                                                                                                                                                                                                  +536    @Override
                                                                                                                                                                                                                                                                                                                  +537    public void setState(long state) {
                                                                                                                                                                                                                                                                                                                  +538        ((LightRNG)random).setState(state);
                                                                                                                                                                                                                                                                                                                  +539        shuffleInPlace(deck);
                                                                                                                                                                                                                                                                                                                  +540        step = 0;
                                                                                                                                                                                                                                                                                                                  +541    }
                                                                                                                                                                                                                                                                                                                  +542
                                                                                                                                                                                                                                                                                                                  +543    @Override
                                                                                                                                                                                                                                                                                                                  +544    public String toString() {
                                                                                                                                                                                                                                                                                                                  +545        return "DeckRNG{state: 0x" + StringKit.hex(lastShuffledState) + "L, step: 0x" + StringKit.hex(step) + "}";
                                                                                                                                                                                                                                                                                                                  +546    }
                                                                                                                                                                                                                                                                                                                  +547
                                                                                                                                                                                                                                                                                                                  +548    @Override
                                                                                                                                                                                                                                                                                                                  +549    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  +550        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  +551        if (o == null || getClass() != o.getClass()) return false;
                                                                                                                                                                                                                                                                                                                  +552        if (!super.equals(o)) return false;
                                                                                                                                                                                                                                                                                                                  +553
                                                                                                                                                                                                                                                                                                                  +554        DeckRNG deckRNG = (DeckRNG) o;
                                                                                                                                                                                                                                                                                                                   555
                                                                                                                                                                                                                                                                                                                  -556    /**
                                                                                                                                                                                                                                                                                                                  -557     * Sets the state of the random number generator to a given long, which will alter future random numbers this
                                                                                                                                                                                                                                                                                                                  -558     * produces based on the state. Setting the state always causes the "deck" of random grades to be shuffled.
                                                                                                                                                                                                                                                                                                                  -559     *
                                                                                                                                                                                                                                                                                                                  -560     * @param state any long (this can tolerate states of 0)
                                                                                                                                                                                                                                                                                                                  -561     */
                                                                                                                                                                                                                                                                                                                  -562    @Override
                                                                                                                                                                                                                                                                                                                  -563    public void setState(long state) {
                                                                                                                                                                                                                                                                                                                  -564        ((LightRNG)random).setState(state);
                                                                                                                                                                                                                                                                                                                  -565        shuffleInPlace(deck);
                                                                                                                                                                                                                                                                                                                  -566        step = 0;
                                                                                                                                                                                                                                                                                                                  -567    }
                                                                                                                                                                                                                                                                                                                  -568
                                                                                                                                                                                                                                                                                                                  -569    @Override
                                                                                                                                                                                                                                                                                                                  -570    public String toString() {
                                                                                                                                                                                                                                                                                                                  -571        return "DeckRNG{state: 0x" + StringKit.hex(lastShuffledState) + "L, step: 0x" + StringKit.hex(step) + "}";
                                                                                                                                                                                                                                                                                                                  -572    }
                                                                                                                                                                                                                                                                                                                  -573
                                                                                                                                                                                                                                                                                                                  -574    @Override
                                                                                                                                                                                                                                                                                                                  -575    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  -576        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  -577        if (o == null || getClass() != o.getClass()) return false;
                                                                                                                                                                                                                                                                                                                  -578        if (!super.equals(o)) return false;
                                                                                                                                                                                                                                                                                                                  -579
                                                                                                                                                                                                                                                                                                                  -580        DeckRNG deckRNG = (DeckRNG) o;
                                                                                                                                                                                                                                                                                                                  -581
                                                                                                                                                                                                                                                                                                                  -582        if (step != deckRNG.step) return false;
                                                                                                                                                                                                                                                                                                                  -583        return lastShuffledState == deckRNG.lastShuffledState;
                                                                                                                                                                                                                                                                                                                  -584    }
                                                                                                                                                                                                                                                                                                                  -585
                                                                                                                                                                                                                                                                                                                  -586    @Override
                                                                                                                                                                                                                                                                                                                  -587    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  -588        int result = random.hashCode();
                                                                                                                                                                                                                                                                                                                  -589        result = 31 * result + step;
                                                                                                                                                                                                                                                                                                                  -590        result = 31 * result + (int) (lastShuffledState ^ (lastShuffledState >>> 32));
                                                                                                                                                                                                                                                                                                                  -591        return result;
                                                                                                                                                                                                                                                                                                                  -592    }
                                                                                                                                                                                                                                                                                                                  -593
                                                                                                                                                                                                                                                                                                                  -594    public int getStep() {
                                                                                                                                                                                                                                                                                                                  -595        return step;
                                                                                                                                                                                                                                                                                                                  -596    }
                                                                                                                                                                                                                                                                                                                  -597
                                                                                                                                                                                                                                                                                                                  -598    public void setStep(int step) {
                                                                                                                                                                                                                                                                                                                  -599        this.step = step;
                                                                                                                                                                                                                                                                                                                  -600    }
                                                                                                                                                                                                                                                                                                                  -601}
                                                                                                                                                                                                                                                                                                                  +556        if (step != deckRNG.step) return false;
                                                                                                                                                                                                                                                                                                                  +557        return lastShuffledState == deckRNG.lastShuffledState;
                                                                                                                                                                                                                                                                                                                  +558    }
                                                                                                                                                                                                                                                                                                                  +559
                                                                                                                                                                                                                                                                                                                  +560    @Override
                                                                                                                                                                                                                                                                                                                  +561    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  +562        int result = random.hashCode();
                                                                                                                                                                                                                                                                                                                  +563        result = 31 * result + step;
                                                                                                                                                                                                                                                                                                                  +564        result = 31 * result + (int) (lastShuffledState ^ (lastShuffledState >>> 32));
                                                                                                                                                                                                                                                                                                                  +565        return result;
                                                                                                                                                                                                                                                                                                                  +566    }
                                                                                                                                                                                                                                                                                                                  +567
                                                                                                                                                                                                                                                                                                                  +568    public int getStep() {
                                                                                                                                                                                                                                                                                                                  +569        return step;
                                                                                                                                                                                                                                                                                                                  +570    }
                                                                                                                                                                                                                                                                                                                  +571
                                                                                                                                                                                                                                                                                                                  +572    public void setStep(int step) {
                                                                                                                                                                                                                                                                                                                  +573        this.step = step;
                                                                                                                                                                                                                                                                                                                  +574    }
                                                                                                                                                                                                                                                                                                                  +575}
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/DharmaRNG.html b/docs/squidlib-util/src-html/squidpony/squidmath/DharmaRNG.html
                                                                                                                                                                                                                                                                                                                  index ff0eb93ec4..0c63518fd5 100644
                                                                                                                                                                                                                                                                                                                  --- a/docs/squidlib-util/src-html/squidpony/squidmath/DharmaRNG.html
                                                                                                                                                                                                                                                                                                                  +++ b/docs/squidlib-util/src-html/squidpony/squidmath/DharmaRNG.html
                                                                                                                                                                                                                                                                                                                  @@ -8,590 +8,530 @@
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  001package squidpony.squidmath;
                                                                                                                                                                                                                                                                                                                   002
                                                                                                                                                                                                                                                                                                                  -003import squidpony.annotation.GwtIncompatible;
                                                                                                                                                                                                                                                                                                                  -004
                                                                                                                                                                                                                                                                                                                  -005import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  -006import java.util.*;
                                                                                                                                                                                                                                                                                                                  -007
                                                                                                                                                                                                                                                                                                                  -008/**
                                                                                                                                                                                                                                                                                                                  -009 * An alteration to a RandomnessSource that attempts to produce values that are perceived as fair to an imperfect user.
                                                                                                                                                                                                                                                                                                                  -010 * <p>
                                                                                                                                                                                                                                                                                                                  -011 * This takes a RandomnessSource, defaulting to a LightRNG, and uses it to generate random values, but tracks the total
                                                                                                                                                                                                                                                                                                                  -012 * and compares it to the potential total of a generator of only numbers with a desired value (default 0.54,
                                                                                                                                                                                                                                                                                                                  -013 * so it compares against a sequence of all 0.54). If the current generated total is too high or low compared to the
                                                                                                                                                                                                                                                                                                                  -014 * desired total, the currently used seed is possibly changed, the generated number is moved in the direction of the
                                                                                                                                                                                                                                                                                                                  -015 * desired fairness, and it returns that instead of the number that would have pushed the current generated total
                                                                                                                                                                                                                                                                                                                  -016 * beyond the desired threshold. The new number, if one is changed, will always be closer to the desired fairness.
                                                                                                                                                                                                                                                                                                                  -017 * This is absolutely insecure for cryptographic purposes, but should seem more "fair" to a player than a
                                                                                                                                                                                                                                                                                                                  -018 * random number generator that seeks to be truly random.
                                                                                                                                                                                                                                                                                                                  -019 * You can create multiple DharmaRNG objects with different fairness values and seeds, and use favorable generators
                                                                                                                                                                                                                                                                                                                  -020 * (with fairness greater than 0.54) for characters that need an easier time, or unfavorable generators if you want
                                                                                                                                                                                                                                                                                                                  -021 * the characters that use that RNG to be impeded somewhat.
                                                                                                                                                                                                                                                                                                                  -022 * The name comes from the Wheel of Dharma.
                                                                                                                                                                                                                                                                                                                  -023 * This class currently will have a slight bias toward lower numbers with many RNGs unless fairness is tweaked; 0.54
                                                                                                                                                                                                                                                                                                                  -024 * can be used as a stand-in because 0.5 leans too low.
                                                                                                                                                                                                                                                                                                                  -025 *
                                                                                                                                                                                                                                                                                                                  -026 * <p>
                                                                                                                                                                                                                                                                                                                  -027 * You can get values from this generator with: {@link #nextDouble()}, {@link #nextInt()},
                                                                                                                                                                                                                                                                                                                  -028 *   {@link #nextLong()}, and the bounded variants on each of those.
                                                                                                                                                                                                                                                                                                                  -029 * <p>
                                                                                                                                                                                                                                                                                                                  -030 * You can alter the tracking information or requested fairness with {@link #resetFortune()},
                                                                                                                                                                                                                                                                                                                  -031 *   {@link #setFairness(double)}, and {@link #getFairness()}.
                                                                                                                                                                                                                                                                                                                  -032 *
                                                                                                                                                                                                                                                                                                                  -033 * Created by Tommy Ettinger on 5/2/2015.
                                                                                                                                                                                                                                                                                                                  -034 */
                                                                                                                                                                                                                                                                                                                  -035public class DharmaRNG extends RNG implements Serializable{
                                                                                                                                                                                                                                                                                                                  -036
                                                                                                                                                                                                                                                                                                                  -037        /** Used to tweak the generator toward high or low values. */
                                                                                                                                                                                                                                                                                                                  -038    private double fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  -039
                                                                                                                                                                                                                                                                                                                  -040    /** Running total for what this has actually produced. */
                                                                                                                                                                                                                                                                                                                  -041    private double produced = 0.0;
                                                                                                                                                                                                                                                                                                                  -042
                                                                                                                                                                                                                                                                                                                  -043    /** Running total for what this would produce if it always produced a value equal to fairness. */
                                                                                                                                                                                                                                                                                                                  -044    private double baseline = 0.0;
                                                                                                                                                                                                                                                                                                                  -045
                                                                                                                                                                                                                                                                                                                  -046        private static final long serialVersionUID = -8919455766853811999L;
                                                                                                                                                                                                                                                                                                                  -047
                                                                                                                                                                                                                                                                                                                  -048    /**
                                                                                                                                                                                                                                                                                                                  -049     * Constructs a DharmaRNG with a pseudo-random seed from Math.random().
                                                                                                                                                                                                                                                                                                                  -050     */
                                                                                                                                                                                                                                                                                                                  -051    public DharmaRNG()
                                                                                                                                                                                                                                                                                                                  -052    {
                                                                                                                                                                                                                                                                                                                  -053        this((long)(Math.random() * ((1L << 50) - 1)));
                                                                                                                                                                                                                                                                                                                  -054    }
                                                                                                                                                                                                                                                                                                                  -055    /**
                                                                                                                                                                                                                                                                                                                  -056     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -057     *
                                                                                                                                                                                                                                                                                                                  -058     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -059     */
                                                                                                                                                                                                                                                                                                                  -060    public DharmaRNG(final long seed) {
                                                                                                                                                                                                                                                                                                                  -061        super(seed);
                                                                                                                                                                                                                                                                                                                  -062    }
                                                                                                                                                                                                                                                                                                                  -063
                                                                                                                                                                                                                                                                                                                  -064    /**
                                                                                                                                                                                                                                                                                                                  -065     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -066     *
                                                                                                                                                                                                                                                                                                                  -067     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -068     * @param fairness the desired fairness metric, which must be between 0.0 and 1.0
                                                                                                                                                                                                                                                                                                                  -069     */
                                                                                                                                                                                                                                                                                                                  -070    public DharmaRNG(final long seed, final double fairness) {
                                                                                                                                                                                                                                                                                                                  -071        super(seed);
                                                                                                                                                                                                                                                                                                                  -072        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  -073            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  -074        else
                                                                                                                                                                                                                                                                                                                  -075            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  -076    }
                                                                                                                                                                                                                                                                                                                  +003import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  +004import java.util.Collection;
                                                                                                                                                                                                                                                                                                                  +005import java.util.List;
                                                                                                                                                                                                                                                                                                                  +006
                                                                                                                                                                                                                                                                                                                  +007/**
                                                                                                                                                                                                                                                                                                                  +008 * An alteration to a RandomnessSource that attempts to produce values that are perceived as fair to an imperfect user.
                                                                                                                                                                                                                                                                                                                  +009 * <p>
                                                                                                                                                                                                                                                                                                                  +010 * This takes a RandomnessSource, defaulting to a LightRNG, and uses it to generate random values, but tracks the total
                                                                                                                                                                                                                                                                                                                  +011 * and compares it to the potential total of a generator of only numbers with a desired value (default 0.54,
                                                                                                                                                                                                                                                                                                                  +012 * so it compares against a sequence of all 0.54). If the current generated total is too high or low compared to the
                                                                                                                                                                                                                                                                                                                  +013 * desired total, the currently used seed is possibly changed, the generated number is moved in the direction of the
                                                                                                                                                                                                                                                                                                                  +014 * desired fairness, and it returns that instead of the number that would have pushed the current generated total
                                                                                                                                                                                                                                                                                                                  +015 * beyond the desired threshold. The new number, if one is changed, will always be closer to the desired fairness.
                                                                                                                                                                                                                                                                                                                  +016 * This is absolutely insecure for cryptographic purposes, but should seem more "fair" to a player than a
                                                                                                                                                                                                                                                                                                                  +017 * random number generator that seeks to be truly random.
                                                                                                                                                                                                                                                                                                                  +018 * You can create multiple DharmaRNG objects with different fairness values and seeds, and use favorable generators
                                                                                                                                                                                                                                                                                                                  +019 * (with fairness greater than 0.54) for characters that need an easier time, or unfavorable generators if you want
                                                                                                                                                                                                                                                                                                                  +020 * the characters that use that RNG to be impeded somewhat.
                                                                                                                                                                                                                                                                                                                  +021 * The name comes from the Wheel of Dharma.
                                                                                                                                                                                                                                                                                                                  +022 * This class currently will have a slight bias toward lower numbers with many RNGs unless fairness is tweaked; 0.54
                                                                                                                                                                                                                                                                                                                  +023 * can be used as a stand-in because 0.5 leans too low.
                                                                                                                                                                                                                                                                                                                  +024 *
                                                                                                                                                                                                                                                                                                                  +025 * <p>
                                                                                                                                                                                                                                                                                                                  +026 * You can get values from this generator with: {@link #nextDouble()}, {@link #nextInt()},
                                                                                                                                                                                                                                                                                                                  +027 *   {@link #nextLong()}, and the bounded variants on each of those.
                                                                                                                                                                                                                                                                                                                  +028 * <p>
                                                                                                                                                                                                                                                                                                                  +029 * You can alter the tracking information or requested fairness with {@link #resetFortune()},
                                                                                                                                                                                                                                                                                                                  +030 *   {@link #setFairness(double)}, and {@link #getFairness()}.
                                                                                                                                                                                                                                                                                                                  +031 *
                                                                                                                                                                                                                                                                                                                  +032 * Created by Tommy Ettinger on 5/2/2015.
                                                                                                                                                                                                                                                                                                                  +033 */
                                                                                                                                                                                                                                                                                                                  +034public class DharmaRNG extends RNG implements Serializable{
                                                                                                                                                                                                                                                                                                                  +035
                                                                                                                                                                                                                                                                                                                  +036        /** Used to tweak the generator toward high or low values. */
                                                                                                                                                                                                                                                                                                                  +037    private double fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  +038
                                                                                                                                                                                                                                                                                                                  +039    /** Running total for what this has actually produced. */
                                                                                                                                                                                                                                                                                                                  +040    private double produced = 0.0;
                                                                                                                                                                                                                                                                                                                  +041
                                                                                                                                                                                                                                                                                                                  +042    /** Running total for what this would produce if it always produced a value equal to fairness. */
                                                                                                                                                                                                                                                                                                                  +043    private double baseline = 0.0;
                                                                                                                                                                                                                                                                                                                  +044
                                                                                                                                                                                                                                                                                                                  +045        private static final long serialVersionUID = -8919455766853811999L;
                                                                                                                                                                                                                                                                                                                  +046
                                                                                                                                                                                                                                                                                                                  +047    /**
                                                                                                                                                                                                                                                                                                                  +048     * Constructs a DharmaRNG with a pseudo-random seed from Math.random().
                                                                                                                                                                                                                                                                                                                  +049     */
                                                                                                                                                                                                                                                                                                                  +050    public DharmaRNG()
                                                                                                                                                                                                                                                                                                                  +051    {
                                                                                                                                                                                                                                                                                                                  +052        this((long)(Math.random() * ((1L << 50) - 1)));
                                                                                                                                                                                                                                                                                                                  +053    }
                                                                                                                                                                                                                                                                                                                  +054    /**
                                                                                                                                                                                                                                                                                                                  +055     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +056     *
                                                                                                                                                                                                                                                                                                                  +057     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +058     */
                                                                                                                                                                                                                                                                                                                  +059    public DharmaRNG(final long seed) {
                                                                                                                                                                                                                                                                                                                  +060        super(seed);
                                                                                                                                                                                                                                                                                                                  +061    }
                                                                                                                                                                                                                                                                                                                  +062
                                                                                                                                                                                                                                                                                                                  +063    /**
                                                                                                                                                                                                                                                                                                                  +064     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +065     *
                                                                                                                                                                                                                                                                                                                  +066     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +067     * @param fairness the desired fairness metric, which must be between 0.0 and 1.0
                                                                                                                                                                                                                                                                                                                  +068     */
                                                                                                                                                                                                                                                                                                                  +069    public DharmaRNG(final long seed, final double fairness) {
                                                                                                                                                                                                                                                                                                                  +070        super(seed);
                                                                                                                                                                                                                                                                                                                  +071        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  +072            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  +073        else
                                                                                                                                                                                                                                                                                                                  +074            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  +075    }
                                                                                                                                                                                                                                                                                                                  +076
                                                                                                                                                                                                                                                                                                                   077
                                                                                                                                                                                                                                                                                                                  -078
                                                                                                                                                                                                                                                                                                                  -079    /**
                                                                                                                                                                                                                                                                                                                  -080     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  -081     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  -082     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -083     *
                                                                                                                                                                                                                                                                                                                  -084     * @param seedString a String as a seed
                                                                                                                                                                                                                                                                                                                  -085     */
                                                                                                                                                                                                                                                                                                                  -086    public DharmaRNG(String seedString) {
                                                                                                                                                                                                                                                                                                                  -087        super(seedString);
                                                                                                                                                                                                                                                                                                                  -088    }
                                                                                                                                                                                                                                                                                                                  +078    /**
                                                                                                                                                                                                                                                                                                                  +079     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  +080     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  +081     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +082     *
                                                                                                                                                                                                                                                                                                                  +083     * @param seedString a String as a seed
                                                                                                                                                                                                                                                                                                                  +084     */
                                                                                                                                                                                                                                                                                                                  +085    public DharmaRNG(CharSequence seedString) {
                                                                                                                                                                                                                                                                                                                  +086        super(seedString);
                                                                                                                                                                                                                                                                                                                  +087    }
                                                                                                                                                                                                                                                                                                                  +088
                                                                                                                                                                                                                                                                                                                   089
                                                                                                                                                                                                                                                                                                                  -090
                                                                                                                                                                                                                                                                                                                  -091    /**
                                                                                                                                                                                                                                                                                                                  -092     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  -093     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  -094     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -095     *
                                                                                                                                                                                                                                                                                                                  -096     * @param seedString a String as a seed
                                                                                                                                                                                                                                                                                                                  -097     */
                                                                                                                                                                                                                                                                                                                  -098    public DharmaRNG(String seedString, double fairness) {
                                                                                                                                                                                                                                                                                                                  -099        super(seedString);
                                                                                                                                                                                                                                                                                                                  -100        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  -101            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  -102        else
                                                                                                                                                                                                                                                                                                                  -103            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  -104
                                                                                                                                                                                                                                                                                                                  -105    }
                                                                                                                                                                                                                                                                                                                  -106    /**
                                                                                                                                                                                                                                                                                                                  -107     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -108     *
                                                                                                                                                                                                                                                                                                                  -109     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  -110     */
                                                                                                                                                                                                                                                                                                                  -111    public DharmaRNG(final RandomnessSource rs) {
                                                                                                                                                                                                                                                                                                                  -112        super(rs);
                                                                                                                                                                                                                                                                                                                  -113    }
                                                                                                                                                                                                                                                                                                                  -114    /**
                                                                                                                                                                                                                                                                                                                  -115     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -116     *
                                                                                                                                                                                                                                                                                                                  -117     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  -118     * @param fairness the desired fairness metric, which must be between 0.0 and 1.0
                                                                                                                                                                                                                                                                                                                  -119     */
                                                                                                                                                                                                                                                                                                                  -120    public DharmaRNG(final RandomnessSource rs, final double fairness) {
                                                                                                                                                                                                                                                                                                                  -121        super(rs);
                                                                                                                                                                                                                                                                                                                  -122        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  -123            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  -124        else
                                                                                                                                                                                                                                                                                                                  -125            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  -126    }
                                                                                                                                                                                                                                                                                                                  -127
                                                                                                                                                                                                                                                                                                                  -128    /**
                                                                                                                                                                                                                                                                                                                  -129     * Generate a random double, altering the result if recently generated results have been leaning
                                                                                                                                                                                                                                                                                                                  -130     * away from this class' fairness value.
                                                                                                                                                                                                                                                                                                                  -131     * @return a double between 0.0 (inclusive) and 1.0 (exclusive)
                                                                                                                                                                                                                                                                                                                  -132     */
                                                                                                                                                                                                                                                                                                                  -133    @Override
                                                                                                                                                                                                                                                                                                                  -134    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  -135        double gen = random.nextLong() * DOUBLE_UNIT;
                                                                                                                                                                                                                                                                                                                  -136        /*if(Math.abs((produced + gen) - (baseline + fairness)) > 1.5) {
                                                                                                                                                                                                                                                                                                                  -137            //do some reseeding here if possible
                                                                                                                                                                                                                                                                                                                  -138        }*/
                                                                                                                                                                                                                                                                                                                  -139        if(Math.abs((produced + gen) - (baseline + fairness)) > 0.5)
                                                                                                                                                                                                                                                                                                                  -140        {
                                                                                                                                                                                                                                                                                                                  -141            gen = (gen + fairness) / 2.0;
                                                                                                                                                                                                                                                                                                                  -142            produced *= 0.5;
                                                                                                                                                                                                                                                                                                                  -143            baseline *= 0.5;
                                                                                                                                                                                                                                                                                                                  -144            produced += gen;
                                                                                                                                                                                                                                                                                                                  -145            baseline += fairness;
                                                                                                                                                                                                                                                                                                                  -146            return gen;
                                                                                                                                                                                                                                                                                                                  -147        }
                                                                                                                                                                                                                                                                                                                  -148        else
                                                                                                                                                                                                                                                                                                                  -149        {
                                                                                                                                                                                                                                                                                                                  -150            produced += gen;
                                                                                                                                                                                                                                                                                                                  -151            baseline += fairness;
                                                                                                                                                                                                                                                                                                                  -152            return gen;
                                                                                                                                                                                                                                                                                                                  -153        }
                                                                                                                                                                                                                                                                                                                  -154    }
                                                                                                                                                                                                                                                                                                                  -155
                                                                                                                                                                                                                                                                                                                  -156    /**
                                                                                                                                                                                                                                                                                                                  -157     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -158     *
                                                                                                                                                                                                                                                                                                                  -159     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  -160     */
                                                                                                                                                                                                                                                                                                                  -161    @Override
                                                                                                                                                                                                                                                                                                                  -162    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  -163        return super.nextDouble(max);
                                                                                                                                                                                                                                                                                                                  -164    }
                                                                                                                                                                                                                                                                                                                  -165
                                                                                                                                                                                                                                                                                                                  -166    /**
                                                                                                                                                                                                                                                                                                                  -167     * Returns a value from a even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  -168     * (exclusive).
                                                                                                                                                                                                                                                                                                                  -169     *
                                                                                                                                                                                                                                                                                                                  -170     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -171     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -172     * @return the found value
                                                                                                                                                                                                                                                                                                                  -173     */
                                                                                                                                                                                                                                                                                                                  -174    @Override
                                                                                                                                                                                                                                                                                                                  -175    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  -176        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  -177    }
                                                                                                                                                                                                                                                                                                                  -178
                                                                                                                                                                                                                                                                                                                  -179    /**
                                                                                                                                                                                                                                                                                                                  -180     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -181     *
                                                                                                                                                                                                                                                                                                                  -182     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -183     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -184     *
                                                                                                                                                                                                                                                                                                                  -185     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -186     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -187     * @return the found value
                                                                                                                                                                                                                                                                                                                  -188     */
                                                                                                                                                                                                                                                                                                                  -189    @Override
                                                                                                                                                                                                                                                                                                                  -190    public int between(int min, int max)
                                                                                                                                                                                                                                                                                                                  -191    {
                                                                                                                                                                                                                                                                                                                  -192        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  -193    }
                                                                                                                                                                                                                                                                                                                  -194
                                                                                                                                                                                                                                                                                                                  -195    /**
                                                                                                                                                                                                                                                                                                                  -196     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  -197     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  -198     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  -199     *
                                                                                                                                                                                                                                                                                                                  -200     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -201     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -202     *
                                                                                                                                                                                                                                                                                                                  -203     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  -204     *
                                                                                                                                                                                                                                                                                                                  -205     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -206     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -207     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  -208     * @return the found value
                                                                                                                                                                                                                                                                                                                  -209     */
                                                                                                                                                                                                                                                                                                                  -210    @Override
                                                                                                                                                                                                                                                                                                                  -211    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  -212        return super.betweenWeighted(min, max, samples);
                                                                                                                                                                                                                                                                                                                  -213    }
                                                                                                                                                                                                                                                                                                                  -214
                                                                                                                                                                                                                                                                                                                  -215    /**
                                                                                                                                                                                                                                                                                                                  -216     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  -217     * type.
                                                                                                                                                                                                                                                                                                                  -218     *
                                                                                                                                                                                                                                                                                                                  -219     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -220     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  -221     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -222     */
                                                                                                                                                                                                                                                                                                                  -223    @Override
                                                                                                                                                                                                                                                                                                                  -224    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  -225        return super.getRandomElement(array);
                                                                                                                                                                                                                                                                                                                  -226    }
                                                                                                                                                                                                                                                                                                                  -227
                                                                                                                                                                                                                                                                                                                  -228    /**
                                                                                                                                                                                                                                                                                                                  -229     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  -230     * then null is returned.
                                                                                                                                                                                                                                                                                                                  -231     *
                                                                                                                                                                                                                                                                                                                  -232     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -233     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  -234     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -235     */
                                                                                                                                                                                                                                                                                                                  -236    @Override
                                                                                                                                                                                                                                                                                                                  -237    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -238        return super.getRandomElement(list);
                                                                                                                                                                                                                                                                                                                  -239    }
                                                                                                                                                                                                                                                                                                                  -240
                                                                                                                                                                                                                                                                                                                  -241    /**
                                                                                                                                                                                                                                                                                                                  -242     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  -243     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  -244     *
                                                                                                                                                                                                                                                                                                                  -245     * <p>
                                                                                                                                                                                                                                                                                                                  -246     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  -247     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  -248     * </p>
                                                                                                                                                                                                                                                                                                                  -249     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  -250     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -251     */
                                                                                                                                                                                                                                                                                                                  -252    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  -253        return super.getRandomElement(set);
                                                                                                                                                                                                                                                                                                                  -254    }
                                                                                                                                                                                                                                                                                                                  -255
                                                                                                                                                                                                                                                                                                                  -256    /**
                                                                                                                                                                                                                                                                                                                  -257     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  -258     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  -259     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  -260     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  -261     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  -262     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  -263     *
                                                                                                                                                                                                                                                                                                                  -264     * <p>
                                                                                                                                                                                                                                                                                                                  -265     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  -266     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  -267     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  -268     * </p>
                                                                                                                                                                                                                                                                                                                  -269     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -270     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  -271     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -272     */
                                                                                                                                                                                                                                                                                                                  -273    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  -274        return super.getRandomElement(coll);
                                                                                                                                                                                                                                                                                                                  -275    }
                                                                                                                                                                                                                                                                                                                  -276
                                                                                                                                                                                                                                                                                                                  -277    /**
                                                                                                                                                                                                                                                                                                                  -278     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  -279     */
                                                                                                                                                                                                                                                                                                                  -280    @Override
                                                                                                                                                                                                                                                                                                                  -281    public synchronized double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  -282        return super.nextGaussian();
                                                                                                                                                                                                                                                                                                                  -283    }
                                                                                                                                                                                                                                                                                                                  -284    /**
                                                                                                                                                                                                                                                                                                                  -285     * Returns a random integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -286     * negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  -287     *
                                                                                                                                                                                                                                                                                                                  -288     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -289     * @return the found number
                                                                                                                                                                                                                                                                                                                  -290     */
                                                                                                                                                                                                                                                                                                                  -291    @Override
                                                                                                                                                                                                                                                                                                                  -292    public int nextInt(int bound) {
                                                                                                                                                                                                                                                                                                                  -293        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  -294            return 0;
                                                                                                                                                                                                                                                                                                                  -295        }
                                                                                                                                                                                                                                                                                                                  -296
                                                                                                                                                                                                                                                                                                                  -297        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -298    }
                                                                                                                                                                                                                                                                                                                  -299
                                                                                                                                                                                                                                                                                                                  -300    /**
                                                                                                                                                                                                                                                                                                                  -301     * Returns a random integer, which may be positive or negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  -302     * @return A random int
                                                                                                                                                                                                                                                                                                                  -303     */
                                                                                                                                                                                                                                                                                                                  -304    @Override
                                                                                                                                                                                                                                                                                                                  -305    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  -306        return (int)((nextDouble() - 0.5) * 2.0 * 0x7FFFFFFF);
                                                                                                                                                                                                                                                                                                                  -307    }
                                                                                                                                                                                                                                                                                                                  -308
                                                                                                                                                                                                                                                                                                                  -309    /**
                                                                                                                                                                                                                                                                                                                  -310     * Returns a random long, which may be positive or negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  -311     * @return A random long
                                                                                                                                                                                                                                                                                                                  -312     */
                                                                                                                                                                                                                                                                                                                  -313    @Override
                                                                                                                                                                                                                                                                                                                  -314    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  -315        return (long)((nextDouble() - 0.5) * 2.0 * 0x7FFFFFFFFFFFFFFFL);
                                                                                                                                                                                                                                                                                                                  -316    }
                                                                                                                                                                                                                                                                                                                  -317
                                                                                                                                                                                                                                                                                                                  -318    /**
                                                                                                                                                                                                                                                                                                                  -319     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -320     * negative.
                                                                                                                                                                                                                                                                                                                  -321     *
                                                                                                                                                                                                                                                                                                                  -322     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -323     * @return the found number
                                                                                                                                                                                                                                                                                                                  -324     */
                                                                                                                                                                                                                                                                                                                  -325    @Override
                                                                                                                                                                                                                                                                                                                  -326        public long nextLong(long bound) {
                                                                                                                                                                                                                                                                                                                  -327        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  -328            return 0;
                                                                                                                                                                                                                                                                                                                  -329        }
                                                                                                                                                                                                                                                                                                                  -330        return (long)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -331    }
                                                                                                                                                                                                                                                                                                                  -332    /**
                                                                                                                                                                                                                                                                                                                  -333     * Gets the measure that this class uses for RNG fairness, defaulting to 0.54 (always between 0.0 and 1.0).
                                                                                                                                                                                                                                                                                                                  -334     * @return the current fairness metric.
                                                                                                                                                                                                                                                                                                                  -335     */
                                                                                                                                                                                                                                                                                                                  -336    public double getFairness() {
                                                                                                                                                                                                                                                                                                                  -337        return fairness;
                                                                                                                                                                                                                                                                                                                  -338    }
                                                                                                                                                                                                                                                                                                                  -339
                                                                                                                                                                                                                                                                                                                  -340    /**
                                                                                                                                                                                                                                                                                                                  -341     * Sets the measure that this class uses for RNG fairness, which must always be between 0.0 and 1.0, and will be
                                                                                                                                                                                                                                                                                                                  -342     * set to 0.54 if an invalid value is passed.
                                                                                                                                                                                                                                                                                                                  -343     * @param fairness the desired fairness metric, which must be 0.0 &lt;= fairness &lt; 1.0
                                                                                                                                                                                                                                                                                                                  -344     */
                                                                                                                                                                                                                                                                                                                  -345    public void setFairness(double fairness) {
                                                                                                                                                                                                                                                                                                                  -346        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  -347            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  -348        else
                                                                                                                                                                                                                                                                                                                  -349            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  -350    }
                                                                                                                                                                                                                                                                                                                  -351
                                                                                                                                                                                                                                                                                                                  -352    /**
                                                                                                                                                                                                                                                                                                                  -353     * Gets the status of the fortune used when calculating fairness adjustments.
                                                                                                                                                                                                                                                                                                                  -354     * @return the current value used to determine whether the results should be adjusted toward fairness.
                                                                                                                                                                                                                                                                                                                  -355     */
                                                                                                                                                                                                                                                                                                                  -356    public double getFortune()
                                                                                                                                                                                                                                                                                                                  -357    {
                                                                                                                                                                                                                                                                                                                  -358        return Math.abs(produced - baseline);
                                                                                                                                                                                                                                                                                                                  -359    }
                                                                                                                                                                                                                                                                                                                  -360
                                                                                                                                                                                                                                                                                                                  -361    /**
                                                                                                                                                                                                                                                                                                                  -362     * Resets the stored history this RNG uses to try to ensure fairness.
                                                                                                                                                                                                                                                                                                                  -363     */
                                                                                                                                                                                                                                                                                                                  -364    public void resetFortune()
                                                                                                                                                                                                                                                                                                                  -365    {
                                                                                                                                                                                                                                                                                                                  -366        produced = 0.0;
                                                                                                                                                                                                                                                                                                                  -367        baseline = 0.0;
                                                                                                                                                                                                                                                                                                                  -368    }
                                                                                                                                                                                                                                                                                                                  -369    /**
                                                                                                                                                                                                                                                                                                                  -370     *
                                                                                                                                                                                                                                                                                                                  -371     * @param bits the number of bits to be returned
                                                                                                                                                                                                                                                                                                                  -372     * @return a random int of the number of bits specified.
                                                                                                                                                                                                                                                                                                                  -373     */
                                                                                                                                                                                                                                                                                                                  -374    @Override
                                                                                                                                                                                                                                                                                                                  -375    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  -376        if(bits <= 0)
                                                                                                                                                                                                                                                                                                                  -377            return 0;
                                                                                                                                                                                                                                                                                                                  -378        if(bits > 32)
                                                                                                                                                                                                                                                                                                                  -379            bits = 32;
                                                                                                                                                                                                                                                                                                                  -380        return (int)(nextDouble() * (1l << bits));
                                                                                                                                                                                                                                                                                                                  -381
                                                                                                                                                                                                                                                                                                                  -382    }
                                                                                                                                                                                                                                                                                                                  -383
                                                                                                                                                                                                                                                                                                                  -384    @Override
                                                                                                                                                                                                                                                                                                                  -385    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  -386        return super.asRandom();
                                                                                                                                                                                                                                                                                                                  -387    }
                                                                                                                                                                                                                                                                                                                  -388
                                                                                                                                                                                                                                                                                                                  -389    @Override
                                                                                                                                                                                                                                                                                                                  -390    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -391    public <T> List<T> randomRotation(List<T> l) {
                                                                                                                                                                                                                                                                                                                  -392        return super.randomRotation(l);
                                                                                                                                                                                                                                                                                                                  -393    }
                                                                                                                                                                                                                                                                                                                  -394
                                                                                                                                                                                                                                                                                                                  -395    @Override
                                                                                                                                                                                                                                                                                                                  -396    public <T> Iterable<T> getRandomStartIterable(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -397        return super.getRandomStartIterable(list);
                                                                                                                                                                                                                                                                                                                  -398    }
                                                                                                                                                                                                                                                                                                                  -399/*
                                                                                                                                                                                                                                                                                                                  -400    @Override
                                                                                                                                                                                                                                                                                                                  -401    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -402    public <T> T[] shuffle(T[] elements) {
                                                                                                                                                                                                                                                                                                                  -403        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  -404    }
                                                                                                                                                                                                                                                                                                                  -405*/
                                                                                                                                                                                                                                                                                                                  -406    @Override
                                                                                                                                                                                                                                                                                                                  -407    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  -408        return super.shuffle(elements, dest);
                                                                                                                                                                                                                                                                                                                  -409    }
                                                                                                                                                                                                                                                                                                                  -410
                                                                                                                                                                                                                                                                                                                  -411    @Override
                                                                                                                                                                                                                                                                                                                  -412    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  -413        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  -414    }
                                                                                                                                                                                                                                                                                                                  -415
                                                                                                                                                                                                                                                                                                                  -416    /**
                                                                                                                                                                                                                                                                                                                  -417     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -418     * <p>
                                                                                                                                                                                                                                                                                                                  -419     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -420     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -421     *
                                                                                                                                                                                                                                                                                                                  -422     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -423     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -424     * @return the found value
                                                                                                                                                                                                                                                                                                                  -425     */
                                                                                                                                                                                                                                                                                                                  -426    @Override
                                                                                                                                                                                                                                                                                                                  -427    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  -428        return min + nextLong(max - min);
                                                                                                                                                                                                                                                                                                                  -429    }
                                                                                                                                                                                                                                                                                                                  -430
                                                                                                                                                                                                                                                                                                                  -431    /**
                                                                                                                                                                                                                                                                                                                  -432     * Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays.
                                                                                                                                                                                                                                                                                                                  -433     * <br>
                                                                                                                                                                                                                                                                                                                  -434     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -435     *
                                                                                                                                                                                                                                                                                                                  -436     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -437     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  +090    /**
                                                                                                                                                                                                                                                                                                                  +091     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  +092     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  +093     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +094     *
                                                                                                                                                                                                                                                                                                                  +095     * @param seedString a String as a seed
                                                                                                                                                                                                                                                                                                                  +096     */
                                                                                                                                                                                                                                                                                                                  +097    public DharmaRNG(String seedString, double fairness) {
                                                                                                                                                                                                                                                                                                                  +098        super(seedString);
                                                                                                                                                                                                                                                                                                                  +099        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  +100            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  +101        else
                                                                                                                                                                                                                                                                                                                  +102            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  +103
                                                                                                                                                                                                                                                                                                                  +104    }
                                                                                                                                                                                                                                                                                                                  +105    /**
                                                                                                                                                                                                                                                                                                                  +106     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +107     *
                                                                                                                                                                                                                                                                                                                  +108     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  +109     */
                                                                                                                                                                                                                                                                                                                  +110    public DharmaRNG(final RandomnessSource rs) {
                                                                                                                                                                                                                                                                                                                  +111        super(rs);
                                                                                                                                                                                                                                                                                                                  +112    }
                                                                                                                                                                                                                                                                                                                  +113    /**
                                                                                                                                                                                                                                                                                                                  +114     * Construct a new DharmaRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +115     *
                                                                                                                                                                                                                                                                                                                  +116     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  +117     * @param fairness the desired fairness metric, which must be between 0.0 and 1.0
                                                                                                                                                                                                                                                                                                                  +118     */
                                                                                                                                                                                                                                                                                                                  +119    public DharmaRNG(final RandomnessSource rs, final double fairness) {
                                                                                                                                                                                                                                                                                                                  +120        super(rs);
                                                                                                                                                                                                                                                                                                                  +121        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  +122            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  +123        else
                                                                                                                                                                                                                                                                                                                  +124            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  +125    }
                                                                                                                                                                                                                                                                                                                  +126
                                                                                                                                                                                                                                                                                                                  +127    /**
                                                                                                                                                                                                                                                                                                                  +128     * Generate a random double, altering the result if recently generated results have been leaning
                                                                                                                                                                                                                                                                                                                  +129     * away from this class' fairness value.
                                                                                                                                                                                                                                                                                                                  +130     * @return a double between 0.0 (inclusive) and 1.0 (exclusive)
                                                                                                                                                                                                                                                                                                                  +131     */
                                                                                                                                                                                                                                                                                                                  +132    @Override
                                                                                                                                                                                                                                                                                                                  +133    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  +134        double gen = random.nextLong() * DOUBLE_UNIT;
                                                                                                                                                                                                                                                                                                                  +135        /*if(Math.abs((produced + gen) - (baseline + fairness)) > 1.5) {
                                                                                                                                                                                                                                                                                                                  +136            //do some reseeding here if possible
                                                                                                                                                                                                                                                                                                                  +137        }*/
                                                                                                                                                                                                                                                                                                                  +138        if(Math.abs((produced + gen) - (baseline + fairness)) > 0.5)
                                                                                                                                                                                                                                                                                                                  +139        {
                                                                                                                                                                                                                                                                                                                  +140            gen = (gen + fairness) / 2.0;
                                                                                                                                                                                                                                                                                                                  +141            produced *= 0.5;
                                                                                                                                                                                                                                                                                                                  +142            baseline *= 0.5;
                                                                                                                                                                                                                                                                                                                  +143            produced += gen;
                                                                                                                                                                                                                                                                                                                  +144            baseline += fairness;
                                                                                                                                                                                                                                                                                                                  +145            return gen;
                                                                                                                                                                                                                                                                                                                  +146        }
                                                                                                                                                                                                                                                                                                                  +147        else
                                                                                                                                                                                                                                                                                                                  +148        {
                                                                                                                                                                                                                                                                                                                  +149            produced += gen;
                                                                                                                                                                                                                                                                                                                  +150            baseline += fairness;
                                                                                                                                                                                                                                                                                                                  +151            return gen;
                                                                                                                                                                                                                                                                                                                  +152        }
                                                                                                                                                                                                                                                                                                                  +153    }
                                                                                                                                                                                                                                                                                                                  +154
                                                                                                                                                                                                                                                                                                                  +155    /**
                                                                                                                                                                                                                                                                                                                  +156     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +157     *
                                                                                                                                                                                                                                                                                                                  +158     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  +159     */
                                                                                                                                                                                                                                                                                                                  +160    @Override
                                                                                                                                                                                                                                                                                                                  +161    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  +162        return super.nextDouble(max);
                                                                                                                                                                                                                                                                                                                  +163    }
                                                                                                                                                                                                                                                                                                                  +164
                                                                                                                                                                                                                                                                                                                  +165    /**
                                                                                                                                                                                                                                                                                                                  +166     * Returns a value from a even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  +167     * (exclusive).
                                                                                                                                                                                                                                                                                                                  +168     *
                                                                                                                                                                                                                                                                                                                  +169     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +170     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +171     * @return the found value
                                                                                                                                                                                                                                                                                                                  +172     */
                                                                                                                                                                                                                                                                                                                  +173    @Override
                                                                                                                                                                                                                                                                                                                  +174    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  +175        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  +176    }
                                                                                                                                                                                                                                                                                                                  +177
                                                                                                                                                                                                                                                                                                                  +178    /**
                                                                                                                                                                                                                                                                                                                  +179     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +180     *
                                                                                                                                                                                                                                                                                                                  +181     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +182     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +183     *
                                                                                                                                                                                                                                                                                                                  +184     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +185     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +186     * @return the found value
                                                                                                                                                                                                                                                                                                                  +187     */
                                                                                                                                                                                                                                                                                                                  +188    @Override
                                                                                                                                                                                                                                                                                                                  +189    public int between(int min, int max)
                                                                                                                                                                                                                                                                                                                  +190    {
                                                                                                                                                                                                                                                                                                                  +191        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  +192    }
                                                                                                                                                                                                                                                                                                                  +193
                                                                                                                                                                                                                                                                                                                  +194    /**
                                                                                                                                                                                                                                                                                                                  +195     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  +196     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  +197     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  +198     *
                                                                                                                                                                                                                                                                                                                  +199     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +200     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +201     *
                                                                                                                                                                                                                                                                                                                  +202     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  +203     *
                                                                                                                                                                                                                                                                                                                  +204     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +205     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +206     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  +207     * @return the found value
                                                                                                                                                                                                                                                                                                                  +208     */
                                                                                                                                                                                                                                                                                                                  +209    @Override
                                                                                                                                                                                                                                                                                                                  +210    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  +211        return super.betweenWeighted(min, max, samples);
                                                                                                                                                                                                                                                                                                                  +212    }
                                                                                                                                                                                                                                                                                                                  +213
                                                                                                                                                                                                                                                                                                                  +214    /**
                                                                                                                                                                                                                                                                                                                  +215     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  +216     * type.
                                                                                                                                                                                                                                                                                                                  +217     *
                                                                                                                                                                                                                                                                                                                  +218     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +219     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  +220     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +221     */
                                                                                                                                                                                                                                                                                                                  +222    @Override
                                                                                                                                                                                                                                                                                                                  +223    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  +224        return super.getRandomElement(array);
                                                                                                                                                                                                                                                                                                                  +225    }
                                                                                                                                                                                                                                                                                                                  +226
                                                                                                                                                                                                                                                                                                                  +227    /**
                                                                                                                                                                                                                                                                                                                  +228     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  +229     * then null is returned.
                                                                                                                                                                                                                                                                                                                  +230     *
                                                                                                                                                                                                                                                                                                                  +231     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +232     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  +233     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +234     */
                                                                                                                                                                                                                                                                                                                  +235    @Override
                                                                                                                                                                                                                                                                                                                  +236    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  +237        return super.getRandomElement(list);
                                                                                                                                                                                                                                                                                                                  +238    }
                                                                                                                                                                                                                                                                                                                  +239
                                                                                                                                                                                                                                                                                                                  +240    /**
                                                                                                                                                                                                                                                                                                                  +241     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  +242     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  +243     *
                                                                                                                                                                                                                                                                                                                  +244     * <p>
                                                                                                                                                                                                                                                                                                                  +245     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  +246     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  +247     * </p>
                                                                                                                                                                                                                                                                                                                  +248     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  +249     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +250     */
                                                                                                                                                                                                                                                                                                                  +251    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  +252        return super.getRandomElement(set);
                                                                                                                                                                                                                                                                                                                  +253    }
                                                                                                                                                                                                                                                                                                                  +254
                                                                                                                                                                                                                                                                                                                  +255    /**
                                                                                                                                                                                                                                                                                                                  +256     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  +257     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  +258     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  +259     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  +260     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  +261     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  +262     *
                                                                                                                                                                                                                                                                                                                  +263     * <p>
                                                                                                                                                                                                                                                                                                                  +264     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  +265     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  +266     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  +267     * </p>
                                                                                                                                                                                                                                                                                                                  +268     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +269     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  +270     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +271     */
                                                                                                                                                                                                                                                                                                                  +272    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  +273        return super.getRandomElement(coll);
                                                                                                                                                                                                                                                                                                                  +274    }
                                                                                                                                                                                                                                                                                                                  +275
                                                                                                                                                                                                                                                                                                                  +276    /**
                                                                                                                                                                                                                                                                                                                  +277     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  +278     */
                                                                                                                                                                                                                                                                                                                  +279    @Override
                                                                                                                                                                                                                                                                                                                  +280    public synchronized double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  +281        return super.nextGaussian();
                                                                                                                                                                                                                                                                                                                  +282    }
                                                                                                                                                                                                                                                                                                                  +283    /**
                                                                                                                                                                                                                                                                                                                  +284     * Returns a random integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +285     * negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  +286     *
                                                                                                                                                                                                                                                                                                                  +287     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +288     * @return the found number
                                                                                                                                                                                                                                                                                                                  +289     */
                                                                                                                                                                                                                                                                                                                  +290    @Override
                                                                                                                                                                                                                                                                                                                  +291    public int nextInt(int bound) {
                                                                                                                                                                                                                                                                                                                  +292        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  +293            return 0;
                                                                                                                                                                                                                                                                                                                  +294        }
                                                                                                                                                                                                                                                                                                                  +295
                                                                                                                                                                                                                                                                                                                  +296        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +297    }
                                                                                                                                                                                                                                                                                                                  +298
                                                                                                                                                                                                                                                                                                                  +299    /**
                                                                                                                                                                                                                                                                                                                  +300     * Returns a random integer, which may be positive or negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  +301     * @return A random int
                                                                                                                                                                                                                                                                                                                  +302     */
                                                                                                                                                                                                                                                                                                                  +303    @Override
                                                                                                                                                                                                                                                                                                                  +304    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  +305        return (int)((nextDouble() - 0.5) * 2.0 * 0x7FFFFFFF);
                                                                                                                                                                                                                                                                                                                  +306    }
                                                                                                                                                                                                                                                                                                                  +307
                                                                                                                                                                                                                                                                                                                  +308    /**
                                                                                                                                                                                                                                                                                                                  +309     * Returns a random long, which may be positive or negative. Affects the current fortune.
                                                                                                                                                                                                                                                                                                                  +310     * @return A random long
                                                                                                                                                                                                                                                                                                                  +311     */
                                                                                                                                                                                                                                                                                                                  +312    @Override
                                                                                                                                                                                                                                                                                                                  +313    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  +314        return (long)((nextDouble() - 0.5) * 2.0 * 0x7FFFFFFFFFFFFFFFL);
                                                                                                                                                                                                                                                                                                                  +315    }
                                                                                                                                                                                                                                                                                                                  +316
                                                                                                                                                                                                                                                                                                                  +317    /**
                                                                                                                                                                                                                                                                                                                  +318     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +319     * negative.
                                                                                                                                                                                                                                                                                                                  +320     *
                                                                                                                                                                                                                                                                                                                  +321     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +322     * @return the found number
                                                                                                                                                                                                                                                                                                                  +323     */
                                                                                                                                                                                                                                                                                                                  +324    @Override
                                                                                                                                                                                                                                                                                                                  +325        public long nextLong(long bound) {
                                                                                                                                                                                                                                                                                                                  +326        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  +327            return 0;
                                                                                                                                                                                                                                                                                                                  +328        }
                                                                                                                                                                                                                                                                                                                  +329        return (long)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +330    }
                                                                                                                                                                                                                                                                                                                  +331    /**
                                                                                                                                                                                                                                                                                                                  +332     * Gets the measure that this class uses for RNG fairness, defaulting to 0.54 (always between 0.0 and 1.0).
                                                                                                                                                                                                                                                                                                                  +333     * @return the current fairness metric.
                                                                                                                                                                                                                                                                                                                  +334     */
                                                                                                                                                                                                                                                                                                                  +335    public double getFairness() {
                                                                                                                                                                                                                                                                                                                  +336        return fairness;
                                                                                                                                                                                                                                                                                                                  +337    }
                                                                                                                                                                                                                                                                                                                  +338
                                                                                                                                                                                                                                                                                                                  +339    /**
                                                                                                                                                                                                                                                                                                                  +340     * Sets the measure that this class uses for RNG fairness, which must always be between 0.0 and 1.0, and will be
                                                                                                                                                                                                                                                                                                                  +341     * set to 0.54 if an invalid value is passed.
                                                                                                                                                                                                                                                                                                                  +342     * @param fairness the desired fairness metric, which must be 0.0 &lt;= fairness &lt; 1.0
                                                                                                                                                                                                                                                                                                                  +343     */
                                                                                                                                                                                                                                                                                                                  +344    public void setFairness(double fairness) {
                                                                                                                                                                                                                                                                                                                  +345        if(fairness < 0.0 || fairness >= 1.0)
                                                                                                                                                                                                                                                                                                                  +346            this.fairness = 0.54;
                                                                                                                                                                                                                                                                                                                  +347        else
                                                                                                                                                                                                                                                                                                                  +348            this.fairness = fairness;
                                                                                                                                                                                                                                                                                                                  +349    }
                                                                                                                                                                                                                                                                                                                  +350
                                                                                                                                                                                                                                                                                                                  +351    /**
                                                                                                                                                                                                                                                                                                                  +352     * Gets the status of the fortune used when calculating fairness adjustments.
                                                                                                                                                                                                                                                                                                                  +353     * @return the current value used to determine whether the results should be adjusted toward fairness.
                                                                                                                                                                                                                                                                                                                  +354     */
                                                                                                                                                                                                                                                                                                                  +355    public double getFortune()
                                                                                                                                                                                                                                                                                                                  +356    {
                                                                                                                                                                                                                                                                                                                  +357        return Math.abs(produced - baseline);
                                                                                                                                                                                                                                                                                                                  +358    }
                                                                                                                                                                                                                                                                                                                  +359
                                                                                                                                                                                                                                                                                                                  +360    /**
                                                                                                                                                                                                                                                                                                                  +361     * Resets the stored history this RNG uses to try to ensure fairness.
                                                                                                                                                                                                                                                                                                                  +362     */
                                                                                                                                                                                                                                                                                                                  +363    public void resetFortune()
                                                                                                                                                                                                                                                                                                                  +364    {
                                                                                                                                                                                                                                                                                                                  +365        produced = 0.0;
                                                                                                                                                                                                                                                                                                                  +366        baseline = 0.0;
                                                                                                                                                                                                                                                                                                                  +367    }
                                                                                                                                                                                                                                                                                                                  +368    /**
                                                                                                                                                                                                                                                                                                                  +369     *
                                                                                                                                                                                                                                                                                                                  +370     * @param bits the number of bits to be returned
                                                                                                                                                                                                                                                                                                                  +371     * @return a random int of the number of bits specified.
                                                                                                                                                                                                                                                                                                                  +372     */
                                                                                                                                                                                                                                                                                                                  +373    @Override
                                                                                                                                                                                                                                                                                                                  +374    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  +375        if(bits <= 0)
                                                                                                                                                                                                                                                                                                                  +376            return 0;
                                                                                                                                                                                                                                                                                                                  +377        if(bits > 32)
                                                                                                                                                                                                                                                                                                                  +378            bits = 32;
                                                                                                                                                                                                                                                                                                                  +379        return (int)(nextDouble() * (1l << bits));
                                                                                                                                                                                                                                                                                                                  +380
                                                                                                                                                                                                                                                                                                                  +381    }
                                                                                                                                                                                                                                                                                                                  +382
                                                                                                                                                                                                                                                                                                                  +383    /**
                                                                                                                                                                                                                                                                                                                  +384     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +385     * <p>
                                                                                                                                                                                                                                                                                                                  +386     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +387     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +388     *
                                                                                                                                                                                                                                                                                                                  +389     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +390     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +391     * @return the found value
                                                                                                                                                                                                                                                                                                                  +392     */
                                                                                                                                                                                                                                                                                                                  +393    @Override
                                                                                                                                                                                                                                                                                                                  +394    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  +395        return min + nextLong(max - min);
                                                                                                                                                                                                                                                                                                                  +396    }
                                                                                                                                                                                                                                                                                                                  +397
                                                                                                                                                                                                                                                                                                                  +398    /**
                                                                                                                                                                                                                                                                                                                  +399     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  +400     * Uses a slightly optimized technique. This method is considered "hasty" since
                                                                                                                                                                                                                                                                                                                  +401     * it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also
                                                                                                                                                                                                                                                                                                                  +402     * has undefined behavior if bound is negative, though it will probably produce a negative
                                                                                                                                                                                                                                                                                                                  +403     * number (just how negative is an open question).
                                                                                                                                                                                                                                                                                                                  +404     *
                                                                                                                                                                                                                                                                                                                  +405     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  +406     * @return the found number
                                                                                                                                                                                                                                                                                                                  +407     */
                                                                                                                                                                                                                                                                                                                  +408    @Override
                                                                                                                                                                                                                                                                                                                  +409    public int nextIntHasty(int bound) {
                                                                                                                                                                                                                                                                                                                  +410        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +411    }
                                                                                                                                                                                                                                                                                                                  +412
                                                                                                                                                                                                                                                                                                                  +413    @Override
                                                                                                                                                                                                                                                                                                                  +414    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  +415        return (float)nextDouble();
                                                                                                                                                                                                                                                                                                                  +416    }
                                                                                                                                                                                                                                                                                                                  +417
                                                                                                                                                                                                                                                                                                                  +418    @Override
                                                                                                                                                                                                                                                                                                                  +419    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  +420        return nextDouble() >= 0.5;
                                                                                                                                                                                                                                                                                                                  +421    }
                                                                                                                                                                                                                                                                                                                  +422
                                                                                                                                                                                                                                                                                                                  +423    @Override
                                                                                                                                                                                                                                                                                                                  +424    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  +425        return random;
                                                                                                                                                                                                                                                                                                                  +426    }
                                                                                                                                                                                                                                                                                                                  +427
                                                                                                                                                                                                                                                                                                                  +428    @Override
                                                                                                                                                                                                                                                                                                                  +429    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +430        this.random = random;
                                                                                                                                                                                                                                                                                                                  +431    }
                                                                                                                                                                                                                                                                                                                  +432
                                                                                                                                                                                                                                                                                                                  +433    /**
                                                                                                                                                                                                                                                                                                                  +434     * Creates a copy of this DharmaRNG; it will generate the same random numbers, given the same calls in order, as
                                                                                                                                                                                                                                                                                                                  +435     * this DharmaRNG at the point copy() is called. The copy will not share references with this DharmaRNG.
                                                                                                                                                                                                                                                                                                                  +436     *
                                                                                                                                                                                                                                                                                                                  +437     * @return a copy of this DharmaRNG
                                                                                                                                                                                                                                                                                                                   438     */
                                                                                                                                                                                                                                                                                                                  -439    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -440    @Override
                                                                                                                                                                                                                                                                                                                  -441    public <T> T[] shuffle(T[] elements) {
                                                                                                                                                                                                                                                                                                                  -442        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  -443    }
                                                                                                                                                                                                                                                                                                                  -444
                                                                                                                                                                                                                                                                                                                  -445    /**
                                                                                                                                                                                                                                                                                                                  -446     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  -447     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  -448     *
                                                                                                                                                                                                                                                                                                                  -449     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  -450     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  -451     */
                                                                                                                                                                                                                                                                                                                  -452    @Override
                                                                                                                                                                                                                                                                                                                  -453    public int[] randomOrdering(int length) {
                                                                                                                                                                                                                                                                                                                  -454        return super.randomOrdering(length);
                                                                                                                                                                                                                                                                                                                  -455    }
                                                                                                                                                                                                                                                                                                                  -456
                                                                                                                                                                                                                                                                                                                  -457
                                                                                                                                                                                                                                                                                                                  -458    /**
                                                                                                                                                                                                                                                                                                                  -459     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  -460     * Uses a slightly optimized technique. This method is considered "hasty" since
                                                                                                                                                                                                                                                                                                                  -461     * it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also
                                                                                                                                                                                                                                                                                                                  -462     * has undefined behavior if bound is negative, though it will probably produce a negative
                                                                                                                                                                                                                                                                                                                  -463     * number (just how negative is an open question).
                                                                                                                                                                                                                                                                                                                  -464     *
                                                                                                                                                                                                                                                                                                                  -465     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  -466     * @return the found number
                                                                                                                                                                                                                                                                                                                  -467     */
                                                                                                                                                                                                                                                                                                                  -468    @Override
                                                                                                                                                                                                                                                                                                                  -469    public int nextIntHasty(int bound) {
                                                                                                                                                                                                                                                                                                                  -470        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -471    }
                                                                                                                                                                                                                                                                                                                  -472
                                                                                                                                                                                                                                                                                                                  +439    @Override
                                                                                                                                                                                                                                                                                                                  +440    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  +441        DharmaRNG next = new DharmaRNG(random.copy(), fairness);
                                                                                                                                                                                                                                                                                                                  +442        next.produced = produced;
                                                                                                                                                                                                                                                                                                                  +443        next.baseline = baseline;
                                                                                                                                                                                                                                                                                                                  +444        return next;
                                                                                                                                                                                                                                                                                                                  +445    }
                                                                                                                                                                                                                                                                                                                  +446
                                                                                                                                                                                                                                                                                                                  +447    /**
                                                                                                                                                                                                                                                                                                                  +448     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  +449     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  +450     * shuffling a copy of data and getting a section of it that matches the length of output.
                                                                                                                                                                                                                                                                                                                  +451     *
                                                                                                                                                                                                                                                                                                                  +452     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  +453     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  +454     * @param data an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +455     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  +456     * @param <T> can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +457     * @return an array of T that has length equal to output's length and may contain null elements if output is shorter
                                                                                                                                                                                                                                                                                                                  +458     * than data
                                                                                                                                                                                                                                                                                                                  +459     */
                                                                                                                                                                                                                                                                                                                  +460    @Override
                                                                                                                                                                                                                                                                                                                  +461    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  +462        return super.randomPortion(data, output);
                                                                                                                                                                                                                                                                                                                  +463    }
                                                                                                                                                                                                                                                                                                                  +464
                                                                                                                                                                                                                                                                                                                  +465    /**
                                                                                                                                                                                                                                                                                                                  +466     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  +467     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  +468     *
                                                                                                                                                                                                                                                                                                                  +469     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +470     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  +471     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  +472     */
                                                                                                                                                                                                                                                                                                                   473    @Override
                                                                                                                                                                                                                                                                                                                  -474    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  -475        return (float)nextDouble();
                                                                                                                                                                                                                                                                                                                  +474    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  +475        return super.randomPortion(data, count);
                                                                                                                                                                                                                                                                                                                   476    }
                                                                                                                                                                                                                                                                                                                   477
                                                                                                                                                                                                                                                                                                                  -478    @Override
                                                                                                                                                                                                                                                                                                                  -479    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  -480        return nextDouble() >= 0.5;
                                                                                                                                                                                                                                                                                                                  -481    }
                                                                                                                                                                                                                                                                                                                  -482
                                                                                                                                                                                                                                                                                                                  -483    @Override
                                                                                                                                                                                                                                                                                                                  -484    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  -485        return random;
                                                                                                                                                                                                                                                                                                                  -486    }
                                                                                                                                                                                                                                                                                                                  -487
                                                                                                                                                                                                                                                                                                                  -488    @Override
                                                                                                                                                                                                                                                                                                                  -489    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -490        this.random = random;
                                                                                                                                                                                                                                                                                                                  -491    }
                                                                                                                                                                                                                                                                                                                  -492
                                                                                                                                                                                                                                                                                                                  -493    /**
                                                                                                                                                                                                                                                                                                                  -494     * Creates a copy of this DharmaRNG; it will generate the same random numbers, given the same calls in order, as
                                                                                                                                                                                                                                                                                                                  -495     * this DharmaRNG at the point copy() is called. The copy will not share references with this DharmaRNG.
                                                                                                                                                                                                                                                                                                                  -496     *
                                                                                                                                                                                                                                                                                                                  -497     * @return a copy of this DharmaRNG
                                                                                                                                                                                                                                                                                                                  -498     */
                                                                                                                                                                                                                                                                                                                  -499    @Override
                                                                                                                                                                                                                                                                                                                  -500    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  -501        DharmaRNG next = new DharmaRNG(random.copy(), fairness);
                                                                                                                                                                                                                                                                                                                  -502        next.produced = produced;
                                                                                                                                                                                                                                                                                                                  -503        next.baseline = baseline;
                                                                                                                                                                                                                                                                                                                  -504        return next;
                                                                                                                                                                                                                                                                                                                  -505    }
                                                                                                                                                                                                                                                                                                                  +478    /**
                                                                                                                                                                                                                                                                                                                  +479     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  +480     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  +481     *
                                                                                                                                                                                                                                                                                                                  +482     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  +483     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  +484     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  +485     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  +486     */
                                                                                                                                                                                                                                                                                                                  +487    @Override
                                                                                                                                                                                                                                                                                                                  +488    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  +489        return super.randomRange(start, end, count);
                                                                                                                                                                                                                                                                                                                  +490    }
                                                                                                                                                                                                                                                                                                                  +491
                                                                                                                                                                                                                                                                                                                  +492    @Override
                                                                                                                                                                                                                                                                                                                  +493    public String toString() {
                                                                                                                                                                                                                                                                                                                  +494        return "DharmaRNG{" +
                                                                                                                                                                                                                                                                                                                  +495                "fairness=" + fairness +
                                                                                                                                                                                                                                                                                                                  +496                ", produced=" + produced +
                                                                                                                                                                                                                                                                                                                  +497                ", baseline=" + baseline +
                                                                                                                                                                                                                                                                                                                  +498                ", Randomness Source=" + random +
                                                                                                                                                                                                                                                                                                                  +499                '}';
                                                                                                                                                                                                                                                                                                                  +500    }
                                                                                                                                                                                                                                                                                                                  +501
                                                                                                                                                                                                                                                                                                                  +502    @Override
                                                                                                                                                                                                                                                                                                                  +503    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  +504        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  +505        if (o == null || getClass() != o.getClass()) return false;
                                                                                                                                                                                                                                                                                                                   506
                                                                                                                                                                                                                                                                                                                  -507    /**
                                                                                                                                                                                                                                                                                                                  -508     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  -509     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  -510     * shuffling a copy of data and getting a section of it that matches the length of output.
                                                                                                                                                                                                                                                                                                                  -511     *
                                                                                                                                                                                                                                                                                                                  -512     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  -513     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  -514     * @param data an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -515     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  -516     * @param <T> can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -517     * @return an array of T that has length equal to output's length and may contain null elements if output is shorter
                                                                                                                                                                                                                                                                                                                  -518     * than data
                                                                                                                                                                                                                                                                                                                  -519     */
                                                                                                                                                                                                                                                                                                                  -520    @Override
                                                                                                                                                                                                                                                                                                                  -521    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  -522        return super.randomPortion(data, output);
                                                                                                                                                                                                                                                                                                                  -523    }
                                                                                                                                                                                                                                                                                                                  -524
                                                                                                                                                                                                                                                                                                                  -525    /**
                                                                                                                                                                                                                                                                                                                  -526     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  -527     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  -528     *
                                                                                                                                                                                                                                                                                                                  -529     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -530     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  -531     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  -532     */
                                                                                                                                                                                                                                                                                                                  -533    @Override
                                                                                                                                                                                                                                                                                                                  -534    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  -535        return super.randomPortion(data, count);
                                                                                                                                                                                                                                                                                                                  -536    }
                                                                                                                                                                                                                                                                                                                  -537
                                                                                                                                                                                                                                                                                                                  -538    /**
                                                                                                                                                                                                                                                                                                                  -539     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  -540     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  -541     *
                                                                                                                                                                                                                                                                                                                  -542     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  -543     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  -544     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  -545     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  -546     */
                                                                                                                                                                                                                                                                                                                  -547    @Override
                                                                                                                                                                                                                                                                                                                  -548    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  -549        return super.randomRange(start, end, count);
                                                                                                                                                                                                                                                                                                                  -550    }
                                                                                                                                                                                                                                                                                                                  -551
                                                                                                                                                                                                                                                                                                                  -552    @Override
                                                                                                                                                                                                                                                                                                                  -553    public String toString() {
                                                                                                                                                                                                                                                                                                                  -554        return "DharmaRNG{" +
                                                                                                                                                                                                                                                                                                                  -555                "fairness=" + fairness +
                                                                                                                                                                                                                                                                                                                  -556                ", produced=" + produced +
                                                                                                                                                                                                                                                                                                                  -557                ", baseline=" + baseline +
                                                                                                                                                                                                                                                                                                                  -558                ", Randomness Source=" + random +
                                                                                                                                                                                                                                                                                                                  -559                '}';
                                                                                                                                                                                                                                                                                                                  -560    }
                                                                                                                                                                                                                                                                                                                  -561
                                                                                                                                                                                                                                                                                                                  -562    @Override
                                                                                                                                                                                                                                                                                                                  -563    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  -564        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  -565        if (o == null || getClass() != o.getClass()) return false;
                                                                                                                                                                                                                                                                                                                  -566
                                                                                                                                                                                                                                                                                                                  -567        DharmaRNG dharmaRNG = (DharmaRNG) o;
                                                                                                                                                                                                                                                                                                                  -568
                                                                                                                                                                                                                                                                                                                  -569        if (Double.compare(dharmaRNG.fairness, fairness) != 0) return false;
                                                                                                                                                                                                                                                                                                                  -570        return Double.compare(dharmaRNG.produced, produced) == 0 && Double.compare(dharmaRNG.baseline, baseline) == 0;
                                                                                                                                                                                                                                                                                                                  -571
                                                                                                                                                                                                                                                                                                                  -572    }
                                                                                                                                                                                                                                                                                                                  -573
                                                                                                                                                                                                                                                                                                                  -574    @Override
                                                                                                                                                                                                                                                                                                                  -575    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  -576        int result;
                                                                                                                                                                                                                                                                                                                  -577        long temp;
                                                                                                                                                                                                                                                                                                                  -578        temp = NumberTools.doubleToLongBits(fairness);
                                                                                                                                                                                                                                                                                                                  -579        result = (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  -580        temp = NumberTools.doubleToLongBits(produced);
                                                                                                                                                                                                                                                                                                                  -581        result = 31 * result + (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  -582        temp = NumberTools.doubleToLongBits(baseline);
                                                                                                                                                                                                                                                                                                                  -583        result = 31 * result + (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  -584        return result;
                                                                                                                                                                                                                                                                                                                  -585    }
                                                                                                                                                                                                                                                                                                                  -586}
                                                                                                                                                                                                                                                                                                                  +507        DharmaRNG dharmaRNG = (DharmaRNG) o;
                                                                                                                                                                                                                                                                                                                  +508
                                                                                                                                                                                                                                                                                                                  +509        if (Double.compare(dharmaRNG.fairness, fairness) != 0) return false;
                                                                                                                                                                                                                                                                                                                  +510        return Double.compare(dharmaRNG.produced, produced) == 0 && Double.compare(dharmaRNG.baseline, baseline) == 0;
                                                                                                                                                                                                                                                                                                                  +511
                                                                                                                                                                                                                                                                                                                  +512    }
                                                                                                                                                                                                                                                                                                                  +513
                                                                                                                                                                                                                                                                                                                  +514    @Override
                                                                                                                                                                                                                                                                                                                  +515    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  +516        int result;
                                                                                                                                                                                                                                                                                                                  +517        long temp;
                                                                                                                                                                                                                                                                                                                  +518        temp = NumberTools.doubleToLongBits(fairness);
                                                                                                                                                                                                                                                                                                                  +519        result = (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  +520        temp = NumberTools.doubleToLongBits(produced);
                                                                                                                                                                                                                                                                                                                  +521        result = 31 * result + (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  +522        temp = NumberTools.doubleToLongBits(baseline);
                                                                                                                                                                                                                                                                                                                  +523        result = 31 * result + (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  +524        return result;
                                                                                                                                                                                                                                                                                                                  +525    }
                                                                                                                                                                                                                                                                                                                  +526}
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/EditRNG.html b/docs/squidlib-util/src-html/squidpony/squidmath/EditRNG.html
                                                                                                                                                                                                                                                                                                                  index 7db5c48972..5c024f7d2a 100644
                                                                                                                                                                                                                                                                                                                  --- a/docs/squidlib-util/src-html/squidpony/squidmath/EditRNG.html
                                                                                                                                                                                                                                                                                                                  +++ b/docs/squidlib-util/src-html/squidpony/squidmath/EditRNG.html
                                                                                                                                                                                                                                                                                                                  @@ -8,674 +8,615 @@
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  001package squidpony.squidmath;
                                                                                                                                                                                                                                                                                                                   002
                                                                                                                                                                                                                                                                                                                  -003import squidpony.annotation.GwtIncompatible;
                                                                                                                                                                                                                                                                                                                  -004
                                                                                                                                                                                                                                                                                                                  -005import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  -006import java.util.ArrayList;
                                                                                                                                                                                                                                                                                                                  -007import java.util.Collection;
                                                                                                                                                                                                                                                                                                                  -008import java.util.List;
                                                                                                                                                                                                                                                                                                                  -009import java.util.Random;
                                                                                                                                                                                                                                                                                                                  -010
                                                                                                                                                                                                                                                                                                                  -011/**
                                                                                                                                                                                                                                                                                                                  -012 * A subclass of StatefulRNG (and thus RNG) that allows customizing many parts of the random number generation.
                                                                                                                                                                                                                                                                                                                  -013 * This is meant to be a more comprehensible version of the functionality present in RandomBias, and also for it to be
                                                                                                                                                                                                                                                                                                                  -014 * easier to use with methods that expect an RNG.
                                                                                                                                                                                                                                                                                                                  -015 * <br>
                                                                                                                                                                                                                                                                                                                  -016 * You can change the expected average for the values this produces, which uses the RandomBias.EXPONENTIAL distribution,
                                                                                                                                                                                                                                                                                                                  -017 * with all the caveats it has: it strongly favors either high or low values when the average gets especially high or
                                                                                                                                                                                                                                                                                                                  -018 * low, but it can essentially cover all averages between 0.0 and 1.0 (this class limits it to 0.1 and 0.9, so other
                                                                                                                                                                                                                                                                                                                  -019 * techniques can be used effectively).
                                                                                                                                                                                                                                                                                                                  -020 * <br>
                                                                                                                                                                                                                                                                                                                  -021 * You can also affect the "centrality" of random numbers, causing more to occur near the expected average (a bell curve
                                                                                                                                                                                                                                                                                                                  -022 * effect), or cause more near extreme ends of the random number spectrum. In practice, centrality changes are hard to
                                                                                                                                                                                                                                                                                                                  -023 * notice, but may be useful to simulate certain effects. An example of centrality changes in existing games include the
                                                                                                                                                                                                                                                                                                                  -024 * Nintendo title Advance Wars 2, where a brutish commander could increase the amount of damage his units dealt but also
                                                                                                                                                                                                                                                                                                                  -025 * suffered unpredictability; attacks could deal even more or much less damage than normal without any way to build
                                                                                                                                                                                                                                                                                                                  -026 * tactics around it. Square Enix's Final Fantasy XII also notably differentiated certain weapons (axes, hammers, and
                                                                                                                                                                                                                                                                                                                  -027 * "hand-cannons") from other similar options by making them deal less predictable damage. In both cases the connotation
                                                                                                                                                                                                                                                                                                                  -028 * is that more randomness is fitting for a brute-force approach to combat where pre-planned strategies are less
                                                                                                                                                                                                                                                                                                                  -029 * emphasized. It should also be noted that increasing the frequency of extreme results makes small bonuses to defense
                                                                                                                                                                                                                                                                                                                  -030 * or offense typically less useful, and small penalties less harmful. The opposite can be true for a carefully tuned
                                                                                                                                                                                                                                                                                                                  -031 * game where the most common results are tightly clustered, and most target numbers are just slightly above the
                                                                                                                                                                                                                                                                                                                  -032 * ordinary average. In tabletop games, 1d20 and 3d6 have the same average, but 1d20 is uniform, where 3d6 is clustered
                                                                                                                                                                                                                                                                                                                  -033 * around 10 and 11, each the result of 1/8 of rolls on their own and 1/4 together. This makes the case where a +1 bonus
                                                                                                                                                                                                                                                                                                                  -034 * to succeed changes the outcome on approximately 5% of 1d20 rolls, regardless of the required number to succeed if it
                                                                                                                                                                                                                                                                                                                  -035 * is less than 20. However, a +1 bonus matters on a variable portion of 3d6 rolls; if you become able to succeed on a
                                                                                                                                                                                                                                                                                                                  -036 * 10 or 11 where that was a failure before, the bonus applies approximately 12.5% of the time. Becoming able to succeed
                                                                                                                                                                                                                                                                                                                  -037 * on an 18 where that was a failure before is essentially worthless, affecting less than 0.5% of rolls. This property
                                                                                                                                                                                                                                                                                                                  -038 * of centralized results should be considered if game balance and/or the lethality of combat is important. One lengthy
                                                                                                                                                                                                                                                                                                                  -039 * stretch of extreme results by enemies that work against the favor of a player character generally result in a dead
                                                                                                                                                                                                                                                                                                                  -040 * player character, and RNGs that make extreme results more common may seem particularly cruel to players.
                                                                                                                                                                                                                                                                                                                  -041 * <br>
                                                                                                                                                                                                                                                                                                                  -042 * This generator sets a field, rawLatest, every time a random number is produced. This stores a pseudo-random double
                                                                                                                                                                                                                                                                                                                  -043 * between 0.0 (inclusive) and 1.0 (exclusive) that is not subject to the bias an expected average introduces, and is
                                                                                                                                                                                                                                                                                                                  -044 * close to uniformly distributed. You should expect rawLatest to be higher when higher numbers are returned from a
                                                                                                                                                                                                                                                                                                                  -045 * method like nextInt(), and lower when lower numbers are returned. This can be useful for rare effects that should not
                                                                                                                                                                                                                                                                                                                  -046 * be drastically more or less likely when slight changes are made to the expected average; if the expected average is
                                                                                                                                                                                                                                                                                                                  -047 * 0.65, many more random doubles from nextDouble() will be between 0.95 and 1.0 (probably more than 10% of random
                                                                                                                                                                                                                                                                                                                  -048 * numbers), but rawLatest will only be between 0.95 and 1.0 for close to 5% of all generations.
                                                                                                                                                                                                                                                                                                                  -049 * <br>
                                                                                                                                                                                                                                                                                                                  -050 * You can get and set the state this uses internally, and this is stored as a 64-bit long.
                                                                                                                                                                                                                                                                                                                  +003import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  +004import java.util.Collection;
                                                                                                                                                                                                                                                                                                                  +005import java.util.List;
                                                                                                                                                                                                                                                                                                                  +006
                                                                                                                                                                                                                                                                                                                  +007/**
                                                                                                                                                                                                                                                                                                                  +008 * A subclass of StatefulRNG (and thus RNG) that allows customizing many parts of the random number generation.
                                                                                                                                                                                                                                                                                                                  +009 * This is meant to be a more comprehensible version of the functionality present in RandomBias, and also for it to be
                                                                                                                                                                                                                                                                                                                  +010 * easier to use with methods that expect an RNG.
                                                                                                                                                                                                                                                                                                                  +011 * <br>
                                                                                                                                                                                                                                                                                                                  +012 * You can change the expected average for the values this produces, which uses the RandomBias.EXPONENTIAL distribution,
                                                                                                                                                                                                                                                                                                                  +013 * with all the caveats it has: it strongly favors either high or low values when the average gets especially high or
                                                                                                                                                                                                                                                                                                                  +014 * low, but it can essentially cover all averages between 0.0 and 1.0 (this class limits it to 0.1 and 0.9, so other
                                                                                                                                                                                                                                                                                                                  +015 * techniques can be used effectively).
                                                                                                                                                                                                                                                                                                                  +016 * <br>
                                                                                                                                                                                                                                                                                                                  +017 * You can also affect the "centrality" of random numbers, causing more to occur near the expected average (a bell curve
                                                                                                                                                                                                                                                                                                                  +018 * effect), or cause more near extreme ends of the random number spectrum. In practice, centrality changes are hard to
                                                                                                                                                                                                                                                                                                                  +019 * notice, but may be useful to simulate certain effects. An example of centrality changes in existing games include the
                                                                                                                                                                                                                                                                                                                  +020 * Nintendo title Advance Wars 2, where a brutish commander could increase the amount of damage his units dealt but also
                                                                                                                                                                                                                                                                                                                  +021 * suffered unpredictability; attacks could deal even more or much less damage than normal without any way to build
                                                                                                                                                                                                                                                                                                                  +022 * tactics around it. Square Enix's Final Fantasy XII also notably differentiated certain weapons (axes, hammers, and
                                                                                                                                                                                                                                                                                                                  +023 * "hand-cannons") from other similar options by making them deal less predictable damage. In both cases the connotation
                                                                                                                                                                                                                                                                                                                  +024 * is that more randomness is fitting for a brute-force approach to combat where pre-planned strategies are less
                                                                                                                                                                                                                                                                                                                  +025 * emphasized. It should also be noted that increasing the frequency of extreme results makes small bonuses to defense
                                                                                                                                                                                                                                                                                                                  +026 * or offense typically less useful, and small penalties less harmful. The opposite can be true for a carefully tuned
                                                                                                                                                                                                                                                                                                                  +027 * game where the most common results are tightly clustered, and most target numbers are just slightly above the
                                                                                                                                                                                                                                                                                                                  +028 * ordinary average. In tabletop games, 1d20 and 3d6 have the same average, but 1d20 is uniform, where 3d6 is clustered
                                                                                                                                                                                                                                                                                                                  +029 * around 10 and 11, each the result of 1/8 of rolls on their own and 1/4 together. This makes the case where a +1 bonus
                                                                                                                                                                                                                                                                                                                  +030 * to succeed changes the outcome on approximately 5% of 1d20 rolls, regardless of the required number to succeed if it
                                                                                                                                                                                                                                                                                                                  +031 * is less than 20. However, a +1 bonus matters on a variable portion of 3d6 rolls; if you become able to succeed on a
                                                                                                                                                                                                                                                                                                                  +032 * 10 or 11 where that was a failure before, the bonus applies approximately 12.5% of the time. Becoming able to succeed
                                                                                                                                                                                                                                                                                                                  +033 * on an 18 where that was a failure before is essentially worthless, affecting less than 0.5% of rolls. This property
                                                                                                                                                                                                                                                                                                                  +034 * of centralized results should be considered if game balance and/or the lethality of combat is important. One lengthy
                                                                                                                                                                                                                                                                                                                  +035 * stretch of extreme results by enemies that work against the favor of a player character generally result in a dead
                                                                                                                                                                                                                                                                                                                  +036 * player character, and RNGs that make extreme results more common may seem particularly cruel to players.
                                                                                                                                                                                                                                                                                                                  +037 * <br>
                                                                                                                                                                                                                                                                                                                  +038 * This generator sets a field, rawLatest, every time a random number is produced. This stores a pseudo-random double
                                                                                                                                                                                                                                                                                                                  +039 * between 0.0 (inclusive) and 1.0 (exclusive) that is not subject to the bias an expected average introduces, and is
                                                                                                                                                                                                                                                                                                                  +040 * close to uniformly distributed. You should expect rawLatest to be higher when higher numbers are returned from a
                                                                                                                                                                                                                                                                                                                  +041 * method like nextInt(), and lower when lower numbers are returned. This can be useful for rare effects that should not
                                                                                                                                                                                                                                                                                                                  +042 * be drastically more or less likely when slight changes are made to the expected average; if the expected average is
                                                                                                                                                                                                                                                                                                                  +043 * 0.65, many more random doubles from nextDouble() will be between 0.95 and 1.0 (probably more than 10% of random
                                                                                                                                                                                                                                                                                                                  +044 * numbers), but rawLatest will only be between 0.95 and 1.0 for close to 5% of all generations.
                                                                                                                                                                                                                                                                                                                  +045 * <br>
                                                                                                                                                                                                                                                                                                                  +046 * You can get and set the state this uses internally, and this is stored as a 64-bit long.
                                                                                                                                                                                                                                                                                                                  +047 * <br>
                                                                                                                                                                                                                                                                                                                  +048 * The choice of RandomnessSource doesn't really matter since this will always use a LightRNG internally. LightRNG is
                                                                                                                                                                                                                                                                                                                  +049 * the current best StatefulRandomness implementation, with excellent performance characteristics and few flaws, though
                                                                                                                                                                                                                                                                                                                  +050 * its relatively low period may sometimes be a detriment.
                                                                                                                                                                                                                                                                                                                   051 * <br>
                                                                                                                                                                                                                                                                                                                  -052 * The choice of RandomnessSource doesn't really matter since this will always use a LightRNG internally. LightRNG is
                                                                                                                                                                                                                                                                                                                  -053 * the current best StatefulRandomness implementation, with excellent performance characteristics and few flaws, though
                                                                                                                                                                                                                                                                                                                  -054 * its relatively low period may sometimes be a detriment.
                                                                                                                                                                                                                                                                                                                  -055 * <br>
                                                                                                                                                                                                                                                                                                                  -056 * More customizations may be added in the future to the ones available currently.
                                                                                                                                                                                                                                                                                                                  -057 */
                                                                                                                                                                                                                                                                                                                  -058public class EditRNG extends StatefulRNG implements Serializable{
                                                                                                                                                                                                                                                                                                                  -059
                                                                                                                                                                                                                                                                                                                  -060        /** Used to tweak the generator toward high or low values. */
                                                                                                                                                                                                                                                                                                                  -061    private double expected = 0.5;
                                                                                                                                                                                                                                                                                                                  -062
                                                                                                                                                                                                                                                                                                                  -063    /**
                                                                                                                                                                                                                                                                                                                  -064     * When positive, makes the generator more likely to generate values close to the average (bell curve).
                                                                                                                                                                                                                                                                                                                  -065     * When zero (the default), makes no changes to the centering of values.
                                                                                                                                                                                                                                                                                                                  -066     * When negative, makes the generator swing more toward extremes rather than gravitate toward the average.
                                                                                                                                                                                                                                                                                                                  -067     * Values are typically between -100 and 100, but can have extreme weight and overshadow other parts of the RNG if
                                                                                                                                                                                                                                                                                                                  -068     * they go much higher than 200.
                                                                                                                                                                                                                                                                                                                  -069     */
                                                                                                                                                                                                                                                                                                                  -070    private double centrality = 0.0;
                                                                                                                                                                                                                                                                                                                  -071    /**
                                                                                                                                                                                                                                                                                                                  -072     * The latest generated double, between 0.0 and 1.0, before changes for centrality and expected average.
                                                                                                                                                                                                                                                                                                                  -073     * Doubles are used to generate all random numbers this class produces, so be aware that calling getRandomElement()
                                                                                                                                                                                                                                                                                                                  -074     * will change this just as much as nextDouble(), nextInt(), or between() will. Primarily useful to obtain
                                                                                                                                                                                                                                                                                                                  -075     * uniformly-distributed random numbers that are related to the biased random numbers this returns as a main result,
                                                                                                                                                                                                                                                                                                                  -076     * such as to find when the last number generated was in the bottom 5% (less than 0.05, which could represent some
                                                                                                                                                                                                                                                                                                                  -077     * kind of critical failure or fumble) or top 10% (greater than or equal to 0.9, which could grant a critical
                                                                                                                                                                                                                                                                                                                  -078     * success or luck-based reward of some kind).
                                                                                                                                                                                                                                                                                                                  -079     */
                                                                                                                                                                                                                                                                                                                  -080    public double rawLatest = 0.5;
                                                                                                                                                                                                                                                                                                                  -081        private static final long serialVersionUID = -2458726316853811777L;
                                                                                                                                                                                                                                                                                                                  -082
                                                                                                                                                                                                                                                                                                                  -083    /**
                                                                                                                                                                                                                                                                                                                  -084     * Constructs an EditRNG with a pseudo-random seed from Math.random().
                                                                                                                                                                                                                                                                                                                  -085     */
                                                                                                                                                                                                                                                                                                                  -086    public EditRNG()
                                                                                                                                                                                                                                                                                                                  -087    {
                                                                                                                                                                                                                                                                                                                  -088    }
                                                                                                                                                                                                                                                                                                                  -089    /**
                                                                                                                                                                                                                                                                                                                  -090     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -091     *
                                                                                                                                                                                                                                                                                                                  -092     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -093     */
                                                                                                                                                                                                                                                                                                                  -094    public EditRNG(final long seed) {
                                                                                                                                                                                                                                                                                                                  -095        super(seed);
                                                                                                                                                                                                                                                                                                                  -096    }
                                                                                                                                                                                                                                                                                                                  -097    /**
                                                                                                                                                                                                                                                                                                                  -098     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -099     *
                                                                                                                                                                                                                                                                                                                  -100     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -101     */
                                                                                                                                                                                                                                                                                                                  -102    public EditRNG(final String seed) {
                                                                                                                                                                                                                                                                                                                  -103        super(seed);
                                                                                                                                                                                                                                                                                                                  -104    }
                                                                                                                                                                                                                                                                                                                  -105
                                                                                                                                                                                                                                                                                                                  -106    /**
                                                                                                                                                                                                                                                                                                                  -107     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -108     *
                                                                                                                                                                                                                                                                                                                  -109     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -110     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  -111     */
                                                                                                                                                                                                                                                                                                                  -112    public EditRNG(final long seed, double expected) {
                                                                                                                                                                                                                                                                                                                  -113        super(seed);
                                                                                                                                                                                                                                                                                                                  -114        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  -115    }
                                                                                                                                                                                                                                                                                                                  -116    /**
                                                                                                                                                                                                                                                                                                                  -117     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -118     *
                                                                                                                                                                                                                                                                                                                  -119     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -120     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  -121     */
                                                                                                                                                                                                                                                                                                                  -122    public EditRNG(final String seed, double expected) {
                                                                                                                                                                                                                                                                                                                  -123        super(seed);
                                                                                                                                                                                                                                                                                                                  -124        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  -125    }
                                                                                                                                                                                                                                                                                                                  -126
                                                                                                                                                                                                                                                                                                                  -127    /**
                                                                                                                                                                                                                                                                                                                  -128     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -129     *
                                                                                                                                                                                                                                                                                                                  -130     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -131     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  -132     * @param centrality if positive, makes results more likely to be near expected; if negative, the opposite. The
                                                                                                                                                                                                                                                                                                                  -133     *                   absolute value of centrality affects how centered results will be, with 0 having no effect
                                                                                                                                                                                                                                                                                                                  -134     */
                                                                                                                                                                                                                                                                                                                  -135    public EditRNG(final long seed, double expected, double centrality) {
                                                                                                                                                                                                                                                                                                                  -136        super(seed);
                                                                                                                                                                                                                                                                                                                  -137        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  -138        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  -139    }
                                                                                                                                                                                                                                                                                                                  -140    /**
                                                                                                                                                                                                                                                                                                                  -141     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -142     *
                                                                                                                                                                                                                                                                                                                  -143     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -144     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  -145     * @param centrality if positive, makes results more likely to be near expected; if negative, the opposite. The
                                                                                                                                                                                                                                                                                                                  -146     *                   absolute value of centrality affects how centered results will be, with 0 having no effect
                                                                                                                                                                                                                                                                                                                  -147     */
                                                                                                                                                                                                                                                                                                                  -148    public EditRNG(final String seed, double expected, double centrality) {
                                                                                                                                                                                                                                                                                                                  -149        super(seed);
                                                                                                                                                                                                                                                                                                                  -150        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  -151        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  -152    }
                                                                                                                                                                                                                                                                                                                  -153
                                                                                                                                                                                                                                                                                                                  -154    /**
                                                                                                                                                                                                                                                                                                                  -155     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -156     *
                                                                                                                                                                                                                                                                                                                  -157     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  -158     */
                                                                                                                                                                                                                                                                                                                  -159    public EditRNG(final RandomnessSource rs) {
                                                                                                                                                                                                                                                                                                                  -160        super(rs);
                                                                                                                                                                                                                                                                                                                  -161    }
                                                                                                                                                                                                                                                                                                                  -162    /**
                                                                                                                                                                                                                                                                                                                  -163     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -164     *
                                                                                                                                                                                                                                                                                                                  -165     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  -166     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  -167     */
                                                                                                                                                                                                                                                                                                                  -168    public EditRNG(final RandomnessSource rs, double expected) {
                                                                                                                                                                                                                                                                                                                  -169        super(rs);
                                                                                                                                                                                                                                                                                                                  -170        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  -171    }
                                                                                                                                                                                                                                                                                                                  -172    /**
                                                                                                                                                                                                                                                                                                                  -173     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  -174     *
                                                                                                                                                                                                                                                                                                                  -175     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  -176     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  -177     * @param centrality if positive, makes results more likely to be near expected; if negative, the opposite. The
                                                                                                                                                                                                                                                                                                                  -178     *                   absolute value of centrality affects how centered results will be, with 0 having no effect
                                                                                                                                                                                                                                                                                                                  -179     */
                                                                                                                                                                                                                                                                                                                  -180    public EditRNG(final RandomnessSource rs, double expected, double centrality) {
                                                                                                                                                                                                                                                                                                                  -181        super(rs);
                                                                                                                                                                                                                                                                                                                  -182        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  -183        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  -184    }
                                                                                                                                                                                                                                                                                                                  -185
                                                                                                                                                                                                                                                                                                                  -186    /**
                                                                                                                                                                                                                                                                                                                  -187     * Generate a random double, altered to try to match the expected average and centrality.
                                                                                                                                                                                                                                                                                                                  -188     * @return a double between 0.0 (inclusive) and 1.0 (exclusive)
                                                                                                                                                                                                                                                                                                                  -189     */
                                                                                                                                                                                                                                                                                                                  -190    @Override
                                                                                                                                                                                                                                                                                                                  -191    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  -192        long l = random.nextLong();
                                                                                                                                                                                                                                                                                                                  -193        double gen = (l & 0x1fffffffffffffL) * DOUBLE_UNIT, scatter = (l & 0xffffffL) * FLOAT_UNIT;
                                                                                                                                                                                                                                                                                                                  -194        rawLatest = 0.9999999999999999 - gen;
                                                                                                                                                                                                                                                                                                                  -195        gen = 0.9999999999999999 - Math.pow(gen, 1.0 / (1.0 - expected) - 1.0);
                                                                                                                                                                                                                                                                                                                  -196        if(centrality > 0) {
                                                                                                                                                                                                                                                                                                                  -197            scatter = 0.9999999999999999 - Math.pow(scatter, 1.0 / (1.0 - expected) - 1.0);
                                                                                                                                                                                                                                                                                                                  -198            gen = (gen * 100 + scatter * centrality) / (100 + centrality);
                                                                                                                                                                                                                                                                                                                  -199        }
                                                                                                                                                                                                                                                                                                                  -200        else if(centrality < 0)
                                                                                                                                                                                                                                                                                                                  -201        {
                                                                                                                                                                                                                                                                                                                  -202            scatter = Math.sin(scatter * Math.PI * 0.5);
                                                                                                                                                                                                                                                                                                                  -203            scatter *= scatter;
                                                                                                                                                                                                                                                                                                                  -204            if(expected >= 0.5)
                                                                                                                                                                                                                                                                                                                  -205                scatter = scatter * (1.0 - expected) * 2 + expected - (1.0 - expected);
                                                                                                                                                                                                                                                                                                                  -206            else
                                                                                                                                                                                                                                                                                                                  -207                scatter *= expected * 2;
                                                                                                                                                                                                                                                                                                                  -208            gen = (gen * 100 - scatter * centrality) / (100 - centrality);
                                                                                                                                                                                                                                                                                                                  -209        }
                                                                                                                                                                                                                                                                                                                  +052 * More customizations may be added in the future to the ones available currently.
                                                                                                                                                                                                                                                                                                                  +053 */
                                                                                                                                                                                                                                                                                                                  +054public class EditRNG extends StatefulRNG implements Serializable{
                                                                                                                                                                                                                                                                                                                  +055
                                                                                                                                                                                                                                                                                                                  +056        /** Used to tweak the generator toward high or low values. */
                                                                                                                                                                                                                                                                                                                  +057    private double expected = 0.5;
                                                                                                                                                                                                                                                                                                                  +058
                                                                                                                                                                                                                                                                                                                  +059    /**
                                                                                                                                                                                                                                                                                                                  +060     * When positive, makes the generator more likely to generate values close to the average (bell curve).
                                                                                                                                                                                                                                                                                                                  +061     * When zero (the default), makes no changes to the centering of values.
                                                                                                                                                                                                                                                                                                                  +062     * When negative, makes the generator swing more toward extremes rather than gravitate toward the average.
                                                                                                                                                                                                                                                                                                                  +063     * Values are typically between -100 and 100, but can have extreme weight and overshadow other parts of the RNG if
                                                                                                                                                                                                                                                                                                                  +064     * they go much higher than 200.
                                                                                                                                                                                                                                                                                                                  +065     */
                                                                                                                                                                                                                                                                                                                  +066    private double centrality = 0.0;
                                                                                                                                                                                                                                                                                                                  +067    /**
                                                                                                                                                                                                                                                                                                                  +068     * The latest generated double, between 0.0 and 1.0, before changes for centrality and expected average.
                                                                                                                                                                                                                                                                                                                  +069     * Doubles are used to generate all random numbers this class produces, so be aware that calling getRandomElement()
                                                                                                                                                                                                                                                                                                                  +070     * will change this just as much as nextDouble(), nextInt(), or between() will. Primarily useful to obtain
                                                                                                                                                                                                                                                                                                                  +071     * uniformly-distributed random numbers that are related to the biased random numbers this returns as a main result,
                                                                                                                                                                                                                                                                                                                  +072     * such as to find when the last number generated was in the bottom 5% (less than 0.05, which could represent some
                                                                                                                                                                                                                                                                                                                  +073     * kind of critical failure or fumble) or top 10% (greater than or equal to 0.9, which could grant a critical
                                                                                                                                                                                                                                                                                                                  +074     * success or luck-based reward of some kind).
                                                                                                                                                                                                                                                                                                                  +075     */
                                                                                                                                                                                                                                                                                                                  +076    public double rawLatest = 0.5;
                                                                                                                                                                                                                                                                                                                  +077        private static final long serialVersionUID = -2458726316853811777L;
                                                                                                                                                                                                                                                                                                                  +078
                                                                                                                                                                                                                                                                                                                  +079    /**
                                                                                                                                                                                                                                                                                                                  +080     * Constructs an EditRNG with a pseudo-random seed from Math.random().
                                                                                                                                                                                                                                                                                                                  +081     */
                                                                                                                                                                                                                                                                                                                  +082    public EditRNG()
                                                                                                                                                                                                                                                                                                                  +083    {
                                                                                                                                                                                                                                                                                                                  +084    }
                                                                                                                                                                                                                                                                                                                  +085    /**
                                                                                                                                                                                                                                                                                                                  +086     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +087     *
                                                                                                                                                                                                                                                                                                                  +088     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +089     */
                                                                                                                                                                                                                                                                                                                  +090    public EditRNG(final long seed) {
                                                                                                                                                                                                                                                                                                                  +091        super(seed);
                                                                                                                                                                                                                                                                                                                  +092    }
                                                                                                                                                                                                                                                                                                                  +093    /**
                                                                                                                                                                                                                                                                                                                  +094     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +095     *
                                                                                                                                                                                                                                                                                                                  +096     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +097     */
                                                                                                                                                                                                                                                                                                                  +098    public EditRNG(final CharSequence seed) {
                                                                                                                                                                                                                                                                                                                  +099        super(seed);
                                                                                                                                                                                                                                                                                                                  +100    }
                                                                                                                                                                                                                                                                                                                  +101
                                                                                                                                                                                                                                                                                                                  +102    /**
                                                                                                                                                                                                                                                                                                                  +103     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +104     *
                                                                                                                                                                                                                                                                                                                  +105     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +106     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  +107     */
                                                                                                                                                                                                                                                                                                                  +108    public EditRNG(final long seed, double expected) {
                                                                                                                                                                                                                                                                                                                  +109        super(seed);
                                                                                                                                                                                                                                                                                                                  +110        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  +111    }
                                                                                                                                                                                                                                                                                                                  +112    /**
                                                                                                                                                                                                                                                                                                                  +113     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +114     *
                                                                                                                                                                                                                                                                                                                  +115     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +116     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  +117     */
                                                                                                                                                                                                                                                                                                                  +118    public EditRNG(final String seed, double expected) {
                                                                                                                                                                                                                                                                                                                  +119        super(seed);
                                                                                                                                                                                                                                                                                                                  +120        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  +121    }
                                                                                                                                                                                                                                                                                                                  +122
                                                                                                                                                                                                                                                                                                                  +123    /**
                                                                                                                                                                                                                                                                                                                  +124     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +125     *
                                                                                                                                                                                                                                                                                                                  +126     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +127     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  +128     * @param centrality if positive, makes results more likely to be near expected; if negative, the opposite. The
                                                                                                                                                                                                                                                                                                                  +129     *                   absolute value of centrality affects how centered results will be, with 0 having no effect
                                                                                                                                                                                                                                                                                                                  +130     */
                                                                                                                                                                                                                                                                                                                  +131    public EditRNG(final long seed, double expected, double centrality) {
                                                                                                                                                                                                                                                                                                                  +132        super(seed);
                                                                                                                                                                                                                                                                                                                  +133        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  +134        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  +135    }
                                                                                                                                                                                                                                                                                                                  +136    /**
                                                                                                                                                                                                                                                                                                                  +137     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +138     *
                                                                                                                                                                                                                                                                                                                  +139     * @param seed used to seed the default RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +140     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  +141     * @param centrality if positive, makes results more likely to be near expected; if negative, the opposite. The
                                                                                                                                                                                                                                                                                                                  +142     *                   absolute value of centrality affects how centered results will be, with 0 having no effect
                                                                                                                                                                                                                                                                                                                  +143     */
                                                                                                                                                                                                                                                                                                                  +144    public EditRNG(final String seed, double expected, double centrality) {
                                                                                                                                                                                                                                                                                                                  +145        super(seed);
                                                                                                                                                                                                                                                                                                                  +146        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  +147        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  +148    }
                                                                                                                                                                                                                                                                                                                  +149
                                                                                                                                                                                                                                                                                                                  +150    /**
                                                                                                                                                                                                                                                                                                                  +151     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +152     *
                                                                                                                                                                                                                                                                                                                  +153     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  +154     */
                                                                                                                                                                                                                                                                                                                  +155    public EditRNG(final RandomnessSource rs) {
                                                                                                                                                                                                                                                                                                                  +156        super(rs);
                                                                                                                                                                                                                                                                                                                  +157    }
                                                                                                                                                                                                                                                                                                                  +158    /**
                                                                                                                                                                                                                                                                                                                  +159     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +160     *
                                                                                                                                                                                                                                                                                                                  +161     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  +162     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  +163     */
                                                                                                                                                                                                                                                                                                                  +164    public EditRNG(final RandomnessSource rs, double expected) {
                                                                                                                                                                                                                                                                                                                  +165        super(rs);
                                                                                                                                                                                                                                                                                                                  +166        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  +167    }
                                                                                                                                                                                                                                                                                                                  +168    /**
                                                                                                                                                                                                                                                                                                                  +169     * Construct a new EditRNG with the given seed.
                                                                                                                                                                                                                                                                                                                  +170     *
                                                                                                                                                                                                                                                                                                                  +171     * @param rs the implementation used to generate random bits.
                                                                                                                                                                                                                                                                                                                  +172     * @param expected the expected average for random doubles, which will be capped between 0.1 and 0.9
                                                                                                                                                                                                                                                                                                                  +173     * @param centrality if positive, makes results more likely to be near expected; if negative, the opposite. The
                                                                                                                                                                                                                                                                                                                  +174     *                   absolute value of centrality affects how centered results will be, with 0 having no effect
                                                                                                                                                                                                                                                                                                                  +175     */
                                                                                                                                                                                                                                                                                                                  +176    public EditRNG(final RandomnessSource rs, double expected, double centrality) {
                                                                                                                                                                                                                                                                                                                  +177        super(rs);
                                                                                                                                                                                                                                                                                                                  +178        this.expected = Math.max(0.1, Math.min(0.89999994, expected));
                                                                                                                                                                                                                                                                                                                  +179        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  +180    }
                                                                                                                                                                                                                                                                                                                  +181
                                                                                                                                                                                                                                                                                                                  +182    /**
                                                                                                                                                                                                                                                                                                                  +183     * Generate a random double, altered to try to match the expected average and centrality.
                                                                                                                                                                                                                                                                                                                  +184     * @return a double between 0.0 (inclusive) and 1.0 (exclusive)
                                                                                                                                                                                                                                                                                                                  +185     */
                                                                                                                                                                                                                                                                                                                  +186    @Override
                                                                                                                                                                                                                                                                                                                  +187    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  +188        long l = random.nextLong();
                                                                                                                                                                                                                                                                                                                  +189        double gen = (l & 0x1fffffffffffffL) * DOUBLE_UNIT, scatter = (l & 0xffffffL) * FLOAT_UNIT;
                                                                                                                                                                                                                                                                                                                  +190        rawLatest = 0.9999999999999999 - gen;
                                                                                                                                                                                                                                                                                                                  +191        gen = 0.9999999999999999 - Math.pow(gen, 1.0 / (1.0 - expected) - 1.0);
                                                                                                                                                                                                                                                                                                                  +192        if(centrality > 0) {
                                                                                                                                                                                                                                                                                                                  +193            scatter = 0.9999999999999999 - Math.pow(scatter, 1.0 / (1.0 - expected) - 1.0);
                                                                                                                                                                                                                                                                                                                  +194            gen = (gen * 100 + scatter * centrality) / (100 + centrality);
                                                                                                                                                                                                                                                                                                                  +195        }
                                                                                                                                                                                                                                                                                                                  +196        else if(centrality < 0)
                                                                                                                                                                                                                                                                                                                  +197        {
                                                                                                                                                                                                                                                                                                                  +198            scatter = Math.sin(scatter * Math.PI * 0.5);
                                                                                                                                                                                                                                                                                                                  +199            scatter *= scatter;
                                                                                                                                                                                                                                                                                                                  +200            if(expected >= 0.5)
                                                                                                                                                                                                                                                                                                                  +201                scatter = scatter * (1.0 - expected) * 2 + expected - (1.0 - expected);
                                                                                                                                                                                                                                                                                                                  +202            else
                                                                                                                                                                                                                                                                                                                  +203                scatter *= expected * 2;
                                                                                                                                                                                                                                                                                                                  +204            gen = (gen * 100 - scatter * centrality) / (100 - centrality);
                                                                                                                                                                                                                                                                                                                  +205        }
                                                                                                                                                                                                                                                                                                                  +206
                                                                                                                                                                                                                                                                                                                  +207        return gen;
                                                                                                                                                                                                                                                                                                                  +208
                                                                                                                                                                                                                                                                                                                  +209    }
                                                                                                                                                                                                                                                                                                                   210
                                                                                                                                                                                                                                                                                                                  -211        return gen;
                                                                                                                                                                                                                                                                                                                  -212
                                                                                                                                                                                                                                                                                                                  -213    }
                                                                                                                                                                                                                                                                                                                  -214
                                                                                                                                                                                                                                                                                                                  -215    /**
                                                                                                                                                                                                                                                                                                                  -216     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -217     *
                                                                                                                                                                                                                                                                                                                  -218     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  -219     */
                                                                                                                                                                                                                                                                                                                  -220    @Override
                                                                                                                                                                                                                                                                                                                  -221    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  -222        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  -223    }
                                                                                                                                                                                                                                                                                                                  -224
                                                                                                                                                                                                                                                                                                                  -225    /**
                                                                                                                                                                                                                                                                                                                  -226     * Returns a value from a even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  -227     * (exclusive).
                                                                                                                                                                                                                                                                                                                  -228     *
                                                                                                                                                                                                                                                                                                                  -229     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -230     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -231     * @return the found value
                                                                                                                                                                                                                                                                                                                  -232     */
                                                                                                                                                                                                                                                                                                                  -233    @Override
                                                                                                                                                                                                                                                                                                                  -234    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  -235        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  -236    }
                                                                                                                                                                                                                                                                                                                  -237
                                                                                                                                                                                                                                                                                                                  -238    /**
                                                                                                                                                                                                                                                                                                                  -239     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -240     *
                                                                                                                                                                                                                                                                                                                  -241     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -242     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -243     *
                                                                                                                                                                                                                                                                                                                  -244     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -245     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -246     * @return the found value
                                                                                                                                                                                                                                                                                                                  -247     */
                                                                                                                                                                                                                                                                                                                  -248    @Override
                                                                                                                                                                                                                                                                                                                  -249    public int between(int min, int max)
                                                                                                                                                                                                                                                                                                                  -250    {
                                                                                                                                                                                                                                                                                                                  -251        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  -252    }
                                                                                                                                                                                                                                                                                                                  -253
                                                                                                                                                                                                                                                                                                                  -254    @Override
                                                                                                                                                                                                                                                                                                                  -255    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  -256        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  -257    }
                                                                                                                                                                                                                                                                                                                  -258
                                                                                                                                                                                                                                                                                                                  -259    /**
                                                                                                                                                                                                                                                                                                                  -260     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  -261     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  -262     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  -263     *
                                                                                                                                                                                                                                                                                                                  -264     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -265     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -266     *
                                                                                                                                                                                                                                                                                                                  -267     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  -268     *
                                                                                                                                                                                                                                                                                                                  -269     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -270     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -271     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  -272     * @return the found value
                                                                                                                                                                                                                                                                                                                  -273     */
                                                                                                                                                                                                                                                                                                                  -274    @Override
                                                                                                                                                                                                                                                                                                                  -275    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  -276        return super.betweenWeighted(min, max, samples);
                                                                                                                                                                                                                                                                                                                  -277    }
                                                                                                                                                                                                                                                                                                                  -278
                                                                                                                                                                                                                                                                                                                  -279    /**
                                                                                                                                                                                                                                                                                                                  -280     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  -281     * type.
                                                                                                                                                                                                                                                                                                                  -282     *
                                                                                                                                                                                                                                                                                                                  -283     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -284     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  -285     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -286     */
                                                                                                                                                                                                                                                                                                                  -287    @Override
                                                                                                                                                                                                                                                                                                                  -288    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  -289        return super.getRandomElement(array);
                                                                                                                                                                                                                                                                                                                  -290    }
                                                                                                                                                                                                                                                                                                                  -291
                                                                                                                                                                                                                                                                                                                  -292    /**
                                                                                                                                                                                                                                                                                                                  -293     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  -294     * then null is returned.
                                                                                                                                                                                                                                                                                                                  -295     *
                                                                                                                                                                                                                                                                                                                  -296     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -297     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  -298     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -299     */
                                                                                                                                                                                                                                                                                                                  -300    @Override
                                                                                                                                                                                                                                                                                                                  -301    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -302        return super.getRandomElement(list);
                                                                                                                                                                                                                                                                                                                  -303    }
                                                                                                                                                                                                                                                                                                                  -304
                                                                                                                                                                                                                                                                                                                  -305    /**
                                                                                                                                                                                                                                                                                                                  -306     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  -307     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  -308     *
                                                                                                                                                                                                                                                                                                                  -309     * <p>
                                                                                                                                                                                                                                                                                                                  -310     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  -311     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  -312     * </p>
                                                                                                                                                                                                                                                                                                                  -313     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  -314     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -315     */
                                                                                                                                                                                                                                                                                                                  -316    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  -317        return super.getRandomElement(set);
                                                                                                                                                                                                                                                                                                                  -318    }
                                                                                                                                                                                                                                                                                                                  -319
                                                                                                                                                                                                                                                                                                                  -320    /**
                                                                                                                                                                                                                                                                                                                  -321     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  -322     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  -323     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  -324     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  -325     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  -326     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  -327     *
                                                                                                                                                                                                                                                                                                                  -328     * <p>
                                                                                                                                                                                                                                                                                                                  -329     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  -330     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  -331     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  -332     * </p>
                                                                                                                                                                                                                                                                                                                  -333     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -334     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  -335     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -336     */
                                                                                                                                                                                                                                                                                                                  -337    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  -338        return super.getRandomElement(coll);
                                                                                                                                                                                                                                                                                                                  -339    }
                                                                                                                                                                                                                                                                                                                  -340
                                                                                                                                                                                                                                                                                                                  -341    /**
                                                                                                                                                                                                                                                                                                                  -342     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  -343     */
                                                                                                                                                                                                                                                                                                                  -344    @Override
                                                                                                                                                                                                                                                                                                                  -345    public synchronized double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  -346        return super.nextGaussian();
                                                                                                                                                                                                                                                                                                                  -347    }
                                                                                                                                                                                                                                                                                                                  -348    /**
                                                                                                                                                                                                                                                                                                                  -349     * Returns a random integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -350     * negative.
                                                                                                                                                                                                                                                                                                                  -351     *
                                                                                                                                                                                                                                                                                                                  -352     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -353     * @return the found number
                                                                                                                                                                                                                                                                                                                  -354     */
                                                                                                                                                                                                                                                                                                                  -355    @Override
                                                                                                                                                                                                                                                                                                                  -356    public int nextInt(int bound) {
                                                                                                                                                                                                                                                                                                                  -357        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  -358            return 0;
                                                                                                                                                                                                                                                                                                                  -359        }
                                                                                                                                                                                                                                                                                                                  -360
                                                                                                                                                                                                                                                                                                                  -361        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -362    }
                                                                                                                                                                                                                                                                                                                  -363
                                                                                                                                                                                                                                                                                                                  -364    /**
                                                                                                                                                                                                                                                                                                                  -365     * Returns a random integer, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  -366     * @return A random int
                                                                                                                                                                                                                                                                                                                  -367     */
                                                                                                                                                                                                                                                                                                                  -368    @Override
                                                                                                                                                                                                                                                                                                                  -369    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  -370        return (int)((nextDouble() * 2.0 - 1.0) * 0x7FFFFFFF);
                                                                                                                                                                                                                                                                                                                  -371    }
                                                                                                                                                                                                                                                                                                                  -372
                                                                                                                                                                                                                                                                                                                  -373    /**
                                                                                                                                                                                                                                                                                                                  -374     * Returns a random long, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  -375     * @return A random long
                                                                                                                                                                                                                                                                                                                  -376     */
                                                                                                                                                                                                                                                                                                                  -377    @Override
                                                                                                                                                                                                                                                                                                                  -378    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  -379        return (long)((nextDouble() * 2.0 - 1.0) * 0x7FFFFFFFFFFFFFFFL);
                                                                                                                                                                                                                                                                                                                  -380    }
                                                                                                                                                                                                                                                                                                                  -381
                                                                                                                                                                                                                                                                                                                  -382    /**
                                                                                                                                                                                                                                                                                                                  -383     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -384     * negative.
                                                                                                                                                                                                                                                                                                                  -385     *
                                                                                                                                                                                                                                                                                                                  -386     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -387     * @return the found number
                                                                                                                                                                                                                                                                                                                  -388     */
                                                                                                                                                                                                                                                                                                                  -389    @Override
                                                                                                                                                                                                                                                                                                                  -390        public long nextLong(long bound) {
                                                                                                                                                                                                                                                                                                                  -391        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  -392            return 0;
                                                                                                                                                                                                                                                                                                                  -393        }
                                                                                                                                                                                                                                                                                                                  -394        return (long)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -395    }
                                                                                                                                                                                                                                                                                                                  -396    /**
                                                                                                                                                                                                                                                                                                                  -397     * Gets the current expected average for this EditRNG.
                                                                                                                                                                                                                                                                                                                  -398     * @return the current expected average.
                                                                                                                                                                                                                                                                                                                  -399     */
                                                                                                                                                                                                                                                                                                                  -400    public double getExpected() {
                                                                                                                                                                                                                                                                                                                  -401        return expected;
                                                                                                                                                                                                                                                                                                                  -402    }
                                                                                                                                                                                                                                                                                                                  -403
                                                                                                                                                                                                                                                                                                                  -404    /**
                                                                                                                                                                                                                                                                                                                  -405     * Sets the expected average for random doubles this produces, which must always be between 0.1 and 0.9, and will be
                                                                                                                                                                                                                                                                                                                  -406     * set to 0.5 if an invalid value is passed.
                                                                                                                                                                                                                                                                                                                  -407     * @param expected the expected average to use, which should be 0.1 &lt;= fairness &lt; 0.9
                                                                                                                                                                                                                                                                                                                  -408     */
                                                                                                                                                                                                                                                                                                                  -409    public void setExpected(double expected) {
                                                                                                                                                                                                                                                                                                                  -410        if(expected < 0.0 || expected >= 1.0)
                                                                                                                                                                                                                                                                                                                  -411            this.expected = 0.5;
                                                                                                                                                                                                                                                                                                                  -412        else
                                                                                                                                                                                                                                                                                                                  -413            this.expected = expected;
                                                                                                                                                                                                                                                                                                                  -414    }
                                                                                                                                                                                                                                                                                                                  -415
                                                                                                                                                                                                                                                                                                                  -416    /**
                                                                                                                                                                                                                                                                                                                  -417     * Gets the current centrality measure of this EditRNG.
                                                                                                                                                                                                                                                                                                                  -418     * Centrality has several possible effects:
                                                                                                                                                                                                                                                                                                                  -419     * When positive, makes the generator more likely to generate values close to the average (bell curve).
                                                                                                                                                                                                                                                                                                                  -420     * When zero (the default), makes no changes to the centering of values.
                                                                                                                                                                                                                                                                                                                  -421     * When negative, makes the generator swing more toward extremes rather than gravitate toward the average.
                                                                                                                                                                                                                                                                                                                  -422     * <br>
                                                                                                                                                                                                                                                                                                                  -423     * Values are typically between -100 and 100, but can have extreme weight and overshadow other parts of the RNG if
                                                                                                                                                                                                                                                                                                                  -424     * they go much higher than 200.
                                                                                                                                                                                                                                                                                                                  -425     * @return the current centrality
                                                                                                                                                                                                                                                                                                                  -426     */
                                                                                                                                                                                                                                                                                                                  -427    public double getCentrality() {
                                                                                                                                                                                                                                                                                                                  -428        return centrality;
                                                                                                                                                                                                                                                                                                                  -429    }
                                                                                                                                                                                                                                                                                                                  -430
                                                                                                                                                                                                                                                                                                                  -431    /**
                                                                                                                                                                                                                                                                                                                  -432     * Gets the current centrality measure of this EditRNG.
                                                                                                                                                                                                                                                                                                                  -433     * Centrality has several possible effects:
                                                                                                                                                                                                                                                                                                                  -434     * When positive, makes the generator more likely to generate values close to the average (bell curve).
                                                                                                                                                                                                                                                                                                                  -435     * When zero (the default), makes no changes to the centering of values.
                                                                                                                                                                                                                                                                                                                  -436     * When negative, makes the generator swing more toward extremes rather than gravitate toward the average.
                                                                                                                                                                                                                                                                                                                  -437     * <br>
                                                                                                                                                                                                                                                                                                                  -438     * Values are typically between -100 and 100, but can have extreme weight and overshadow other parts of the RNG if
                                                                                                                                                                                                                                                                                                                  -439     * they go much higher than 200.
                                                                                                                                                                                                                                                                                                                  -440     * @param centrality the new centrality measure to use
                                                                                                                                                                                                                                                                                                                  -441     */
                                                                                                                                                                                                                                                                                                                  -442    public void setCentrality(double centrality) {
                                                                                                                                                                                                                                                                                                                  -443        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  -444    }
                                                                                                                                                                                                                                                                                                                  -445
                                                                                                                                                                                                                                                                                                                  -446    /**
                                                                                                                                                                                                                                                                                                                  -447     *
                                                                                                                                                                                                                                                                                                                  -448     * @param bits the number of bits to be returned
                                                                                                                                                                                                                                                                                                                  -449     * @return a random int of the number of bits specified.
                                                                                                                                                                                                                                                                                                                  -450     */
                                                                                                                                                                                                                                                                                                                  -451    @Override
                                                                                                                                                                                                                                                                                                                  -452    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  -453        if(bits <= 0)
                                                                                                                                                                                                                                                                                                                  -454            return 0;
                                                                                                                                                                                                                                                                                                                  -455        if(bits > 32)
                                                                                                                                                                                                                                                                                                                  -456            bits = 32;
                                                                                                                                                                                                                                                                                                                  -457        return (int)(nextDouble() * (1L << bits));
                                                                                                                                                                                                                                                                                                                  -458
                                                                                                                                                                                                                                                                                                                  -459    }
                                                                                                                                                                                                                                                                                                                  -460
                                                                                                                                                                                                                                                                                                                  -461    @Override
                                                                                                                                                                                                                                                                                                                  -462    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  -463        return super.asRandom();
                                                                                                                                                                                                                                                                                                                  -464    }
                                                                                                                                                                                                                                                                                                                  -465
                                                                                                                                                                                                                                                                                                                  -466    @Override
                                                                                                                                                                                                                                                                                                                  -467    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -468    public <T> List<T> randomRotation(List<T> l) {
                                                                                                                                                                                                                                                                                                                  -469        return super.randomRotation(l);
                                                                                                                                                                                                                                                                                                                  +211    /**
                                                                                                                                                                                                                                                                                                                  +212     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +213     *
                                                                                                                                                                                                                                                                                                                  +214     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  +215     */
                                                                                                                                                                                                                                                                                                                  +216    @Override
                                                                                                                                                                                                                                                                                                                  +217    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  +218        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  +219    }
                                                                                                                                                                                                                                                                                                                  +220
                                                                                                                                                                                                                                                                                                                  +221    /**
                                                                                                                                                                                                                                                                                                                  +222     * Returns a value from a even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  +223     * (exclusive).
                                                                                                                                                                                                                                                                                                                  +224     *
                                                                                                                                                                                                                                                                                                                  +225     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +226     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +227     * @return the found value
                                                                                                                                                                                                                                                                                                                  +228     */
                                                                                                                                                                                                                                                                                                                  +229    @Override
                                                                                                                                                                                                                                                                                                                  +230    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  +231        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  +232    }
                                                                                                                                                                                                                                                                                                                  +233
                                                                                                                                                                                                                                                                                                                  +234    /**
                                                                                                                                                                                                                                                                                                                  +235     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +236     *
                                                                                                                                                                                                                                                                                                                  +237     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +238     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +239     *
                                                                                                                                                                                                                                                                                                                  +240     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +241     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +242     * @return the found value
                                                                                                                                                                                                                                                                                                                  +243     */
                                                                                                                                                                                                                                                                                                                  +244    @Override
                                                                                                                                                                                                                                                                                                                  +245    public int between(int min, int max)
                                                                                                                                                                                                                                                                                                                  +246    {
                                                                                                                                                                                                                                                                                                                  +247        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  +248    }
                                                                                                                                                                                                                                                                                                                  +249
                                                                                                                                                                                                                                                                                                                  +250    @Override
                                                                                                                                                                                                                                                                                                                  +251    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  +252        return super.between(min, max);
                                                                                                                                                                                                                                                                                                                  +253    }
                                                                                                                                                                                                                                                                                                                  +254
                                                                                                                                                                                                                                                                                                                  +255    /**
                                                                                                                                                                                                                                                                                                                  +256     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  +257     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  +258     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  +259     *
                                                                                                                                                                                                                                                                                                                  +260     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +261     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +262     *
                                                                                                                                                                                                                                                                                                                  +263     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  +264     *
                                                                                                                                                                                                                                                                                                                  +265     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +266     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +267     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  +268     * @return the found value
                                                                                                                                                                                                                                                                                                                  +269     */
                                                                                                                                                                                                                                                                                                                  +270    @Override
                                                                                                                                                                                                                                                                                                                  +271    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  +272        return super.betweenWeighted(min, max, samples);
                                                                                                                                                                                                                                                                                                                  +273    }
                                                                                                                                                                                                                                                                                                                  +274
                                                                                                                                                                                                                                                                                                                  +275    /**
                                                                                                                                                                                                                                                                                                                  +276     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  +277     * type.
                                                                                                                                                                                                                                                                                                                  +278     *
                                                                                                                                                                                                                                                                                                                  +279     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +280     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  +281     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +282     */
                                                                                                                                                                                                                                                                                                                  +283    @Override
                                                                                                                                                                                                                                                                                                                  +284    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  +285        return super.getRandomElement(array);
                                                                                                                                                                                                                                                                                                                  +286    }
                                                                                                                                                                                                                                                                                                                  +287
                                                                                                                                                                                                                                                                                                                  +288    /**
                                                                                                                                                                                                                                                                                                                  +289     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  +290     * then null is returned.
                                                                                                                                                                                                                                                                                                                  +291     *
                                                                                                                                                                                                                                                                                                                  +292     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +293     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  +294     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +295     */
                                                                                                                                                                                                                                                                                                                  +296    @Override
                                                                                                                                                                                                                                                                                                                  +297    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  +298        return super.getRandomElement(list);
                                                                                                                                                                                                                                                                                                                  +299    }
                                                                                                                                                                                                                                                                                                                  +300
                                                                                                                                                                                                                                                                                                                  +301    /**
                                                                                                                                                                                                                                                                                                                  +302     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  +303     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  +304     *
                                                                                                                                                                                                                                                                                                                  +305     * <p>
                                                                                                                                                                                                                                                                                                                  +306     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  +307     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  +308     * </p>
                                                                                                                                                                                                                                                                                                                  +309     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  +310     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +311     */
                                                                                                                                                                                                                                                                                                                  +312    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  +313        return super.getRandomElement(set);
                                                                                                                                                                                                                                                                                                                  +314    }
                                                                                                                                                                                                                                                                                                                  +315
                                                                                                                                                                                                                                                                                                                  +316    /**
                                                                                                                                                                                                                                                                                                                  +317     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  +318     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  +319     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  +320     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  +321     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  +322     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  +323     *
                                                                                                                                                                                                                                                                                                                  +324     * <p>
                                                                                                                                                                                                                                                                                                                  +325     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  +326     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  +327     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  +328     * </p>
                                                                                                                                                                                                                                                                                                                  +329     * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +330     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  +331     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +332     */
                                                                                                                                                                                                                                                                                                                  +333    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  +334        return super.getRandomElement(coll);
                                                                                                                                                                                                                                                                                                                  +335    }
                                                                                                                                                                                                                                                                                                                  +336
                                                                                                                                                                                                                                                                                                                  +337    /**
                                                                                                                                                                                                                                                                                                                  +338     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  +339     */
                                                                                                                                                                                                                                                                                                                  +340    @Override
                                                                                                                                                                                                                                                                                                                  +341    public synchronized double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  +342        return super.nextGaussian();
                                                                                                                                                                                                                                                                                                                  +343    }
                                                                                                                                                                                                                                                                                                                  +344    /**
                                                                                                                                                                                                                                                                                                                  +345     * Returns a random integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +346     * negative.
                                                                                                                                                                                                                                                                                                                  +347     *
                                                                                                                                                                                                                                                                                                                  +348     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +349     * @return the found number
                                                                                                                                                                                                                                                                                                                  +350     */
                                                                                                                                                                                                                                                                                                                  +351    @Override
                                                                                                                                                                                                                                                                                                                  +352    public int nextInt(int bound) {
                                                                                                                                                                                                                                                                                                                  +353        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  +354            return 0;
                                                                                                                                                                                                                                                                                                                  +355        }
                                                                                                                                                                                                                                                                                                                  +356
                                                                                                                                                                                                                                                                                                                  +357        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +358    }
                                                                                                                                                                                                                                                                                                                  +359
                                                                                                                                                                                                                                                                                                                  +360    /**
                                                                                                                                                                                                                                                                                                                  +361     * Returns a random integer, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  +362     * @return A random int
                                                                                                                                                                                                                                                                                                                  +363     */
                                                                                                                                                                                                                                                                                                                  +364    @Override
                                                                                                                                                                                                                                                                                                                  +365    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  +366        return (int)((nextDouble() * 2.0 - 1.0) * 0x7FFFFFFF);
                                                                                                                                                                                                                                                                                                                  +367    }
                                                                                                                                                                                                                                                                                                                  +368
                                                                                                                                                                                                                                                                                                                  +369    /**
                                                                                                                                                                                                                                                                                                                  +370     * Returns a random long, which may be positive or negative.
                                                                                                                                                                                                                                                                                                                  +371     * @return A random long
                                                                                                                                                                                                                                                                                                                  +372     */
                                                                                                                                                                                                                                                                                                                  +373    @Override
                                                                                                                                                                                                                                                                                                                  +374    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  +375        return (long)((nextDouble() * 2.0 - 1.0) * 0x7FFFFFFFFFFFFFFFL);
                                                                                                                                                                                                                                                                                                                  +376    }
                                                                                                                                                                                                                                                                                                                  +377
                                                                                                                                                                                                                                                                                                                  +378    /**
                                                                                                                                                                                                                                                                                                                  +379     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +380     * negative.
                                                                                                                                                                                                                                                                                                                  +381     *
                                                                                                                                                                                                                                                                                                                  +382     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +383     * @return the found number
                                                                                                                                                                                                                                                                                                                  +384     */
                                                                                                                                                                                                                                                                                                                  +385    @Override
                                                                                                                                                                                                                                                                                                                  +386        public long nextLong(long bound) {
                                                                                                                                                                                                                                                                                                                  +387        if (bound <= 0) {
                                                                                                                                                                                                                                                                                                                  +388            return 0;
                                                                                                                                                                                                                                                                                                                  +389        }
                                                                                                                                                                                                                                                                                                                  +390        return (long)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +391    }
                                                                                                                                                                                                                                                                                                                  +392    /**
                                                                                                                                                                                                                                                                                                                  +393     * Gets the current expected average for this EditRNG.
                                                                                                                                                                                                                                                                                                                  +394     * @return the current expected average.
                                                                                                                                                                                                                                                                                                                  +395     */
                                                                                                                                                                                                                                                                                                                  +396    public double getExpected() {
                                                                                                                                                                                                                                                                                                                  +397        return expected;
                                                                                                                                                                                                                                                                                                                  +398    }
                                                                                                                                                                                                                                                                                                                  +399
                                                                                                                                                                                                                                                                                                                  +400    /**
                                                                                                                                                                                                                                                                                                                  +401     * Sets the expected average for random doubles this produces, which must always be between 0.1 and 0.9, and will be
                                                                                                                                                                                                                                                                                                                  +402     * set to 0.5 if an invalid value is passed.
                                                                                                                                                                                                                                                                                                                  +403     * @param expected the expected average to use, which should be 0.1 &lt;= fairness &lt; 0.9
                                                                                                                                                                                                                                                                                                                  +404     */
                                                                                                                                                                                                                                                                                                                  +405    public void setExpected(double expected) {
                                                                                                                                                                                                                                                                                                                  +406        if(expected < 0.0 || expected >= 1.0)
                                                                                                                                                                                                                                                                                                                  +407            this.expected = 0.5;
                                                                                                                                                                                                                                                                                                                  +408        else
                                                                                                                                                                                                                                                                                                                  +409            this.expected = expected;
                                                                                                                                                                                                                                                                                                                  +410    }
                                                                                                                                                                                                                                                                                                                  +411
                                                                                                                                                                                                                                                                                                                  +412    /**
                                                                                                                                                                                                                                                                                                                  +413     * Gets the current centrality measure of this EditRNG.
                                                                                                                                                                                                                                                                                                                  +414     * Centrality has several possible effects:
                                                                                                                                                                                                                                                                                                                  +415     * When positive, makes the generator more likely to generate values close to the average (bell curve).
                                                                                                                                                                                                                                                                                                                  +416     * When zero (the default), makes no changes to the centering of values.
                                                                                                                                                                                                                                                                                                                  +417     * When negative, makes the generator swing more toward extremes rather than gravitate toward the average.
                                                                                                                                                                                                                                                                                                                  +418     * <br>
                                                                                                                                                                                                                                                                                                                  +419     * Values are typically between -100 and 100, but can have extreme weight and overshadow other parts of the RNG if
                                                                                                                                                                                                                                                                                                                  +420     * they go much higher than 200.
                                                                                                                                                                                                                                                                                                                  +421     * @return the current centrality
                                                                                                                                                                                                                                                                                                                  +422     */
                                                                                                                                                                                                                                                                                                                  +423    public double getCentrality() {
                                                                                                                                                                                                                                                                                                                  +424        return centrality;
                                                                                                                                                                                                                                                                                                                  +425    }
                                                                                                                                                                                                                                                                                                                  +426
                                                                                                                                                                                                                                                                                                                  +427    /**
                                                                                                                                                                                                                                                                                                                  +428     * Gets the current centrality measure of this EditRNG.
                                                                                                                                                                                                                                                                                                                  +429     * Centrality has several possible effects:
                                                                                                                                                                                                                                                                                                                  +430     * When positive, makes the generator more likely to generate values close to the average (bell curve).
                                                                                                                                                                                                                                                                                                                  +431     * When zero (the default), makes no changes to the centering of values.
                                                                                                                                                                                                                                                                                                                  +432     * When negative, makes the generator swing more toward extremes rather than gravitate toward the average.
                                                                                                                                                                                                                                                                                                                  +433     * <br>
                                                                                                                                                                                                                                                                                                                  +434     * Values are typically between -100 and 100, but can have extreme weight and overshadow other parts of the RNG if
                                                                                                                                                                                                                                                                                                                  +435     * they go much higher than 200.
                                                                                                                                                                                                                                                                                                                  +436     * @param centrality the new centrality measure to use
                                                                                                                                                                                                                                                                                                                  +437     */
                                                                                                                                                                                                                                                                                                                  +438    public void setCentrality(double centrality) {
                                                                                                                                                                                                                                                                                                                  +439        this.centrality = centrality;
                                                                                                                                                                                                                                                                                                                  +440    }
                                                                                                                                                                                                                                                                                                                  +441
                                                                                                                                                                                                                                                                                                                  +442    /**
                                                                                                                                                                                                                                                                                                                  +443     *
                                                                                                                                                                                                                                                                                                                  +444     * @param bits the number of bits to be returned
                                                                                                                                                                                                                                                                                                                  +445     * @return a random int of the number of bits specified.
                                                                                                                                                                                                                                                                                                                  +446     */
                                                                                                                                                                                                                                                                                                                  +447    @Override
                                                                                                                                                                                                                                                                                                                  +448    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  +449        if(bits <= 0)
                                                                                                                                                                                                                                                                                                                  +450            return 0;
                                                                                                                                                                                                                                                                                                                  +451        if(bits > 32)
                                                                                                                                                                                                                                                                                                                  +452            bits = 32;
                                                                                                                                                                                                                                                                                                                  +453        return (int)(nextDouble() * (1L << bits));
                                                                                                                                                                                                                                                                                                                  +454
                                                                                                                                                                                                                                                                                                                  +455    }
                                                                                                                                                                                                                                                                                                                  +456
                                                                                                                                                                                                                                                                                                                  +457    @Override
                                                                                                                                                                                                                                                                                                                  +458    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  +459        return (float)nextDouble();
                                                                                                                                                                                                                                                                                                                  +460    }
                                                                                                                                                                                                                                                                                                                  +461
                                                                                                                                                                                                                                                                                                                  +462    @Override
                                                                                                                                                                                                                                                                                                                  +463    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  +464        return nextDouble() >= 0.5;
                                                                                                                                                                                                                                                                                                                  +465    }
                                                                                                                                                                                                                                                                                                                  +466
                                                                                                                                                                                                                                                                                                                  +467    @Override
                                                                                                                                                                                                                                                                                                                  +468    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  +469        return random;
                                                                                                                                                                                                                                                                                                                   470    }
                                                                                                                                                                                                                                                                                                                   471
                                                                                                                                                                                                                                                                                                                   472    @Override
                                                                                                                                                                                                                                                                                                                  -473    public <T> Iterable<T> getRandomStartIterable(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -474        return super.getRandomStartIterable(list);
                                                                                                                                                                                                                                                                                                                  +473    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +474        this.random = random;
                                                                                                                                                                                                                                                                                                                   475    }
                                                                                                                                                                                                                                                                                                                   476
                                                                                                                                                                                                                                                                                                                  -477    @Override
                                                                                                                                                                                                                                                                                                                  -478    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  -479        return super.shuffle(elements, dest);
                                                                                                                                                                                                                                                                                                                  -480    }
                                                                                                                                                                                                                                                                                                                  -481
                                                                                                                                                                                                                                                                                                                  -482    @Override
                                                                                                                                                                                                                                                                                                                  -483    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  -484        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  -485    }
                                                                                                                                                                                                                                                                                                                  -486
                                                                                                                                                                                                                                                                                                                  -487    @Override
                                                                                                                                                                                                                                                                                                                  -488    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  -489        return (float)nextDouble();
                                                                                                                                                                                                                                                                                                                  -490    }
                                                                                                                                                                                                                                                                                                                  -491
                                                                                                                                                                                                                                                                                                                  -492    @Override
                                                                                                                                                                                                                                                                                                                  -493    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  -494        return nextDouble() >= 0.5;
                                                                                                                                                                                                                                                                                                                  -495    }
                                                                                                                                                                                                                                                                                                                  -496
                                                                                                                                                                                                                                                                                                                  -497    @Override
                                                                                                                                                                                                                                                                                                                  -498    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  -499        return random;
                                                                                                                                                                                                                                                                                                                  -500    }
                                                                                                                                                                                                                                                                                                                  -501
                                                                                                                                                                                                                                                                                                                  -502    @Override
                                                                                                                                                                                                                                                                                                                  -503    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -504        this.random = random;
                                                                                                                                                                                                                                                                                                                  -505    }
                                                                                                                                                                                                                                                                                                                  -506
                                                                                                                                                                                                                                                                                                                  -507    /**
                                                                                                                                                                                                                                                                                                                  -508     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  -509     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  -510     * shuffling a copy of data and getting a section of it that matches the length of output.
                                                                                                                                                                                                                                                                                                                  +477    /**
                                                                                                                                                                                                                                                                                                                  +478     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  +479     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  +480     * shuffling a copy of data and getting a section of it that matches the length of output.
                                                                                                                                                                                                                                                                                                                  +481     *
                                                                                                                                                                                                                                                                                                                  +482     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  +483     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  +484     * @param data an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +485     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  +486     * @param <T> can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +487     * @return an array of T that has length equal to output's length and may contain null elements if output is shorter
                                                                                                                                                                                                                                                                                                                  +488     * than data
                                                                                                                                                                                                                                                                                                                  +489     */
                                                                                                                                                                                                                                                                                                                  +490    @Override
                                                                                                                                                                                                                                                                                                                  +491    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  +492        return super.randomPortion(data, output);
                                                                                                                                                                                                                                                                                                                  +493    }
                                                                                                                                                                                                                                                                                                                  +494
                                                                                                                                                                                                                                                                                                                  +495    /**
                                                                                                                                                                                                                                                                                                                  +496     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  +497     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  +498     *
                                                                                                                                                                                                                                                                                                                  +499     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +500     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  +501     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  +502     */
                                                                                                                                                                                                                                                                                                                  +503    @Override
                                                                                                                                                                                                                                                                                                                  +504    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  +505        return super.randomPortion(data, count);
                                                                                                                                                                                                                                                                                                                  +506    }
                                                                                                                                                                                                                                                                                                                  +507
                                                                                                                                                                                                                                                                                                                  +508    /**
                                                                                                                                                                                                                                                                                                                  +509     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  +510     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                   511     *
                                                                                                                                                                                                                                                                                                                  -512     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  -513     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  -514     * @param data an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -515     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  -516     * @param <T> can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -517     * @return an array of T that has length equal to output's length and may contain null elements if output is shorter
                                                                                                                                                                                                                                                                                                                  -518     * than data
                                                                                                                                                                                                                                                                                                                  -519     */
                                                                                                                                                                                                                                                                                                                  -520    @Override
                                                                                                                                                                                                                                                                                                                  -521    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  -522        return super.randomPortion(data, output);
                                                                                                                                                                                                                                                                                                                  -523    }
                                                                                                                                                                                                                                                                                                                  -524
                                                                                                                                                                                                                                                                                                                  -525    /**
                                                                                                                                                                                                                                                                                                                  -526     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  -527     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  -528     *
                                                                                                                                                                                                                                                                                                                  -529     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -530     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  -531     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  -532     */
                                                                                                                                                                                                                                                                                                                  -533    @Override
                                                                                                                                                                                                                                                                                                                  -534    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  -535        return super.randomPortion(data, count);
                                                                                                                                                                                                                                                                                                                  -536    }
                                                                                                                                                                                                                                                                                                                  -537
                                                                                                                                                                                                                                                                                                                  -538    /**
                                                                                                                                                                                                                                                                                                                  -539     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  -540     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  -541     *
                                                                                                                                                                                                                                                                                                                  -542     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  -543     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  -544     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  -545     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  -546     */
                                                                                                                                                                                                                                                                                                                  -547    @Override
                                                                                                                                                                                                                                                                                                                  -548    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  -549        return super.randomRange(start, end, count);
                                                                                                                                                                                                                                                                                                                  -550    }
                                                                                                                                                                                                                                                                                                                  -551
                                                                                                                                                                                                                                                                                                                  -552    /**
                                                                                                                                                                                                                                                                                                                  -553     * Gets the latest "un-biased" random double used to produce the most recent (potentially) biased random number
                                                                                                                                                                                                                                                                                                                  -554     * generated for another method in this class, such as nextDouble(), between(), or getRandomElement(). This is a
                                                                                                                                                                                                                                                                                                                  -555     * double between 0.0 (inclusive) and 1.0 (exclusive).
                                                                                                                                                                                                                                                                                                                  -556     * @return the latest uniformly-distributed double before bias is added; between 0.0 and 1.0 (exclusive upper)
                                                                                                                                                                                                                                                                                                                  -557     */
                                                                                                                                                                                                                                                                                                                  -558    public double getRawLatest() {
                                                                                                                                                                                                                                                                                                                  -559        return rawLatest;
                                                                                                                                                                                                                                                                                                                  -560    }
                                                                                                                                                                                                                                                                                                                  -561
                                                                                                                                                                                                                                                                                                                  -562    /**
                                                                                                                                                                                                                                                                                                                  -563     * Creates a copy of this StatefulRNG; it will generate the same random numbers, given the same calls in order, as
                                                                                                                                                                                                                                                                                                                  -564     * this StatefulRNG at the point copy() is called. The copy will not share references with this StatefulRNG.
                                                                                                                                                                                                                                                                                                                  -565     *
                                                                                                                                                                                                                                                                                                                  -566     * @return a copy of this StatefulRNG
                                                                                                                                                                                                                                                                                                                  -567     */
                                                                                                                                                                                                                                                                                                                  -568    @Override
                                                                                                                                                                                                                                                                                                                  -569    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  -570        EditRNG next = new EditRNG(random.copy(), expected, centrality);
                                                                                                                                                                                                                                                                                                                  -571        next.rawLatest = rawLatest;
                                                                                                                                                                                                                                                                                                                  -572        return next;
                                                                                                                                                                                                                                                                                                                  +512     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  +513     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  +514     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  +515     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  +516     */
                                                                                                                                                                                                                                                                                                                  +517    @Override
                                                                                                                                                                                                                                                                                                                  +518    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  +519        return super.randomRange(start, end, count);
                                                                                                                                                                                                                                                                                                                  +520    }
                                                                                                                                                                                                                                                                                                                  +521
                                                                                                                                                                                                                                                                                                                  +522    /**
                                                                                                                                                                                                                                                                                                                  +523     * Gets the latest "un-biased" random double used to produce the most recent (potentially) biased random number
                                                                                                                                                                                                                                                                                                                  +524     * generated for another method in this class, such as nextDouble(), between(), or getRandomElement(). This is a
                                                                                                                                                                                                                                                                                                                  +525     * double between 0.0 (inclusive) and 1.0 (exclusive).
                                                                                                                                                                                                                                                                                                                  +526     * @return the latest uniformly-distributed double before bias is added; between 0.0 and 1.0 (exclusive upper)
                                                                                                                                                                                                                                                                                                                  +527     */
                                                                                                                                                                                                                                                                                                                  +528    public double getRawLatest() {
                                                                                                                                                                                                                                                                                                                  +529        return rawLatest;
                                                                                                                                                                                                                                                                                                                  +530    }
                                                                                                                                                                                                                                                                                                                  +531
                                                                                                                                                                                                                                                                                                                  +532    /**
                                                                                                                                                                                                                                                                                                                  +533     * Creates a copy of this StatefulRNG; it will generate the same random numbers, given the same calls in order, as
                                                                                                                                                                                                                                                                                                                  +534     * this StatefulRNG at the point copy() is called. The copy will not share references with this StatefulRNG.
                                                                                                                                                                                                                                                                                                                  +535     *
                                                                                                                                                                                                                                                                                                                  +536     * @return a copy of this StatefulRNG
                                                                                                                                                                                                                                                                                                                  +537     */
                                                                                                                                                                                                                                                                                                                  +538    @Override
                                                                                                                                                                                                                                                                                                                  +539    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  +540        EditRNG next = new EditRNG(random.copy(), expected, centrality);
                                                                                                                                                                                                                                                                                                                  +541        next.rawLatest = rawLatest;
                                                                                                                                                                                                                                                                                                                  +542        return next;
                                                                                                                                                                                                                                                                                                                  +543    }
                                                                                                                                                                                                                                                                                                                  +544
                                                                                                                                                                                                                                                                                                                  +545    /**
                                                                                                                                                                                                                                                                                                                  +546     * Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                                                                                                                                                                                                                                                                  +547     *
                                                                                                                                                                                                                                                                                                                  +548     * @return a long that can be used as state.
                                                                                                                                                                                                                                                                                                                  +549     */
                                                                                                                                                                                                                                                                                                                  +550    @Override
                                                                                                                                                                                                                                                                                                                  +551    public long getState() {
                                                                                                                                                                                                                                                                                                                  +552        return super.getState();
                                                                                                                                                                                                                                                                                                                  +553    }
                                                                                                                                                                                                                                                                                                                  +554
                                                                                                                                                                                                                                                                                                                  +555    /**
                                                                                                                                                                                                                                                                                                                  +556     * Sets the state of the random number generator to a given long, which will alter future random numbers this
                                                                                                                                                                                                                                                                                                                  +557     * produces based on the state.
                                                                                                                                                                                                                                                                                                                  +558     *
                                                                                                                                                                                                                                                                                                                  +559     * @param state a long, which typically should not be 0 (some implementations may tolerate a state of 0, however).
                                                                                                                                                                                                                                                                                                                  +560     */
                                                                                                                                                                                                                                                                                                                  +561    @Override
                                                                                                                                                                                                                                                                                                                  +562    public void setState(long state) {
                                                                                                                                                                                                                                                                                                                  +563        super.setState(state);
                                                                                                                                                                                                                                                                                                                  +564    }
                                                                                                                                                                                                                                                                                                                  +565
                                                                                                                                                                                                                                                                                                                  +566    @Override
                                                                                                                                                                                                                                                                                                                  +567    public String toString() {
                                                                                                                                                                                                                                                                                                                  +568        return "EditRNG{" +
                                                                                                                                                                                                                                                                                                                  +569                "expected=" + expected +
                                                                                                                                                                                                                                                                                                                  +570                ", centrality=" + centrality +
                                                                                                                                                                                                                                                                                                                  +571                ", Randomness Source=" + random +
                                                                                                                                                                                                                                                                                                                  +572                '}';
                                                                                                                                                                                                                                                                                                                   573    }
                                                                                                                                                                                                                                                                                                                   574
                                                                                                                                                                                                                                                                                                                  -575    /**
                                                                                                                                                                                                                                                                                                                  -576     * Get a long that can be used to reproduce the sequence of random numbers this object will generate starting now.
                                                                                                                                                                                                                                                                                                                  -577     *
                                                                                                                                                                                                                                                                                                                  -578     * @return a long that can be used as state.
                                                                                                                                                                                                                                                                                                                  -579     */
                                                                                                                                                                                                                                                                                                                  -580    @Override
                                                                                                                                                                                                                                                                                                                  -581    public long getState() {
                                                                                                                                                                                                                                                                                                                  -582        return super.getState();
                                                                                                                                                                                                                                                                                                                  -583    }
                                                                                                                                                                                                                                                                                                                  -584
                                                                                                                                                                                                                                                                                                                  -585    /**
                                                                                                                                                                                                                                                                                                                  -586     * Sets the state of the random number generator to a given long, which will alter future random numbers this
                                                                                                                                                                                                                                                                                                                  -587     * produces based on the state.
                                                                                                                                                                                                                                                                                                                  -588     *
                                                                                                                                                                                                                                                                                                                  -589     * @param state a long, which typically should not be 0 (some implementations may tolerate a state of 0, however).
                                                                                                                                                                                                                                                                                                                  -590     */
                                                                                                                                                                                                                                                                                                                  -591    @Override
                                                                                                                                                                                                                                                                                                                  -592    public void setState(long state) {
                                                                                                                                                                                                                                                                                                                  -593        super.setState(state);
                                                                                                                                                                                                                                                                                                                  -594    }
                                                                                                                                                                                                                                                                                                                  -595
                                                                                                                                                                                                                                                                                                                  -596    @Override
                                                                                                                                                                                                                                                                                                                  -597    public String toString() {
                                                                                                                                                                                                                                                                                                                  -598        return "EditRNG{" +
                                                                                                                                                                                                                                                                                                                  -599                "expected=" + expected +
                                                                                                                                                                                                                                                                                                                  -600                ", centrality=" + centrality +
                                                                                                                                                                                                                                                                                                                  -601                ", Randomness Source=" + random +
                                                                                                                                                                                                                                                                                                                  -602                '}';
                                                                                                                                                                                                                                                                                                                  -603    }
                                                                                                                                                                                                                                                                                                                  -604
                                                                                                                                                                                                                                                                                                                  +575    @Override
                                                                                                                                                                                                                                                                                                                  +576    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  +577        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  +578        if (o == null || getClass() != o.getClass()) return false;
                                                                                                                                                                                                                                                                                                                  +579        if (!super.equals(o)) return false;
                                                                                                                                                                                                                                                                                                                  +580
                                                                                                                                                                                                                                                                                                                  +581        EditRNG editRNG = (EditRNG) o;
                                                                                                                                                                                                                                                                                                                  +582
                                                                                                                                                                                                                                                                                                                  +583        if (Double.compare(editRNG.expected, expected) != 0) return false;
                                                                                                                                                                                                                                                                                                                  +584        return Double.compare(editRNG.centrality, centrality) == 0;
                                                                                                                                                                                                                                                                                                                  +585    }
                                                                                                                                                                                                                                                                                                                  +586
                                                                                                                                                                                                                                                                                                                  +587    @Override
                                                                                                                                                                                                                                                                                                                  +588    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  +589        int result = super.hashCode() * 31;
                                                                                                                                                                                                                                                                                                                  +590        result += NumberTools.doubleToMixedIntBits(expected);
                                                                                                                                                                                                                                                                                                                  +591        result = 31 * result + NumberTools.doubleToMixedIntBits(centrality);
                                                                                                                                                                                                                                                                                                                  +592        return result;
                                                                                                                                                                                                                                                                                                                  +593    }
                                                                                                                                                                                                                                                                                                                  +594
                                                                                                                                                                                                                                                                                                                  +595    /**
                                                                                                                                                                                                                                                                                                                  +596     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  +597     * Uses a slightly optimized technique. This method is considered "hasty" since
                                                                                                                                                                                                                                                                                                                  +598     * it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also
                                                                                                                                                                                                                                                                                                                  +599     * has undefined behavior if bound is negative, though it will probably produce a negative
                                                                                                                                                                                                                                                                                                                  +600     * number (just how negative is an open question).
                                                                                                                                                                                                                                                                                                                  +601     *
                                                                                                                                                                                                                                                                                                                  +602     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  +603     * @return the found number
                                                                                                                                                                                                                                                                                                                  +604     */
                                                                                                                                                                                                                                                                                                                   605    @Override
                                                                                                                                                                                                                                                                                                                  -606    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  -607        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  -608        if (o == null || getClass() != o.getClass()) return false;
                                                                                                                                                                                                                                                                                                                  -609        if (!super.equals(o)) return false;
                                                                                                                                                                                                                                                                                                                  +606    public int nextIntHasty(int bound) {
                                                                                                                                                                                                                                                                                                                  +607        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  +608    }
                                                                                                                                                                                                                                                                                                                  +609
                                                                                                                                                                                                                                                                                                                   610
                                                                                                                                                                                                                                                                                                                  -611        EditRNG editRNG = (EditRNG) o;
                                                                                                                                                                                                                                                                                                                  -612
                                                                                                                                                                                                                                                                                                                  -613        if (Double.compare(editRNG.expected, expected) != 0) return false;
                                                                                                                                                                                                                                                                                                                  -614        return Double.compare(editRNG.centrality, centrality) == 0;
                                                                                                                                                                                                                                                                                                                  -615    }
                                                                                                                                                                                                                                                                                                                  -616
                                                                                                                                                                                                                                                                                                                  -617    @Override
                                                                                                                                                                                                                                                                                                                  -618    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  -619        int result = super.hashCode() * 31;
                                                                                                                                                                                                                                                                                                                  -620        long temp;
                                                                                                                                                                                                                                                                                                                  -621        temp = NumberTools.doubleToLongBits(expected);
                                                                                                                                                                                                                                                                                                                  -622        result += (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  -623        temp = NumberTools.doubleToLongBits(centrality);
                                                                                                                                                                                                                                                                                                                  -624        result = 31 * result + (int) (temp ^ (temp >>> 32));
                                                                                                                                                                                                                                                                                                                  -625        return result;
                                                                                                                                                                                                                                                                                                                  -626    }
                                                                                                                                                                                                                                                                                                                  -627
                                                                                                                                                                                                                                                                                                                  -628    /**
                                                                                                                                                                                                                                                                                                                  -629     * Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays.
                                                                                                                                                                                                                                                                                                                  -630     * <br>
                                                                                                                                                                                                                                                                                                                  -631     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -632     *
                                                                                                                                                                                                                                                                                                                  -633     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -634     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  -635     */
                                                                                                                                                                                                                                                                                                                  -636    @GwtIncompatible
                                                                                                                                                                                                                                                                                                                  -637    @Override
                                                                                                                                                                                                                                                                                                                  -638    public <T> T[] shuffle(T[] elements) {
                                                                                                                                                                                                                                                                                                                  -639        return super.shuffle(elements);
                                                                                                                                                                                                                                                                                                                  -640    }
                                                                                                                                                                                                                                                                                                                  -641
                                                                                                                                                                                                                                                                                                                  -642    /**
                                                                                                                                                                                                                                                                                                                  -643     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  -644     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  -645     *
                                                                                                                                                                                                                                                                                                                  -646     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  -647     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  -648     */
                                                                                                                                                                                                                                                                                                                  -649    @Override
                                                                                                                                                                                                                                                                                                                  -650    public int[] randomOrdering(int length) {
                                                                                                                                                                                                                                                                                                                  -651        return super.randomOrdering(length);
                                                                                                                                                                                                                                                                                                                  -652    }
                                                                                                                                                                                                                                                                                                                  -653
                                                                                                                                                                                                                                                                                                                  -654    /**
                                                                                                                                                                                                                                                                                                                  -655     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  -656     * Uses a slightly optimized technique. This method is considered "hasty" since
                                                                                                                                                                                                                                                                                                                  -657     * it should be faster than nextInt() doesn't check for "less-valid" bounds values. It also
                                                                                                                                                                                                                                                                                                                  -658     * has undefined behavior if bound is negative, though it will probably produce a negative
                                                                                                                                                                                                                                                                                                                  -659     * number (just how negative is an open question).
                                                                                                                                                                                                                                                                                                                  -660     *
                                                                                                                                                                                                                                                                                                                  -661     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  -662     * @return the found number
                                                                                                                                                                                                                                                                                                                  -663     */
                                                                                                                                                                                                                                                                                                                  -664    @Override
                                                                                                                                                                                                                                                                                                                  -665    public int nextIntHasty(int bound) {
                                                                                                                                                                                                                                                                                                                  -666        return (int)(nextDouble() * bound);
                                                                                                                                                                                                                                                                                                                  -667    }
                                                                                                                                                                                                                                                                                                                  -668
                                                                                                                                                                                                                                                                                                                  -669
                                                                                                                                                                                                                                                                                                                  -670}
                                                                                                                                                                                                                                                                                                                  +611}
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/MeadNoise.html b/docs/squidlib-util/src-html/squidpony/squidmath/MeadNoise.html
                                                                                                                                                                                                                                                                                                                  index fa1ddc79bf..d85ced9243 100644
                                                                                                                                                                                                                                                                                                                  --- a/docs/squidlib-util/src-html/squidpony/squidmath/MeadNoise.html
                                                                                                                                                                                                                                                                                                                  +++ b/docs/squidlib-util/src-html/squidpony/squidmath/MeadNoise.html
                                                                                                                                                                                                                                                                                                                  @@ -1224,7 +1224,7 @@
                                                                                                                                                                                                                                                                                                                   1216     * @param t the float to find the floor for
                                                                                                                                                                                                                                                                                                                   1217     * @return the floor of t, as an int
                                                                                                                                                                                                                                                                                                                   1218     */
                                                                                                                                                                                                                                                                                                                  -1219    public static long longFloor(float t) {
                                                                                                                                                                                                                                                                                                                  +1219    public static long longFloor(double t) {
                                                                                                                                                                                                                                                                                                                   1220        return t >= 0 ? (long) t : (long) t - 1L;
                                                                                                                                                                                                                                                                                                                   1221    }
                                                                                                                                                                                                                                                                                                                   1222
                                                                                                                                                                                                                                                                                                                  @@ -1258,403 +1258,443 @@
                                                                                                                                                                                                                                                                                                                   1250    private static final int[] distOrder = {0, 0, 0, 0, 0, 0},
                                                                                                                                                                                                                                                                                                                   1251            newDistOrder = new int[]{-1, 0, 0, 0, 0, 0, 0},
                                                                                                                                                                                                                                                                                                                   1252            intLoc = {0, 0, 0, 0, 0, 0};
                                                                                                                                                                                                                                                                                                                  -1253    private static final float
                                                                                                                                                                                                                                                                                                                  -1254            //PI_F = 3.14159265358979323846f,
                                                                                                                                                                                                                                                                                                                  -1255            PHI_F = 1.618033988749895f,
                                                                                                                                                                                                                                                                                                                  -1256            HALF_PI_F = 1.5707963267948966f;
                                                                                                                                                                                                                                                                                                                  -1257    /*
                                                                                                                                                                                                                                                                                                                  -1258     * Quintic-interpolates between start and end (valid floats), with a between 0 (yields start) and 1 (yields end).
                                                                                                                                                                                                                                                                                                                  -1259     * Will smoothly transition toward start or end as a approaches 0 or 1, respectively.
                                                                                                                                                                                                                                                                                                                  -1260     * @param start a valid float
                                                                                                                                                                                                                                                                                                                  -1261     * @param end a valid float
                                                                                                                                                                                                                                                                                                                  -1262     * @param a a float between 0 and 1 inclusive
                                                                                                                                                                                                                                                                                                                  -1263     * @return a float between x and y inclusive
                                                                                                                                                                                                                                                                                                                  -1264     */
                                                                                                                                                                                                                                                                                                                  -1265    public static float querp(final float start, final float end, float a){
                                                                                                                                                                                                                                                                                                                  -1266        return (1f - (a *= a * a * (a * (a * 6f - 15f) + 10f))) * start + a * end;
                                                                                                                                                                                                                                                                                                                  -1267    }
                                                                                                                                                                                                                                                                                                                  -1268
                                                                                                                                                                                                                                                                                                                  -1269    public static double noise(final double x, final double y, final int seed) {
                                                                                                                                                                                                                                                                                                                  -1270        return noise((float)x, (float)y, seed);
                                                                                                                                                                                                                                                                                                                  -1271    }
                                                                                                                                                                                                                                                                                                                  -1272
                                                                                                                                                                                                                                                                                                                  -1273    public static float noise(float x, float y, final int seed) {
                                                                                                                                                                                                                                                                                                                  -1274//        final float
                                                                                                                                                                                                                                                                                                                  -1275//                rx = NumberTools.formFloat(seed + (~seed << 15)) + 0.5f,
                                                                                                                                                                                                                                                                                                                  -1276//                ry = NumberTools.formFloat(~seed ^ (seed << 14)) + 0.5f,
                                                                                                                                                                                                                                                                                                                  -1277//                x0y0 = (((x - 0.5f) * rx) + ((y - 0.5f) * ry)),
                                                                                                                                                                                                                                                                                                                  -1278//                x0y1 = (((x - 0.5f) * rx) + ((y + 0.5f) * ry)),
                                                                                                                                                                                                                                                                                                                  -1279//                x1y0 = (((x + 0.5f) * rx) + ((y - 0.5f) * ry)),
                                                                                                                                                                                                                                                                                                                  -1280//                x1y1 = (((x + 0.5f) * rx) + ((y + 0.5f) * ry));
                                                                                                                                                                                                                                                                                                                  -1281//        return NumberTools.sway(x0y0 + x1y0 + x0y1 + x1y1);
                                                                                                                                                                                                                                                                                                                  -1282        // produces a spotted pattern
                                                                                                                                                                                                                                                                                                                  -1283        final float[] jitterLUT = MeadNoise.jitter2DLUT;
                                                                                                                                                                                                                                                                                                                  -1284        final int s = (0x632BE5AB + seed * 0x9E3779B9) ^ 0x85157AF5;
                                                                                                                                                                                                                                                                                                                  -1285        final float
                                                                                                                                                                                                                                                                                                                  -1286                //gxy = NumberTools.zigzag(x + y) * 0.3f + 0.7f,
                                                                                                                                                                                                                                                                                                                  -1287                sx = NumberTools.zigzag(x) * 0.23f, sy = NumberTools.zigzag(y) * 0.23f,
                                                                                                                                                                                                                                                                                                                  -1288                mx0 = jitterLUT[(s & 255) << 1], my0 = jitterLUT[(s & 255) << 1 | 1],
                                                                                                                                                                                                                                                                                                                  -1289                mx1 = jitterLUT[(s >>> 8 & 255) << 1], my1 = jitterLUT[(s >>> 8 & 255) << 1 | 1],
                                                                                                                                                                                                                                                                                                                  -1290                mx2 = jitterLUT[(s >>> 16 & 255) << 1], my2 = jitterLUT[(s >>> 16 & 255) << 1 | 1],
                                                                                                                                                                                                                                                                                                                  -1291                mx3 = jitterLUT[(s >>> 24) << 1], my3 = jitterLUT[(s >>> 24) << 1 | 1];
                                                                                                                                                                                                                                                                                                                  -1292        x *= 7f;
                                                                                                                                                                                                                                                                                                                  -1293        y *= 7f;
                                                                                                                                                                                                                                                                                                                  -1294        return NumberTools.sway(
                                                                                                                                                                                                                                                                                                                  -1295                        (NumberTools.sway(mx0 * x + my0 * y) * (0.26f + sx)) +
                                                                                                                                                                                                                                                                                                                  -1296                        (NumberTools.sway(mx1 * x + my1 * y) * (0.26f + sy)) +
                                                                                                                                                                                                                                                                                                                  -1297                        (NumberTools.sway(mx2 * x + my2 * y) * (0.26f - sy)) +
                                                                                                                                                                                                                                                                                                                  -1298                        (NumberTools.sway(mx3 * x + my3 * y) * (0.26f - sx)));
                                                                                                                                                                                                                                                                                                                  -1299
                                                                                                                                                                                                                                                                                                                  -1300        //original
                                                                                                                                                                                                                                                                                                                  -1301//        final float s = (x + y) * F2;
                                                                                                                                                                                                                                                                                                                  -1302//        final float[] gradient2DLUT = MeadNoise.gradient2DLUT, jitterLUT = MeadNoise.jitter2DLUT;
                                                                                                                                                                                                                                                                                                                  -1303//        final int i = fastFloor(x + s),
                                                                                                                                                                                                                                                                                                                  -1304//                j = fastFloor(y + s);
                                                                                                                                                                                                                                                                                                                  -1305//        float t = (i + j) * G2,
                                                                                                                                                                                                                                                                                                                  -1306//                x0 = x - (i - t),
                                                                                                                                                                                                                                                                                                                  -1307//                y0 = y - (j - t);
                                                                                                                                                                                                                                                                                                                  -1308//        int i1, j1;
                                                                                                                                                                                                                                                                                                                  -1309//        if (x0 > y0) {
                                                                                                                                                                                                                                                                                                                  -1310//            i1 = 1;
                                                                                                                                                                                                                                                                                                                  -1311//            j1 = 0;
                                                                                                                                                                                                                                                                                                                  -1312//        } else {
                                                                                                                                                                                                                                                                                                                  -1313//            i1 = 0;
                                                                                                                                                                                                                                                                                                                  -1314//            j1 = 1;
                                                                                                                                                                                                                                                                                                                  -1315//        }
                                                                                                                                                                                                                                                                                                                  -1316//        final int h0 = hash(i, j, seed) << 1,
                                                                                                                                                                                                                                                                                                                  -1317//                h1 = hash(i + i1, j + j1, seed) << 1,
                                                                                                                                                                                                                                                                                                                  -1318//                h2 = hash(i + 1, j + 1, seed) << 1;
                                                                                                                                                                                                                                                                                                                  -1319//        final float mx0 = jitterLUT[h0] * 0.5f, my0 = jitterLUT[h0 | 1] * 0.5f,
                                                                                                                                                                                                                                                                                                                  -1320//                mx1 = jitterLUT[h1] * 0.5f, my1 = jitterLUT[h1 | 1] * 0.5f,
                                                                                                                                                                                                                                                                                                                  -1321//                mx2 = jitterLUT[h2] * 0.5f, my2 = jitterLUT[h2 | 1] * 0.5f;
                                                                                                                                                                                                                                                                                                                  -1322//        final float
                                                                                                                                                                                                                                                                                                                  -1323//                x1 = x0 - i1 + G2,
                                                                                                                                                                                                                                                                                                                  -1324//                y1 = y0 - j1 + G2,
                                                                                                                                                                                                                                                                                                                  -1325//                x2 = x0 - 1f + 2f * G2,
                                                                                                                                                                                                                                                                                                                  -1326//                y2 = y0 - 1f + 2f * G2;
                                                                                                                                                                                                                                                                                                                  -1327//        float n0, n1, n2;
                                                                                                                                                                                                                                                                                                                  -1328//        float t0 = 0.5f - x0 * x0 - y0 * y0;
                                                                                                                                                                                                                                                                                                                  -1329//        if (t0 < 0)
                                                                                                                                                                                                                                                                                                                  -1330//            n0 = 0;
                                                                                                                                                                                                                                                                                                                  -1331//        else {
                                                                                                                                                                                                                                                                                                                  -1332//            t0 *= t0;
                                                                                                                                                                                                                                                                                                                  -1333//            n0 = t0 * ((x0 + mx0) * gradient2DLUT[h0] + (y0 + my0) * gradient2DLUT[h0 | 1]);
                                                                                                                                                                                                                                                                                                                  -1334//        }
                                                                                                                                                                                                                                                                                                                  -1335//        float t1 = 0.5f - x1 * x1 - y1 * y1;
                                                                                                                                                                                                                                                                                                                  -1336//        if (t1 < 0)
                                                                                                                                                                                                                                                                                                                  -1337//            n1 = 0;
                                                                                                                                                                                                                                                                                                                  -1338//        else {
                                                                                                                                                                                                                                                                                                                  -1339//            t1 *= t1;
                                                                                                                                                                                                                                                                                                                  -1340//            n1 = t1 * ((x1 + mx1) * gradient2DLUT[h1] + (y1 + my1) * gradient2DLUT[h1 | 1]);
                                                                                                                                                                                                                                                                                                                  -1341//        }
                                                                                                                                                                                                                                                                                                                  -1342//        float t2 = 0.5f - x2 * x2 - y2 * y2;
                                                                                                                                                                                                                                                                                                                  -1343//        if (t2 < 0)
                                                                                                                                                                                                                                                                                                                  -1344//            n2 = 0;
                                                                                                                                                                                                                                                                                                                  -1345//        else {
                                                                                                                                                                                                                                                                                                                  -1346//            t2 *= t2;
                                                                                                                                                                                                                                                                                                                  -1347//            n2 = t2 * ((x2 + mx2) * gradient2DLUT[h2] + (y2 + my2) * gradient2DLUT[h2 | 1]);
                                                                                                                                                                                                                                                                                                                  -1348//        }
                                                                                                                                                                                                                                                                                                                  -1349//        return NumberTools.bounce((n0 + n1 + n2) * 11.5f + 10f);
                                                                                                                                                                                                                                                                                                                  -1350    }
                                                                                                                                                                                                                                                                                                                  -1351
                                                                                                                                                                                                                                                                                                                  -1352    public static double noise(final double x, final double y, final double z, final int seed) {
                                                                                                                                                                                                                                                                                                                  -1353        return noise((float)x, (float)y, (float)z, seed);
                                                                                                                                                                                                                                                                                                                  -1354    }
                                                                                                                                                                                                                                                                                                                  -1355    public static float noise(float x, float y, float z, int seed) {
                                                                                                                                                                                                                                                                                                                  -1356        // produces a spotted pattern
                                                                                                                                                                                                                                                                                                                  -1357        final float[] jitterLUT = MeadNoise.jitter3DLUT;
                                                                                                                                                                                                                                                                                                                  -1358        seed = (0x632BE5AB + seed * 0x9E3779B9) ^ 0x85157AF5;
                                                                                                                                                                                                                                                                                                                  -1359        final float
                                                                                                                                                                                                                                                                                                                  -1360                //gxy = NumberTools.zigzag(x + y) * 0.3f + 0.7f,
                                                                                                                                                                                                                                                                                                                  -1361                sx = NumberTools.zigzag(x) * 0.47f, sy = NumberTools.zigzag(y) * 0.47f, sz = NumberTools.zigzag(z) * 0.47f,
                                                                                                                                                                                                                                                                                                                  -1362                mx0 = jitterLUT[(seed & 255) * 3], my0 = jitterLUT[(seed & 255) * 3 + 1], mz0 = jitterLUT[(seed & 255) * 3 + 2],
                                                                                                                                                                                                                                                                                                                  -1363                mx1 = jitterLUT[(seed >>> 8 & 255) * 3], my1 = jitterLUT[(seed >>> 8 & 255) * 3 + 1], mz1 = jitterLUT[(seed >>> 8 & 255) * 3 + 2],
                                                                                                                                                                                                                                                                                                                  -1364                mx2 = jitterLUT[(seed >>> 16 & 255) * 3], my2 = jitterLUT[(seed >>> 16 & 255) * 3 + 1], mz2 = jitterLUT[(seed >>> 16 & 255) * 3 + 2],
                                                                                                                                                                                                                                                                                                                  -1365                mx3 = jitterLUT[(seed >>> 24) * 3], my3 = jitterLUT[(seed >>> 24) * 3 + 1], mz3 = jitterLUT[(seed >>> 24) * 3 + 2];
                                                                                                                                                                                                                                                                                                                  -1366        x *= 7f;
                                                                                                                                                                                                                                                                                                                  -1367        y *= 7f;
                                                                                                                                                                                                                                                                                                                  -1368        z *= 7f;
                                                                                                                                                                                                                                                                                                                  -1369        return NumberTools.sway(
                                                                                                                                                                                                                                                                                                                  -1370                  (NumberTools.sway(mx0 * x + my0 * y + mz0 * z) * (0.23f + sy * sz)) +
                                                                                                                                                                                                                                                                                                                  -1371                        (NumberTools.sway(mx1 * x + my1 * y + mz1 * z) * (0.23f + sz * sz)) +
                                                                                                                                                                                                                                                                                                                  -1372                        (NumberTools.sway(mx2 * x + my2 * y + mz2 * z) * (0.23f + sx * sy)) +
                                                                                                                                                                                                                                                                                                                  -1373                        (NumberTools.sway(mx3 * x + my3 * y + mz3 * z) * (0.46f - sy * sz - sz * sz - sx * sy)));
                                                                                                                                                                                                                                                                                                                  -1374
                                                                                                                                                                                                                                                                                                                  -1375
                                                                                                                                                                                                                                                                                                                  -1376//        float n0, n1, n2, n3;
                                                                                                                                                                                                                                                                                                                  -1377//        final float[] gradient3DLUT = MeadNoise.gradient3DLUT, jitterLUT = MeadNoise.jitter3DLUT;
                                                                                                                                                                                                                                                                                                                  -1378//        final float s = (x + y + z) * F3;
                                                                                                                                                                                                                                                                                                                  -1379//        final int i = fastFloor(x + s),
                                                                                                                                                                                                                                                                                                                  -1380//                j = fastFloor(y + s),
                                                                                                                                                                                                                                                                                                                  -1381//                k = fastFloor(z + s);
                                                                                                                                                                                                                                                                                                                  -1382//
                                                                                                                                                                                                                                                                                                                  -1383//        final float t = (i + j + k) * G3;
                                                                                                                                                                                                                                                                                                                  -1384//        final float X0 = i - t, Y0 = j - t, Z0 = k - t,
                                                                                                                                                                                                                                                                                                                  -1385//                x0 = x - X0, y0 = y - Y0, z0 = z - Z0;
                                                                                                                                                                                                                                                                                                                  -1386//
                                                                                                                                                                                                                                                                                                                  -1387//        int i1, j1, k1;
                                                                                                                                                                                                                                                                                                                  -1388//        int i2, j2, k2;
                                                                                                                                                                                                                                                                                                                  -1389//
                                                                                                                                                                                                                                                                                                                  -1390//        if (x0 >= y0) {
                                                                                                                                                                                                                                                                                                                  -1391//            if (y0 >= z0) {
                                                                                                                                                                                                                                                                                                                  -1392//                i1 = 1;
                                                                                                                                                                                                                                                                                                                  -1393//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  -1394//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  -1395//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  -1396//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  -1397//                k2 = 0;
                                                                                                                                                                                                                                                                                                                  -1398//            } else if (x0 >= z0) {
                                                                                                                                                                                                                                                                                                                  -1399//                i1 = 1;
                                                                                                                                                                                                                                                                                                                  -1400//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  -1401//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  -1402//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  -1403//                j2 = 0;
                                                                                                                                                                                                                                                                                                                  -1404//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  -1405//            } else {
                                                                                                                                                                                                                                                                                                                  -1406//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  -1407//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  -1408//                k1 = 1;
                                                                                                                                                                                                                                                                                                                  -1409//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  -1410//                j2 = 0;
                                                                                                                                                                                                                                                                                                                  -1411//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  -1412//            }
                                                                                                                                                                                                                                                                                                                  -1413//        } else {
                                                                                                                                                                                                                                                                                                                  -1414//            if (y0 < z0) {
                                                                                                                                                                                                                                                                                                                  -1415//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  -1416//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  -1417//                k1 = 1;
                                                                                                                                                                                                                                                                                                                  -1418//                i2 = 0;
                                                                                                                                                                                                                                                                                                                  -1419//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  -1420//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  -1421//            } else if (x0 < z0) {
                                                                                                                                                                                                                                                                                                                  -1422//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  -1423//                j1 = 1;
                                                                                                                                                                                                                                                                                                                  -1424//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  -1425//                i2 = 0;
                                                                                                                                                                                                                                                                                                                  -1426//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  -1427//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  -1428//            } else {
                                                                                                                                                                                                                                                                                                                  -1429//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  -1430//                j1 = 1;
                                                                                                                                                                                                                                                                                                                  -1431//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  -1432//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  -1433//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  -1434//                k2 = 0;
                                                                                                                                                                                                                                                                                                                  -1435//            }
                                                                                                                                                                                                                                                                                                                  -1436//        }
                                                                                                                                                                                                                                                                                                                  -1437//
                                                                                                                                                                                                                                                                                                                  -1438//        float x1 = x0 - i1 + G3,
                                                                                                                                                                                                                                                                                                                  -1439//                y1 = y0 - j1 + G3,
                                                                                                                                                                                                                                                                                                                  -1440//                z1 = z0 - k1 + G3,
                                                                                                                                                                                                                                                                                                                  -1441//                x2 = x0 - i2 + 2f * G3,
                                                                                                                                                                                                                                                                                                                  -1442//                y2 = y0 - j2 + 2f * G3,
                                                                                                                                                                                                                                                                                                                  -1443//                z2 = z0 - k2 + 2f * G3,
                                                                                                                                                                                                                                                                                                                  -1444//                x3 = x0 - 1f + 3f * G3,
                                                                                                                                                                                                                                                                                                                  -1445//                y3 = y0 - 1f + 3f * G3,
                                                                                                                                                                                                                                                                                                                  -1446//                z3 = z0 - 1f + 3f * G3;
                                                                                                                                                                                                                                                                                                                  -1447//
                                                                                                                                                                                                                                                                                                                  -1448//        final int h0 = hash(i, j, k, seed) * 3,
                                                                                                                                                                                                                                                                                                                  -1449//                h1 = hash(i + i1, j + j1, k + k1, seed) * 3,
                                                                                                                                                                                                                                                                                                                  -1450//                h2 = hash(i + i2, j + j2, k + k2, seed) * 3,
                                                                                                                                                                                                                                                                                                                  -1451//                h3 = hash(i + 1, j + 1, k + 1, seed) * 3;
                                                                                                                                                                                                                                                                                                                  -1452//        final float mx0 = jitterLUT[h0] * 0.25f, my0 = jitterLUT[h0 + 1] * 0.25f, mz0 = jitterLUT[h0 + 2] * 0.25f,
                                                                                                                                                                                                                                                                                                                  -1453//                mx1 = jitterLUT[h1] * 0.25f, my1 = jitterLUT[h1 + 1] * 0.25f, mz1 = jitterLUT[h1 + 2] * 0.25f,
                                                                                                                                                                                                                                                                                                                  -1454//                mx2 = jitterLUT[h2] * 0.25f, my2 = jitterLUT[h2 + 1] * 0.25f, mz2 = jitterLUT[h2 + 2] * 0.25f,
                                                                                                                                                                                                                                                                                                                  -1455//                mx3 = jitterLUT[h3] * 0.25f, my3 = jitterLUT[h3 + 1] * 0.25f, mz3 = jitterLUT[h3 + 2] * 0.25f;
                                                                                                                                                                                                                                                                                                                  -1456//
                                                                                                                                                                                                                                                                                                                  -1457//        float t0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
                                                                                                                                                                                                                                                                                                                  -1458//        if (t0 < 0.0f)
                                                                                                                                                                                                                                                                                                                  -1459//            n0 = 0.0f;
                                                                                                                                                                                                                                                                                                                  -1460//        else {
                                                                                                                                                                                                                                                                                                                  -1461//            t0 *= t0;
                                                                                                                                                                                                                                                                                                                  -1462//            n0 = t0 * t0 * ((x0 + mx0) * gradient3DLUT[h0] + (y0 + my0) * gradient3DLUT[h0 + 1] + (z0 + mz0) * gradient3DLUT[h0 + 2]);
                                                                                                                                                                                                                                                                                                                  -1463//        }
                                                                                                                                                                                                                                                                                                                  -1464//
                                                                                                                                                                                                                                                                                                                  -1465//        float t1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
                                                                                                                                                                                                                                                                                                                  -1466//        if (t1 < 0.0f)
                                                                                                                                                                                                                                                                                                                  -1467//            n1 = 0.0f;
                                                                                                                                                                                                                                                                                                                  -1468//        else {
                                                                                                                                                                                                                                                                                                                  -1469//            t1 *= t1;
                                                                                                                                                                                                                                                                                                                  -1470//            n1 = t1 * t1 * ((x1 + mx1) * gradient3DLUT[h1] + (y1 + my1) * gradient3DLUT[h1 + 1] + (z1 + mz1) * gradient3DLUT[h1 + 2]);
                                                                                                                                                                                                                                                                                                                  -1471//        }
                                                                                                                                                                                                                                                                                                                  -1472//
                                                                                                                                                                                                                                                                                                                  -1473//        float t2 = 0.75f - x2 * x2 - y2 * y2 - z2 * z2;
                                                                                                                                                                                                                                                                                                                  -1474//        if (t2 < 0.0f)
                                                                                                                                                                                                                                                                                                                  -1475//            n2 = 0.0f;
                                                                                                                                                                                                                                                                                                                  -1476//        else {
                                                                                                                                                                                                                                                                                                                  -1477//            t2 *= t2;
                                                                                                                                                                                                                                                                                                                  -1478//            n2 = t2 * t2 * ((x2 + mx2) * gradient3DLUT[h2] + (y2 + my2) * gradient3DLUT[h2 + 1] + (z2 + mz2) * gradient3DLUT[h2 + 2]);
                                                                                                                                                                                                                                                                                                                  -1479//        }
                                                                                                                                                                                                                                                                                                                  -1480//
                                                                                                                                                                                                                                                                                                                  -1481//        float t3 = 0.75f - x3 * x3 - y3 * y3 - z3 * z3;
                                                                                                                                                                                                                                                                                                                  -1482//        if (t3 < 0.0f)
                                                                                                                                                                                                                                                                                                                  -1483//            n3 = 0.0f;
                                                                                                                                                                                                                                                                                                                  -1484//        else {
                                                                                                                                                                                                                                                                                                                  -1485//            t3 *= t3;
                                                                                                                                                                                                                                                                                                                  -1486//            n3 = t3 * t3 * ((x3 + mx3) * gradient3DLUT[h3] + (y3 + my3) * gradient3DLUT[h3 + 1] + (z3 + mz3) * gradient3DLUT[h3 + 2]);
                                                                                                                                                                                                                                                                                                                  -1487//        }
                                                                                                                                                                                                                                                                                                                  -1488//
                                                                                                                                                                                                                                                                                                                  -1489//        return NumberTools.bounce((18.0f * (n0 + n1 + n2 + n3)) + 10f);
                                                                                                                                                                                                                                                                                                                  -1490    }
                                                                                                                                                                                                                                                                                                                  -1491
                                                                                                                                                                                                                                                                                                                  -1492    public static double noise(final double x, final double y, final double z, final double w, final int seed) {
                                                                                                                                                                                                                                                                                                                  -1493        return noise((float)x, (float)y, (float)z, (float)w, seed);
                                                                                                                                                                                                                                                                                                                  -1494    }
                                                                                                                                                                                                                                                                                                                  -1495    public static double noise(final float x, final float y, final float z, final float w, final int seed) {
                                                                                                                                                                                                                                                                                                                  -1496        float n = 0.0f;
                                                                                                                                                                                                                                                                                                                  -1497        final float s = (x + y + z + w) * F4;
                                                                                                                                                                                                                                                                                                                  -1498        final int i = fastFloor(x + s), j = fastFloor(y + s), k = fastFloor(z + s), l = fastFloor(w + s);
                                                                                                                                                                                                                                                                                                                  -1499        final float[] gradient4DLUT = MeadNoise.gradient4DLUT;
                                                                                                                                                                                                                                                                                                                  -1500        final float t = (i + j + k + l) * G4,
                                                                                                                                                                                                                                                                                                                  -1501                X0 = i - t,
                                                                                                                                                                                                                                                                                                                  -1502                Y0 = j - t,
                                                                                                                                                                                                                                                                                                                  -1503                Z0 = k - t,
                                                                                                                                                                                                                                                                                                                  -1504                W0 = l - t,
                                                                                                                                                                                                                                                                                                                  -1505                x0 = x - X0,
                                                                                                                                                                                                                                                                                                                  -1506                y0 = y - Y0,
                                                                                                                                                                                                                                                                                                                  -1507                z0 = z - Z0,
                                                                                                                                                                                                                                                                                                                  -1508                w0 = w - W0;
                                                                                                                                                                                                                                                                                                                  -1509        final int c = (x0 > y0 ? 128 : 0) | (x0 > z0 ? 64 : 0) | (y0 > z0 ? 32 : 0) | (x0 > w0 ? 16 : 0) | (y0 > w0 ? 8 : 0) | (z0 > w0 ? 4 : 0);
                                                                                                                                                                                                                                                                                                                  -1510        final int i1 = SIMPLEX[c] >>> 2,
                                                                                                                                                                                                                                                                                                                  -1511                j1 = SIMPLEX[c | 1] >>> 2,
                                                                                                                                                                                                                                                                                                                  -1512                k1 = SIMPLEX[c | 2] >>> 2,
                                                                                                                                                                                                                                                                                                                  -1513                l1 = SIMPLEX[c | 3] >>> 2,
                                                                                                                                                                                                                                                                                                                  -1514                i2 = SIMPLEX[c] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  -1515                j2 = SIMPLEX[c | 1] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  -1516                k2 = SIMPLEX[c | 2] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  -1517                l2 = SIMPLEX[c | 3] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  -1518                i3 = SIMPLEX[c] & 1,
                                                                                                                                                                                                                                                                                                                  -1519                j3 = SIMPLEX[c | 1] & 1,
                                                                                                                                                                                                                                                                                                                  -1520                k3 = SIMPLEX[c | 2] & 1,
                                                                                                                                                                                                                                                                                                                  -1521                l3 = SIMPLEX[c | 3] & 1;
                                                                                                                                                                                                                                                                                                                  -1522        final float x1 = x0 - i1 + G4,
                                                                                                                                                                                                                                                                                                                  -1523                y1 = y0 - j1 + G4,
                                                                                                                                                                                                                                                                                                                  -1524                z1 = z0 - k1 + G4,
                                                                                                                                                                                                                                                                                                                  -1525                w1 = w0 - l1 + G4,
                                                                                                                                                                                                                                                                                                                  -1526                x2 = x0 - i2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  -1527                y2 = y0 - j2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  -1528                z2 = z0 - k2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  -1529                w2 = w0 - l2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  -1530                x3 = x0 - i3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  -1531                y3 = y0 - j3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  -1532                z3 = z0 - k3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  -1533                w3 = w0 - l3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  -1534                x4 = x0 - 1f + 4f * G4,
                                                                                                                                                                                                                                                                                                                  -1535                y4 = y0 - 1f + 4f * G4,
                                                                                                                                                                                                                                                                                                                  -1536                z4 = z0 - 1f + 4f * G4,
                                                                                                                                                                                                                                                                                                                  -1537                w4 = w0 - 1f + 4f * G4;
                                                                                                                                                                                                                                                                                                                  -1538        final int h0 = hash(i, j, k, l, seed) << 2,
                                                                                                                                                                                                                                                                                                                  -1539                h1 = hash(i + i1, j + j1, k + k1, l + l1, seed) << 2,
                                                                                                                                                                                                                                                                                                                  -1540                h2 = hash(i + i2, j + j2, k + k2, l + l2, seed) << 2,
                                                                                                                                                                                                                                                                                                                  -1541                h3 = hash(i + i3, j + j3, k + k3, l + l3, seed) << 2,
                                                                                                                                                                                                                                                                                                                  -1542                h4 = hash(i + 1, j + 1, k + 1, l + 1, seed) << 2;
                                                                                                                                                                                                                                                                                                                  -1543        float t0 = LIMIT4 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
                                                                                                                                                                                                                                                                                                                  -1544        if(t0 > 0) {
                                                                                                                                                                                                                                                                                                                  -1545            t0 *= t0;
                                                                                                                                                                                                                                                                                                                  -1546            n += t0 * t0 * (x0 * gradient4DLUT[h0] + y0 * gradient4DLUT[h0 | 1] + z0 * gradient4DLUT[h0 | 2] + w0 * gradient4DLUT[h0 | 3]);
                                                                                                                                                                                                                                                                                                                  -1547        }
                                                                                                                                                                                                                                                                                                                  -1548        float t1 = LIMIT4 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
                                                                                                                                                                                                                                                                                                                  -1549        if (t1 > 0) {
                                                                                                                                                                                                                                                                                                                  -1550            t1 *= t1;
                                                                                                                                                                                                                                                                                                                  -1551            n += t1 * t1 * (x1 * gradient4DLUT[h1] + y1 * gradient4DLUT[h1 | 1] + z1 * gradient4DLUT[h1 | 2] + w1 * gradient4DLUT[h1 | 3]);
                                                                                                                                                                                                                                                                                                                  -1552        }
                                                                                                                                                                                                                                                                                                                  -1553        float t2 = LIMIT4 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
                                                                                                                                                                                                                                                                                                                  -1554        if (t2 > 0) {
                                                                                                                                                                                                                                                                                                                  -1555            t2 *= t2;
                                                                                                                                                                                                                                                                                                                  -1556            n += t2 * t2 * (x2 * gradient4DLUT[h2] + y2 * gradient4DLUT[h2 | 1] + z2 * gradient4DLUT[h2 | 2] + w2 * gradient4DLUT[h2 | 3]);
                                                                                                                                                                                                                                                                                                                  -1557        }
                                                                                                                                                                                                                                                                                                                  -1558        float t3 = LIMIT4 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
                                                                                                                                                                                                                                                                                                                  -1559        if (t3 > 0) {
                                                                                                                                                                                                                                                                                                                  -1560            t3 *= t3;
                                                                                                                                                                                                                                                                                                                  -1561            n += t3 * t3 * (x3 * gradient4DLUT[h3] + y3 * gradient4DLUT[h3 | 1] + z3 * gradient4DLUT[h3 | 2] + w3 * gradient4DLUT[h3 | 3]);
                                                                                                                                                                                                                                                                                                                  -1562        }
                                                                                                                                                                                                                                                                                                                  -1563        float t4 = LIMIT4 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
                                                                                                                                                                                                                                                                                                                  -1564        if (t4 > 0) {
                                                                                                                                                                                                                                                                                                                  -1565            t4 *= t4;
                                                                                                                                                                                                                                                                                                                  -1566            n += t4 * t4 * (x4 * gradient4DLUT[h4] + y4 * gradient4DLUT[h4 | 1] + z4 * gradient4DLUT[h4 | 2] + w4 * gradient4DLUT[h4 | 3]);
                                                                                                                                                                                                                                                                                                                  -1567        }
                                                                                                                                                                                                                                                                                                                  -1568        return NumberTools.bounce(5.0 + 41.0 * n);
                                                                                                                                                                                                                                                                                                                  -1569    }
                                                                                                                                                                                                                                                                                                                  -1570
                                                                                                                                                                                                                                                                                                                  -1571
                                                                                                                                                                                                                                                                                                                  -1572    public static double noise(final double x, final double y, final double z,
                                                                                                                                                                                                                                                                                                                  -1573                               final double w, final double u, final double v, final int seed) {
                                                                                                                                                                                                                                                                                                                  -1574        return noise((float)x, (float)y, (float)z, (float)w, (float)u, (float)v, seed);
                                                                                                                                                                                                                                                                                                                  -1575    }
                                                                                                                                                                                                                                                                                                                  -1576
                                                                                                                                                                                                                                                                                                                  -1577    public static double noise(final float x, final float y, final float z, final float w, final float u, final float v, final int seed) {
                                                                                                                                                                                                                                                                                                                  -1578
                                                                                                                                                                                                                                                                                                                  -1579        final float s = (x + y + z + w + u + v) * F6;
                                                                                                                                                                                                                                                                                                                  -1580
                                                                                                                                                                                                                                                                                                                  -1581        final int skewX = fastFloor(x + s), skewY = fastFloor(y + s), skewZ = fastFloor(z + s),
                                                                                                                                                                                                                                                                                                                  -1582                skewW = fastFloor(w + s), skewU = fastFloor(u + s), skewV = fastFloor(v + s);
                                                                                                                                                                                                                                                                                                                  -1583        final int[] intLoc = MeadNoise.intLoc, distOrder = MeadNoise.distOrder;
                                                                                                                                                                                                                                                                                                                  -1584        intLoc[0] = skewX;
                                                                                                                                                                                                                                                                                                                  -1585        intLoc[1] = skewY;
                                                                                                                                                                                                                                                                                                                  -1586        intLoc[2] = skewZ;
                                                                                                                                                                                                                                                                                                                  -1587        intLoc[3] = skewW;
                                                                                                                                                                                                                                                                                                                  -1588        intLoc[4] = skewU;
                                                                                                                                                                                                                                                                                                                  -1589        intLoc[5] = skewV;
                                                                                                                                                                                                                                                                                                                  -1590
                                                                                                                                                                                                                                                                                                                  -1591        final float unskew = (skewX + skewY + skewZ + skewW + skewU + skewV) * G6;
                                                                                                                                                                                                                                                                                                                  -1592        final float[] cellDist = MeadNoise.cellDist, gradient6DLUT = MeadNoise.gradient6DLUT;
                                                                                                                                                                                                                                                                                                                  -1593        cellDist[0] = x - skewX + unskew;
                                                                                                                                                                                                                                                                                                                  -1594        cellDist[1] = y - skewY + unskew;
                                                                                                                                                                                                                                                                                                                  -1595        cellDist[2] = z - skewZ + unskew;
                                                                                                                                                                                                                                                                                                                  -1596        cellDist[3] = w - skewW + unskew;
                                                                                                                                                                                                                                                                                                                  -1597        cellDist[4] = u - skewU + unskew;
                                                                                                                                                                                                                                                                                                                  -1598        cellDist[5] = v - skewV + unskew;
                                                                                                                                                                                                                                                                                                                  -1599
                                                                                                                                                                                                                                                                                                                  -1600        int o0 = (cellDist[0]<cellDist[1]?1:0)+(cellDist[0]<cellDist[2]?1:0)+(cellDist[0]<cellDist[3]?1:0)+(cellDist[0]<cellDist[4]?1:0)+(cellDist[0]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  -1601        int o1 = (cellDist[1]<=cellDist[0]?1:0)+(cellDist[1]<cellDist[2]?1:0)+(cellDist[1]<cellDist[3]?1:0)+(cellDist[1]<cellDist[4]?1:0)+(cellDist[1]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  -1602        int o2 = (cellDist[2]<=cellDist[0]?1:0)+(cellDist[2]<=cellDist[1]?1:0)+(cellDist[2]<cellDist[3]?1:0)+(cellDist[2]<cellDist[4]?1:0)+(cellDist[2]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  -1603        int o3 = (cellDist[3]<=cellDist[0]?1:0)+(cellDist[3]<=cellDist[1]?1:0)+(cellDist[3]<=cellDist[2]?1:0)+(cellDist[3]<cellDist[4]?1:0)+(cellDist[3]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  -1604        int o4 = (cellDist[4]<=cellDist[0]?1:0)+(cellDist[4]<=cellDist[1]?1:0)+(cellDist[4]<=cellDist[2]?1:0)+(cellDist[4]<=cellDist[3]?1:0)+(cellDist[4]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  -1605        int o5 = 15-(o0+o1+o2+o3+o4);
                                                                                                                                                                                                                                                                                                                  -1606
                                                                                                                                                                                                                                                                                                                  -1607        distOrder[o0]=0;
                                                                                                                                                                                                                                                                                                                  -1608        distOrder[o1]=1;
                                                                                                                                                                                                                                                                                                                  -1609        distOrder[o2]=2;
                                                                                                                                                                                                                                                                                                                  -1610        distOrder[o3]=3;
                                                                                                                                                                                                                                                                                                                  -1611        distOrder[o4]=4;
                                                                                                                                                                                                                                                                                                                  -1612        distOrder[o5]=5;
                                                                                                                                                                                                                                                                                                                  -1613
                                                                                                                                                                                                                                                                                                                  -1614        float n = 0f;
                                                                                                                                                                                                                                                                                                                  -1615        float skewOffset = 0f;
                                                                                                                                                                                                                                                                                                                  +1253    private static final double
                                                                                                                                                                                                                                                                                                                  +1254            PI_F = 3.14159265358979323846,
                                                                                                                                                                                                                                                                                                                  +1255            PHI_F = 1.618033988749895,
                                                                                                                                                                                                                                                                                                                  +1256            I_PHI_F = 0.6180339887498949,
                                                                                                                                                                                                                                                                                                                  +1257            HALF_PI_F = 1.5707963267948966;
                                                                                                                                                                                                                                                                                                                  +1258    /*
                                                                                                                                                                                                                                                                                                                  +1259     * Quintic-interpolates between start and end (valid floats), with a between 0 (yields start) and 1 (yields end).
                                                                                                                                                                                                                                                                                                                  +1260     * Will smoothly transition toward start or end as a approaches 0 or 1, respectively.
                                                                                                                                                                                                                                                                                                                  +1261     * @param start a valid float
                                                                                                                                                                                                                                                                                                                  +1262     * @param end a valid float
                                                                                                                                                                                                                                                                                                                  +1263     * @param a a float between 0 and 1 inclusive
                                                                                                                                                                                                                                                                                                                  +1264     * @return a float between x and y inclusive
                                                                                                                                                                                                                                                                                                                  +1265     */
                                                                                                                                                                                                                                                                                                                  +1266    public static float querp(final float start, final float end, float a){
                                                                                                                                                                                                                                                                                                                  +1267        return (1f - (a *= a * a * (a * (a * 6f - 15f) + 10f))) * start + a * end;
                                                                                                                                                                                                                                                                                                                  +1268    }
                                                                                                                                                                                                                                                                                                                  +1269    /*
                                                                                                                                                                                                                                                                                                                  +1270     * Quintic-interpolates between start and end (valid floats), with a between 0 (yields start) and 1 (yields end).
                                                                                                                                                                                                                                                                                                                  +1271     * Will smoothly transition toward start or end as a approaches 0 or 1, respectively.
                                                                                                                                                                                                                                                                                                                  +1272     * @param start a valid float
                                                                                                                                                                                                                                                                                                                  +1273     * @param end a valid float
                                                                                                                                                                                                                                                                                                                  +1274     * @param a a float between 0 and 1 inclusive
                                                                                                                                                                                                                                                                                                                  +1275     * @return a float between x and y inclusive
                                                                                                                                                                                                                                                                                                                  +1276     */
                                                                                                                                                                                                                                                                                                                  +1277    public static double querp(final double start, final double end, double a){
                                                                                                                                                                                                                                                                                                                  +1278        return (1.0 - (a *= a * a * (a * (a * 6.0 - 15.0) + 10.0))) * start + a * end;
                                                                                                                                                                                                                                                                                                                  +1279    }
                                                                                                                                                                                                                                                                                                                  +1280
                                                                                                                                                                                                                                                                                                                  +1281    public static double noise(double x, double y, int seed) {
                                                                                                                                                                                                                                                                                                                  +1282//        final float
                                                                                                                                                                                                                                                                                                                  +1283//                rx = NumberTools.formFloat(seed + (~seed << 15)) + 0.5f,
                                                                                                                                                                                                                                                                                                                  +1284//                ry = NumberTools.formFloat(~seed ^ (seed << 14)) + 0.5f,
                                                                                                                                                                                                                                                                                                                  +1285//                x0y0 = (((x - 0.5f) * rx) + ((y - 0.5f) * ry)),
                                                                                                                                                                                                                                                                                                                  +1286//                x0y1 = (((x - 0.5f) * rx) + ((y + 0.5f) * ry)),
                                                                                                                                                                                                                                                                                                                  +1287//                x1y0 = (((x + 0.5f) * rx) + ((y - 0.5f) * ry)),
                                                                                                                                                                                                                                                                                                                  +1288//                x1y1 = (((x + 0.5f) * rx) + ((y + 0.5f) * ry));
                                                                                                                                                                                                                                                                                                                  +1289//        return NumberTools.sway(x0y0 + x1y0 + x0y1 + x1y1);
                                                                                                                                                                                                                                                                                                                  +1290        x *= 3.25;
                                                                                                                                                                                                                                                                                                                  +1291        y *= 3.25;
                                                                                                                                                                                                                                                                                                                  +1292        final float[] jitterLUT = MeadNoise.jitter2DLUT;
                                                                                                                                                                                                                                                                                                                  +1293        final long s = ThrustRNG.determine(seed);
                                                                                                                                                                                                                                                                                                                  +1294        final double
                                                                                                                                                                                                                                                                                                                  +1295                r = NumberTools.longBitsToDouble((longFloor(s * x + y * s * s + s) & 0x000FFFFFFFFFFFFFL) | 0x3FF0000000000000L) * 0.6 - 0.4,
                                                                                                                                                                                                                                                                                                                  +1296                mx0 = jitterLUT[(seed & 510)] * PI_F * r, my0 = jitterLUT[(seed & 510)|1] * PI_F * (1.0 - r),
                                                                                                                                                                                                                                                                                                                  +1297                mx1 = jitterLUT[(seed >>> 10 & 510)] * PI_F * r, my1 = jitterLUT[(seed >>> 10 & 510)|1] * PI_F * (1.0 - r),
                                                                                                                                                                                                                                                                                                                  +1298                sx = NumberTools.sway(x * mx0 + y * my0) * 0.55, sy = NumberTools.sway(y * mx1 + x * my1) * 0.55;
                                                                                                                                                                                                                                                                                                                  +1299        final long ix = longFloor(x + sy), iy = longFloor(y + sx);
                                                                                                                                                                                                                                                                                                                  +1300        final double
                                                                                                                                                                                                                                                                                                                  +1301                rx0y0 = NumberTools.longBitsToDouble((ThrustRNG.determine(ix << 32 ^ iy) & 0x000FFFFFFFFFFFFFL) | 0x4000000000000000L),
                                                                                                                                                                                                                                                                                                                  +1302                rx1y0 = NumberTools.longBitsToDouble((ThrustRNG.determine((ix+1L) << 32 ^ iy) & 0x000FFFFFFFFFFFFFL) | 0x4000000000000000L),
                                                                                                                                                                                                                                                                                                                  +1303                rx0y1 = NumberTools.longBitsToDouble((ThrustRNG.determine(ix << 32 ^ (iy+1L)) & 0x000FFFFFFFFFFFFFL) | 0x4000000000000000L),
                                                                                                                                                                                                                                                                                                                  +1304                rx1y1 = NumberTools.longBitsToDouble((ThrustRNG.determine((ix+1L) << 32 ^ (iy+1L)) & 0x000FFFFFFFFFFFFFL) | 0x4000000000000000L),
                                                                                                                                                                                                                                                                                                                  +1305                dx = x + sy - ix, dy = y + sx - iy;
                                                                                                                                                                                                                                                                                                                  +1306        //return NumberTools.sway(rx0y0 * ux * uy + rx0y1 * dy * ux + rx1y0 * dx + uy + rx1y1 * dy + dx);
                                                                                                                                                                                                                                                                                                                  +1307        return querp(
                                                                                                                                                                                                                                                                                                                  +1308                querp(rx0y0, rx0y1, dy),
                                                                                                                                                                                                                                                                                                                  +1309                querp(rx1y0, rx1y1, dy), dx) - 3.0;
                                                                                                                                                                                                                                                                                                                  +1310
                                                                                                                                                                                                                                                                                                                  +1311        //very periodic...
                                                                                                                                                                                                                                                                                                                  +1312//        final double
                                                                                                                                                                                                                                                                                                                  +1313//                cx = NumberTools.sway(x * PHI_F *
                                                                                                                                                                                                                                                                                                                  +1314//                (NumberTools.formFloat(seed ^= 0x632BE5AB + (seed * 0x9E3779B9 >> 4) * 181) - HALF_PI_F)) + I_PHI_F,
                                                                                                                                                                                                                                                                                                                  +1315//                cy = NumberTools.sway(y * PHI_F +
                                                                                                                                                                                                                                                                                                                  +1316//                        (NumberTools.formFloat(seed ^= 0x632BE5AB + (seed * 0x9E3779B9 >> 4) * 181) - HALF_PI_F)) + I_PHI_F,
                                                                                                                                                                                                                                                                                                                  +1317//                ca = NumberTools.sway((cx + cy) * 0x3.337p-3f *
                                                                                                                                                                                                                                                                                                                  +1318//                        (NumberTools.formFloat(seed ^ 0x632BE5AB + (seed * 0x9E3779B9 >> 4) * 181) - PHI_F)) - I_PHI_F;
                                                                                                                                                                                                                                                                                                                  +1319//                //ca = NumberTools.formCurvedFloat(seed ^= 0x632BE5AB + (seed * 0x9E3779B9 >> 4) * 181, fastFloor(y * x - (y + x) * 7f) * seed) * (seed >> 16);
                                                                                                                                                                                                                                                                                                                  +1320//        return NumberTools.sway((cx + cy) * 2.14f - ca * 3.718f);
                                                                                                                                                                                                                                                                                                                  +1321        // produces a spotted pattern
                                                                                                                                                                                                                                                                                                                  +1322//        final float[] jitterLUT = MeadNoise.jitter2DLUT;
                                                                                                                                                                                                                                                                                                                  +1323//        final int s = (0x632BE5AB + seed * 0x9E3779B9) ^ 0x85157AF5;
                                                                                                                                                                                                                                                                                                                  +1324//        final float
                                                                                                                                                                                                                                                                                                                  +1325//                //gxy = NumberTools.zigzag(x + y) * 0.3f + 0.7f,
                                                                                                                                                                                                                                                                                                                  +1326//                sx = NumberTools.sway(x * HALF_PI_F) * 0.42f, sy = NumberTools.sway(y * HALF_PI_F) * 0.42f,
                                                                                                                                                                                                                                                                                                                  +1327//                //sxy = NumberTools.sway((x + y) * PHI_F) * 0.72f,
                                                                                                                                                                                                                                                                                                                  +1328//                mx0 = jitterLUT[(s & 255) << 1], my0 = jitterLUT[(s & 255) << 1 | 1],
                                                                                                                                                                                                                                                                                                                  +1329//                mx1 = jitterLUT[(s >>> 8 & 255) << 1], my1 = jitterLUT[(s >>> 8 & 255) << 1 | 1],
                                                                                                                                                                                                                                                                                                                  +1330//                mx2 = jitterLUT[(s >>> 16 & 255) << 1], my2 = jitterLUT[(s >>> 16 & 255) << 1 | 1],
                                                                                                                                                                                                                                                                                                                  +1331//                mx3 = jitterLUT[(s >>> 24) << 1], my3 = jitterLUT[(s >>> 24) << 1 | 1];
                                                                                                                                                                                                                                                                                                                  +1332//        x *= 5.25f;
                                                                                                                                                                                                                                                                                                                  +1333//        y *= 5.25f;
                                                                                                                                                                                                                                                                                                                  +1334//        return NumberTools.sway((
                                                                                                                                                                                                                                                                                                                  +1335//                        (NumberTools.sway(mx0 * x + my0 * y) * (2f + sx)) +
                                                                                                                                                                                                                                                                                                                  +1336//                        (NumberTools.sway(mx1 * x + my1 * y) * (2f + sy)) +
                                                                                                                                                                                                                                                                                                                  +1337//                        (NumberTools.sway(mx2 * x + my2 * y) * (2f - sy)) +
                                                                                                                                                                                                                                                                                                                  +1338//                        (NumberTools.sway(mx3 * x + my3 * y) * (2f - sx))) * 0.3f);
                                                                                                                                                                                                                                                                                                                  +1339
                                                                                                                                                                                                                                                                                                                  +1340        //original
                                                                                                                                                                                                                                                                                                                  +1341//        final float s = (x + y) * F2;
                                                                                                                                                                                                                                                                                                                  +1342//        final float[] gradient2DLUT = MeadNoise.gradient2DLUT, jitterLUT = MeadNoise.jitter2DLUT;
                                                                                                                                                                                                                                                                                                                  +1343//        final int i = fastFloor(x + s),
                                                                                                                                                                                                                                                                                                                  +1344//                j = fastFloor(y + s);
                                                                                                                                                                                                                                                                                                                  +1345//        float t = (i + j) * G2,
                                                                                                                                                                                                                                                                                                                  +1346//                x0 = x - (i - t),
                                                                                                                                                                                                                                                                                                                  +1347//                y0 = y - (j - t);
                                                                                                                                                                                                                                                                                                                  +1348//        int i1, j1;
                                                                                                                                                                                                                                                                                                                  +1349//        if (x0 > y0) {
                                                                                                                                                                                                                                                                                                                  +1350//            i1 = 1;
                                                                                                                                                                                                                                                                                                                  +1351//            j1 = 0;
                                                                                                                                                                                                                                                                                                                  +1352//        } else {
                                                                                                                                                                                                                                                                                                                  +1353//            i1 = 0;
                                                                                                                                                                                                                                                                                                                  +1354//            j1 = 1;
                                                                                                                                                                                                                                                                                                                  +1355//        }
                                                                                                                                                                                                                                                                                                                  +1356//        final int h0 = hash(i, j, seed) << 1,
                                                                                                                                                                                                                                                                                                                  +1357//                h1 = hash(i + i1, j + j1, seed) << 1,
                                                                                                                                                                                                                                                                                                                  +1358//                h2 = hash(i + 1, j + 1, seed) << 1;
                                                                                                                                                                                                                                                                                                                  +1359//        final float mx0 = jitterLUT[h0] * 0.5f, my0 = jitterLUT[h0 | 1] * 0.5f,
                                                                                                                                                                                                                                                                                                                  +1360//                mx1 = jitterLUT[h1] * 0.5f, my1 = jitterLUT[h1 | 1] * 0.5f,
                                                                                                                                                                                                                                                                                                                  +1361//                mx2 = jitterLUT[h2] * 0.5f, my2 = jitterLUT[h2 | 1] * 0.5f;
                                                                                                                                                                                                                                                                                                                  +1362//        final float
                                                                                                                                                                                                                                                                                                                  +1363//                x1 = x0 - i1 + G2,
                                                                                                                                                                                                                                                                                                                  +1364//                y1 = y0 - j1 + G2,
                                                                                                                                                                                                                                                                                                                  +1365//                x2 = x0 - 1f + 2f * G2,
                                                                                                                                                                                                                                                                                                                  +1366//                y2 = y0 - 1f + 2f * G2;
                                                                                                                                                                                                                                                                                                                  +1367//        float n0, n1, n2;
                                                                                                                                                                                                                                                                                                                  +1368//        float t0 = 0.5f - x0 * x0 - y0 * y0;
                                                                                                                                                                                                                                                                                                                  +1369//        if (t0 < 0)
                                                                                                                                                                                                                                                                                                                  +1370//            n0 = 0;
                                                                                                                                                                                                                                                                                                                  +1371//        else {
                                                                                                                                                                                                                                                                                                                  +1372//            t0 *= t0;
                                                                                                                                                                                                                                                                                                                  +1373//            n0 = t0 * ((x0 + mx0) * gradient2DLUT[h0] + (y0 + my0) * gradient2DLUT[h0 | 1]);
                                                                                                                                                                                                                                                                                                                  +1374//        }
                                                                                                                                                                                                                                                                                                                  +1375//        float t1 = 0.5f - x1 * x1 - y1 * y1;
                                                                                                                                                                                                                                                                                                                  +1376//        if (t1 < 0)
                                                                                                                                                                                                                                                                                                                  +1377//            n1 = 0;
                                                                                                                                                                                                                                                                                                                  +1378//        else {
                                                                                                                                                                                                                                                                                                                  +1379//            t1 *= t1;
                                                                                                                                                                                                                                                                                                                  +1380//            n1 = t1 * ((x1 + mx1) * gradient2DLUT[h1] + (y1 + my1) * gradient2DLUT[h1 | 1]);
                                                                                                                                                                                                                                                                                                                  +1381//        }
                                                                                                                                                                                                                                                                                                                  +1382//        float t2 = 0.5f - x2 * x2 - y2 * y2;
                                                                                                                                                                                                                                                                                                                  +1383//        if (t2 < 0)
                                                                                                                                                                                                                                                                                                                  +1384//            n2 = 0;
                                                                                                                                                                                                                                                                                                                  +1385//        else {
                                                                                                                                                                                                                                                                                                                  +1386//            t2 *= t2;
                                                                                                                                                                                                                                                                                                                  +1387//            n2 = t2 * ((x2 + mx2) * gradient2DLUT[h2] + (y2 + my2) * gradient2DLUT[h2 | 1]);
                                                                                                                                                                                                                                                                                                                  +1388//        }
                                                                                                                                                                                                                                                                                                                  +1389//        return NumberTools.bounce((n0 + n1 + n2) * 11.5f + 10f);
                                                                                                                                                                                                                                                                                                                  +1390    }
                                                                                                                                                                                                                                                                                                                  +1391
                                                                                                                                                                                                                                                                                                                  +1392    public static double noise(final double x, final double y, final double z, final int seed) {
                                                                                                                                                                                                                                                                                                                  +1393        return noise((float)x, (float)y, (float)z, seed);
                                                                                                                                                                                                                                                                                                                  +1394    }
                                                                                                                                                                                                                                                                                                                  +1395    public static float noise(float x, float y, float z, int seed) {
                                                                                                                                                                                                                                                                                                                  +1396        // produces a spotted pattern
                                                                                                                                                                                                                                                                                                                  +1397        final float[] jitterLUT = MeadNoise.jitter3DLUT;
                                                                                                                                                                                                                                                                                                                  +1398        seed = (0x632BE5AB + seed * 0x9E3779B9) ^ 0x85157AF5;
                                                                                                                                                                                                                                                                                                                  +1399        final float
                                                                                                                                                                                                                                                                                                                  +1400                //gxy = NumberTools.zigzag(x + y) * 0.3f + 0.7f,
                                                                                                                                                                                                                                                                                                                  +1401                sx = NumberTools.zigzag(x) * 0.47f, sy = NumberTools.zigzag(y) * 0.47f, sz = NumberTools.zigzag(z) * 0.47f,
                                                                                                                                                                                                                                                                                                                  +1402                mx0 = jitterLUT[(seed & 255) * 3], my0 = jitterLUT[(seed & 255) * 3 + 1], mz0 = jitterLUT[(seed & 255) * 3 + 2],
                                                                                                                                                                                                                                                                                                                  +1403                mx1 = jitterLUT[(seed >>> 8 & 255) * 3], my1 = jitterLUT[(seed >>> 8 & 255) * 3 + 1], mz1 = jitterLUT[(seed >>> 8 & 255) * 3 + 2],
                                                                                                                                                                                                                                                                                                                  +1404                mx2 = jitterLUT[(seed >>> 16 & 255) * 3], my2 = jitterLUT[(seed >>> 16 & 255) * 3 + 1], mz2 = jitterLUT[(seed >>> 16 & 255) * 3 + 2],
                                                                                                                                                                                                                                                                                                                  +1405                mx3 = jitterLUT[(seed >>> 24) * 3], my3 = jitterLUT[(seed >>> 24) * 3 + 1], mz3 = jitterLUT[(seed >>> 24) * 3 + 2];
                                                                                                                                                                                                                                                                                                                  +1406        x *= 7f;
                                                                                                                                                                                                                                                                                                                  +1407        y *= 7f;
                                                                                                                                                                                                                                                                                                                  +1408        z *= 7f;
                                                                                                                                                                                                                                                                                                                  +1409        return NumberTools.sway(
                                                                                                                                                                                                                                                                                                                  +1410                  (NumberTools.sway(mx0 * x + my0 * y + mz0 * z) * (0.23f + sy * sz)) +
                                                                                                                                                                                                                                                                                                                  +1411                        (NumberTools.sway(mx1 * x + my1 * y + mz1 * z) * (0.23f + sz * sz)) +
                                                                                                                                                                                                                                                                                                                  +1412                        (NumberTools.sway(mx2 * x + my2 * y + mz2 * z) * (0.23f + sx * sy)) +
                                                                                                                                                                                                                                                                                                                  +1413                        (NumberTools.sway(mx3 * x + my3 * y + mz3 * z) * (0.46f - sy * sz - sz * sz - sx * sy)));
                                                                                                                                                                                                                                                                                                                  +1414
                                                                                                                                                                                                                                                                                                                  +1415
                                                                                                                                                                                                                                                                                                                  +1416//        float n0, n1, n2, n3;
                                                                                                                                                                                                                                                                                                                  +1417//        final float[] gradient3DLUT = MeadNoise.gradient3DLUT, jitterLUT = MeadNoise.jitter3DLUT;
                                                                                                                                                                                                                                                                                                                  +1418//        final float s = (x + y + z) * F3;
                                                                                                                                                                                                                                                                                                                  +1419//        final int i = fastFloor(x + s),
                                                                                                                                                                                                                                                                                                                  +1420//                j = fastFloor(y + s),
                                                                                                                                                                                                                                                                                                                  +1421//                k = fastFloor(z + s);
                                                                                                                                                                                                                                                                                                                  +1422//
                                                                                                                                                                                                                                                                                                                  +1423//        final float t = (i + j + k) * G3;
                                                                                                                                                                                                                                                                                                                  +1424//        final float X0 = i - t, Y0 = j - t, Z0 = k - t,
                                                                                                                                                                                                                                                                                                                  +1425//                x0 = x - X0, y0 = y - Y0, z0 = z - Z0;
                                                                                                                                                                                                                                                                                                                  +1426//
                                                                                                                                                                                                                                                                                                                  +1427//        int i1, j1, k1;
                                                                                                                                                                                                                                                                                                                  +1428//        int i2, j2, k2;
                                                                                                                                                                                                                                                                                                                  +1429//
                                                                                                                                                                                                                                                                                                                  +1430//        if (x0 >= y0) {
                                                                                                                                                                                                                                                                                                                  +1431//            if (y0 >= z0) {
                                                                                                                                                                                                                                                                                                                  +1432//                i1 = 1;
                                                                                                                                                                                                                                                                                                                  +1433//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  +1434//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  +1435//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  +1436//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  +1437//                k2 = 0;
                                                                                                                                                                                                                                                                                                                  +1438//            } else if (x0 >= z0) {
                                                                                                                                                                                                                                                                                                                  +1439//                i1 = 1;
                                                                                                                                                                                                                                                                                                                  +1440//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  +1441//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  +1442//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  +1443//                j2 = 0;
                                                                                                                                                                                                                                                                                                                  +1444//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  +1445//            } else {
                                                                                                                                                                                                                                                                                                                  +1446//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  +1447//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  +1448//                k1 = 1;
                                                                                                                                                                                                                                                                                                                  +1449//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  +1450//                j2 = 0;
                                                                                                                                                                                                                                                                                                                  +1451//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  +1452//            }
                                                                                                                                                                                                                                                                                                                  +1453//        } else {
                                                                                                                                                                                                                                                                                                                  +1454//            if (y0 < z0) {
                                                                                                                                                                                                                                                                                                                  +1455//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  +1456//                j1 = 0;
                                                                                                                                                                                                                                                                                                                  +1457//                k1 = 1;
                                                                                                                                                                                                                                                                                                                  +1458//                i2 = 0;
                                                                                                                                                                                                                                                                                                                  +1459//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  +1460//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  +1461//            } else if (x0 < z0) {
                                                                                                                                                                                                                                                                                                                  +1462//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  +1463//                j1 = 1;
                                                                                                                                                                                                                                                                                                                  +1464//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  +1465//                i2 = 0;
                                                                                                                                                                                                                                                                                                                  +1466//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  +1467//                k2 = 1;
                                                                                                                                                                                                                                                                                                                  +1468//            } else {
                                                                                                                                                                                                                                                                                                                  +1469//                i1 = 0;
                                                                                                                                                                                                                                                                                                                  +1470//                j1 = 1;
                                                                                                                                                                                                                                                                                                                  +1471//                k1 = 0;
                                                                                                                                                                                                                                                                                                                  +1472//                i2 = 1;
                                                                                                                                                                                                                                                                                                                  +1473//                j2 = 1;
                                                                                                                                                                                                                                                                                                                  +1474//                k2 = 0;
                                                                                                                                                                                                                                                                                                                  +1475//            }
                                                                                                                                                                                                                                                                                                                  +1476//        }
                                                                                                                                                                                                                                                                                                                  +1477//
                                                                                                                                                                                                                                                                                                                  +1478//        float x1 = x0 - i1 + G3,
                                                                                                                                                                                                                                                                                                                  +1479//                y1 = y0 - j1 + G3,
                                                                                                                                                                                                                                                                                                                  +1480//                z1 = z0 - k1 + G3,
                                                                                                                                                                                                                                                                                                                  +1481//                x2 = x0 - i2 + 2f * G3,
                                                                                                                                                                                                                                                                                                                  +1482//                y2 = y0 - j2 + 2f * G3,
                                                                                                                                                                                                                                                                                                                  +1483//                z2 = z0 - k2 + 2f * G3,
                                                                                                                                                                                                                                                                                                                  +1484//                x3 = x0 - 1f + 3f * G3,
                                                                                                                                                                                                                                                                                                                  +1485//                y3 = y0 - 1f + 3f * G3,
                                                                                                                                                                                                                                                                                                                  +1486//                z3 = z0 - 1f + 3f * G3;
                                                                                                                                                                                                                                                                                                                  +1487//
                                                                                                                                                                                                                                                                                                                  +1488//        final int h0 = hash(i, j, k, seed) * 3,
                                                                                                                                                                                                                                                                                                                  +1489//                h1 = hash(i + i1, j + j1, k + k1, seed) * 3,
                                                                                                                                                                                                                                                                                                                  +1490//                h2 = hash(i + i2, j + j2, k + k2, seed) * 3,
                                                                                                                                                                                                                                                                                                                  +1491//                h3 = hash(i + 1, j + 1, k + 1, seed) * 3;
                                                                                                                                                                                                                                                                                                                  +1492//        final float mx0 = jitterLUT[h0] * 0.25f, my0 = jitterLUT[h0 + 1] * 0.25f, mz0 = jitterLUT[h0 + 2] * 0.25f,
                                                                                                                                                                                                                                                                                                                  +1493//                mx1 = jitterLUT[h1] * 0.25f, my1 = jitterLUT[h1 + 1] * 0.25f, mz1 = jitterLUT[h1 + 2] * 0.25f,
                                                                                                                                                                                                                                                                                                                  +1494//                mx2 = jitterLUT[h2] * 0.25f, my2 = jitterLUT[h2 + 1] * 0.25f, mz2 = jitterLUT[h2 + 2] * 0.25f,
                                                                                                                                                                                                                                                                                                                  +1495//                mx3 = jitterLUT[h3] * 0.25f, my3 = jitterLUT[h3 + 1] * 0.25f, mz3 = jitterLUT[h3 + 2] * 0.25f;
                                                                                                                                                                                                                                                                                                                  +1496//
                                                                                                                                                                                                                                                                                                                  +1497//        float t0 = 0.75f - x0 * x0 - y0 * y0 - z0 * z0;
                                                                                                                                                                                                                                                                                                                  +1498//        if (t0 < 0.0f)
                                                                                                                                                                                                                                                                                                                  +1499//            n0 = 0.0f;
                                                                                                                                                                                                                                                                                                                  +1500//        else {
                                                                                                                                                                                                                                                                                                                  +1501//            t0 *= t0;
                                                                                                                                                                                                                                                                                                                  +1502//            n0 = t0 * t0 * ((x0 + mx0) * gradient3DLUT[h0] + (y0 + my0) * gradient3DLUT[h0 + 1] + (z0 + mz0) * gradient3DLUT[h0 + 2]);
                                                                                                                                                                                                                                                                                                                  +1503//        }
                                                                                                                                                                                                                                                                                                                  +1504//
                                                                                                                                                                                                                                                                                                                  +1505//        float t1 = 0.75f - x1 * x1 - y1 * y1 - z1 * z1;
                                                                                                                                                                                                                                                                                                                  +1506//        if (t1 < 0.0f)
                                                                                                                                                                                                                                                                                                                  +1507//            n1 = 0.0f;
                                                                                                                                                                                                                                                                                                                  +1508//        else {
                                                                                                                                                                                                                                                                                                                  +1509//            t1 *= t1;
                                                                                                                                                                                                                                                                                                                  +1510//            n1 = t1 * t1 * ((x1 + mx1) * gradient3DLUT[h1] + (y1 + my1) * gradient3DLUT[h1 + 1] + (z1 + mz1) * gradient3DLUT[h1 + 2]);
                                                                                                                                                                                                                                                                                                                  +1511//        }
                                                                                                                                                                                                                                                                                                                  +1512//
                                                                                                                                                                                                                                                                                                                  +1513//        float t2 = 0.75f - x2 * x2 - y2 * y2 - z2 * z2;
                                                                                                                                                                                                                                                                                                                  +1514//        if (t2 < 0.0f)
                                                                                                                                                                                                                                                                                                                  +1515//            n2 = 0.0f;
                                                                                                                                                                                                                                                                                                                  +1516//        else {
                                                                                                                                                                                                                                                                                                                  +1517//            t2 *= t2;
                                                                                                                                                                                                                                                                                                                  +1518//            n2 = t2 * t2 * ((x2 + mx2) * gradient3DLUT[h2] + (y2 + my2) * gradient3DLUT[h2 + 1] + (z2 + mz2) * gradient3DLUT[h2 + 2]);
                                                                                                                                                                                                                                                                                                                  +1519//        }
                                                                                                                                                                                                                                                                                                                  +1520//
                                                                                                                                                                                                                                                                                                                  +1521//        float t3 = 0.75f - x3 * x3 - y3 * y3 - z3 * z3;
                                                                                                                                                                                                                                                                                                                  +1522//        if (t3 < 0.0f)
                                                                                                                                                                                                                                                                                                                  +1523//            n3 = 0.0f;
                                                                                                                                                                                                                                                                                                                  +1524//        else {
                                                                                                                                                                                                                                                                                                                  +1525//            t3 *= t3;
                                                                                                                                                                                                                                                                                                                  +1526//            n3 = t3 * t3 * ((x3 + mx3) * gradient3DLUT[h3] + (y3 + my3) * gradient3DLUT[h3 + 1] + (z3 + mz3) * gradient3DLUT[h3 + 2]);
                                                                                                                                                                                                                                                                                                                  +1527//        }
                                                                                                                                                                                                                                                                                                                  +1528//
                                                                                                                                                                                                                                                                                                                  +1529//        return NumberTools.bounce((18.0f * (n0 + n1 + n2 + n3)) + 10f);
                                                                                                                                                                                                                                                                                                                  +1530    }
                                                                                                                                                                                                                                                                                                                  +1531
                                                                                                                                                                                                                                                                                                                  +1532    public static double noise(final double x, final double y, final double z, final double w, final int seed) {
                                                                                                                                                                                                                                                                                                                  +1533        return noise((float)x, (float)y, (float)z, (float)w, seed);
                                                                                                                                                                                                                                                                                                                  +1534    }
                                                                                                                                                                                                                                                                                                                  +1535    public static double noise(final float x, final float y, final float z, final float w, final int seed) {
                                                                                                                                                                                                                                                                                                                  +1536        float n = 0.0f;
                                                                                                                                                                                                                                                                                                                  +1537        final float s = (x + y + z + w) * F4;
                                                                                                                                                                                                                                                                                                                  +1538        final int i = fastFloor(x + s), j = fastFloor(y + s), k = fastFloor(z + s), l = fastFloor(w + s);
                                                                                                                                                                                                                                                                                                                  +1539        final float[] gradient4DLUT = MeadNoise.gradient4DLUT;
                                                                                                                                                                                                                                                                                                                  +1540        final float t = (i + j + k + l) * G4,
                                                                                                                                                                                                                                                                                                                  +1541                X0 = i - t,
                                                                                                                                                                                                                                                                                                                  +1542                Y0 = j - t,
                                                                                                                                                                                                                                                                                                                  +1543                Z0 = k - t,
                                                                                                                                                                                                                                                                                                                  +1544                W0 = l - t,
                                                                                                                                                                                                                                                                                                                  +1545                x0 = x - X0,
                                                                                                                                                                                                                                                                                                                  +1546                y0 = y - Y0,
                                                                                                                                                                                                                                                                                                                  +1547                z0 = z - Z0,
                                                                                                                                                                                                                                                                                                                  +1548                w0 = w - W0;
                                                                                                                                                                                                                                                                                                                  +1549        final int c = (x0 > y0 ? 128 : 0) | (x0 > z0 ? 64 : 0) | (y0 > z0 ? 32 : 0) | (x0 > w0 ? 16 : 0) | (y0 > w0 ? 8 : 0) | (z0 > w0 ? 4 : 0);
                                                                                                                                                                                                                                                                                                                  +1550        final int i1 = SIMPLEX[c] >>> 2,
                                                                                                                                                                                                                                                                                                                  +1551                j1 = SIMPLEX[c | 1] >>> 2,
                                                                                                                                                                                                                                                                                                                  +1552                k1 = SIMPLEX[c | 2] >>> 2,
                                                                                                                                                                                                                                                                                                                  +1553                l1 = SIMPLEX[c | 3] >>> 2,
                                                                                                                                                                                                                                                                                                                  +1554                i2 = SIMPLEX[c] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  +1555                j2 = SIMPLEX[c | 1] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  +1556                k2 = SIMPLEX[c | 2] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  +1557                l2 = SIMPLEX[c | 3] >>> 1 & 1,
                                                                                                                                                                                                                                                                                                                  +1558                i3 = SIMPLEX[c] & 1,
                                                                                                                                                                                                                                                                                                                  +1559                j3 = SIMPLEX[c | 1] & 1,
                                                                                                                                                                                                                                                                                                                  +1560                k3 = SIMPLEX[c | 2] & 1,
                                                                                                                                                                                                                                                                                                                  +1561                l3 = SIMPLEX[c | 3] & 1;
                                                                                                                                                                                                                                                                                                                  +1562        final float x1 = x0 - i1 + G4,
                                                                                                                                                                                                                                                                                                                  +1563                y1 = y0 - j1 + G4,
                                                                                                                                                                                                                                                                                                                  +1564                z1 = z0 - k1 + G4,
                                                                                                                                                                                                                                                                                                                  +1565                w1 = w0 - l1 + G4,
                                                                                                                                                                                                                                                                                                                  +1566                x2 = x0 - i2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  +1567                y2 = y0 - j2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  +1568                z2 = z0 - k2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  +1569                w2 = w0 - l2 + 2f * G4,
                                                                                                                                                                                                                                                                                                                  +1570                x3 = x0 - i3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  +1571                y3 = y0 - j3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  +1572                z3 = z0 - k3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  +1573                w3 = w0 - l3 + 3f * G4,
                                                                                                                                                                                                                                                                                                                  +1574                x4 = x0 - 1f + 4f * G4,
                                                                                                                                                                                                                                                                                                                  +1575                y4 = y0 - 1f + 4f * G4,
                                                                                                                                                                                                                                                                                                                  +1576                z4 = z0 - 1f + 4f * G4,
                                                                                                                                                                                                                                                                                                                  +1577                w4 = w0 - 1f + 4f * G4;
                                                                                                                                                                                                                                                                                                                  +1578        final int h0 = hash(i, j, k, l, seed) << 2,
                                                                                                                                                                                                                                                                                                                  +1579                h1 = hash(i + i1, j + j1, k + k1, l + l1, seed) << 2,
                                                                                                                                                                                                                                                                                                                  +1580                h2 = hash(i + i2, j + j2, k + k2, l + l2, seed) << 2,
                                                                                                                                                                                                                                                                                                                  +1581                h3 = hash(i + i3, j + j3, k + k3, l + l3, seed) << 2,
                                                                                                                                                                                                                                                                                                                  +1582                h4 = hash(i + 1, j + 1, k + 1, l + 1, seed) << 2;
                                                                                                                                                                                                                                                                                                                  +1583        float t0 = LIMIT4 - x0 * x0 - y0 * y0 - z0 * z0 - w0 * w0;
                                                                                                                                                                                                                                                                                                                  +1584        if(t0 > 0) {
                                                                                                                                                                                                                                                                                                                  +1585            t0 *= t0;
                                                                                                                                                                                                                                                                                                                  +1586            n += t0 * t0 * (x0 * gradient4DLUT[h0] + y0 * gradient4DLUT[h0 | 1] + z0 * gradient4DLUT[h0 | 2] + w0 * gradient4DLUT[h0 | 3]);
                                                                                                                                                                                                                                                                                                                  +1587        }
                                                                                                                                                                                                                                                                                                                  +1588        float t1 = LIMIT4 - x1 * x1 - y1 * y1 - z1 * z1 - w1 * w1;
                                                                                                                                                                                                                                                                                                                  +1589        if (t1 > 0) {
                                                                                                                                                                                                                                                                                                                  +1590            t1 *= t1;
                                                                                                                                                                                                                                                                                                                  +1591            n += t1 * t1 * (x1 * gradient4DLUT[h1] + y1 * gradient4DLUT[h1 | 1] + z1 * gradient4DLUT[h1 | 2] + w1 * gradient4DLUT[h1 | 3]);
                                                                                                                                                                                                                                                                                                                  +1592        }
                                                                                                                                                                                                                                                                                                                  +1593        float t2 = LIMIT4 - x2 * x2 - y2 * y2 - z2 * z2 - w2 * w2;
                                                                                                                                                                                                                                                                                                                  +1594        if (t2 > 0) {
                                                                                                                                                                                                                                                                                                                  +1595            t2 *= t2;
                                                                                                                                                                                                                                                                                                                  +1596            n += t2 * t2 * (x2 * gradient4DLUT[h2] + y2 * gradient4DLUT[h2 | 1] + z2 * gradient4DLUT[h2 | 2] + w2 * gradient4DLUT[h2 | 3]);
                                                                                                                                                                                                                                                                                                                  +1597        }
                                                                                                                                                                                                                                                                                                                  +1598        float t3 = LIMIT4 - x3 * x3 - y3 * y3 - z3 * z3 - w3 * w3;
                                                                                                                                                                                                                                                                                                                  +1599        if (t3 > 0) {
                                                                                                                                                                                                                                                                                                                  +1600            t3 *= t3;
                                                                                                                                                                                                                                                                                                                  +1601            n += t3 * t3 * (x3 * gradient4DLUT[h3] + y3 * gradient4DLUT[h3 | 1] + z3 * gradient4DLUT[h3 | 2] + w3 * gradient4DLUT[h3 | 3]);
                                                                                                                                                                                                                                                                                                                  +1602        }
                                                                                                                                                                                                                                                                                                                  +1603        float t4 = LIMIT4 - x4 * x4 - y4 * y4 - z4 * z4 - w4 * w4;
                                                                                                                                                                                                                                                                                                                  +1604        if (t4 > 0) {
                                                                                                                                                                                                                                                                                                                  +1605            t4 *= t4;
                                                                                                                                                                                                                                                                                                                  +1606            n += t4 * t4 * (x4 * gradient4DLUT[h4] + y4 * gradient4DLUT[h4 | 1] + z4 * gradient4DLUT[h4 | 2] + w4 * gradient4DLUT[h4 | 3]);
                                                                                                                                                                                                                                                                                                                  +1607        }
                                                                                                                                                                                                                                                                                                                  +1608        return NumberTools.bounce(5.0 + 41.0 * n);
                                                                                                                                                                                                                                                                                                                  +1609    }
                                                                                                                                                                                                                                                                                                                  +1610
                                                                                                                                                                                                                                                                                                                  +1611
                                                                                                                                                                                                                                                                                                                  +1612    public static double noise(final double x, final double y, final double z,
                                                                                                                                                                                                                                                                                                                  +1613                               final double w, final double u, final double v, final int seed) {
                                                                                                                                                                                                                                                                                                                  +1614        return noise((float)x, (float)y, (float)z, (float)w, (float)u, (float)v, seed);
                                                                                                                                                                                                                                                                                                                  +1615    }
                                                                                                                                                                                                                                                                                                                   1616
                                                                                                                                                                                                                                                                                                                  -1617        for (int c = -1; c < 6; c++) {
                                                                                                                                                                                                                                                                                                                  -1618            if (c != -1) intLoc[distOrder[c]]++;
                                                                                                                                                                                                                                                                                                                  -1619
                                                                                                                                                                                                                                                                                                                  -1620            m[0] = cellDist[0] - (intLoc[0] - skewX) + skewOffset;
                                                                                                                                                                                                                                                                                                                  -1621            m[1] = cellDist[1] - (intLoc[1] - skewY) + skewOffset;
                                                                                                                                                                                                                                                                                                                  -1622            m[2] = cellDist[2] - (intLoc[2] - skewZ) + skewOffset;
                                                                                                                                                                                                                                                                                                                  -1623            m[3] = cellDist[3] - (intLoc[3] - skewW) + skewOffset;
                                                                                                                                                                                                                                                                                                                  -1624            m[4] = cellDist[4] - (intLoc[4] - skewU) + skewOffset;
                                                                                                                                                                                                                                                                                                                  -1625            m[5] = cellDist[5] - (intLoc[5] - skewV) + skewOffset;
                                                                                                                                                                                                                                                                                                                  -1626
                                                                                                                                                                                                                                                                                                                  -1627            float tc = LIMIT6;
                                                                                                                                                                                                                                                                                                                  -1628
                                                                                                                                                                                                                                                                                                                  -1629            for (int d = 0; d < 6; d++) {
                                                                                                                                                                                                                                                                                                                  -1630                tc -= m[d] * m[d];
                                                                                                                                                                                                                                                                                                                  -1631            }
                                                                                                                                                                                                                                                                                                                  -1632
                                                                                                                                                                                                                                                                                                                  -1633            if (tc > 0f) {
                                                                                                                                                                                                                                                                                                                  -1634                final int h = hash(intLoc[0], intLoc[1], intLoc[2], intLoc[3],
                                                                                                                                                                                                                                                                                                                  -1635                        intLoc[4], intLoc[5], seed) * 6;
                                                                                                                                                                                                                                                                                                                  -1636                float gr = 0f;
                                                                                                                                                                                                                                                                                                                  -1637                for (int d = 0; d < 6; d++) {
                                                                                                                                                                                                                                                                                                                  -1638                    gr += gradient6DLUT[h + d] * m[d];
                                                                                                                                                                                                                                                                                                                  -1639                }
                                                                                                                                                                                                                                                                                                                  -1640
                                                                                                                                                                                                                                                                                                                  -1641                n += gr * tc * tc * tc * tc;
                                                                                                                                                                                                                                                                                                                  -1642            }
                                                                                                                                                                                                                                                                                                                  -1643            skewOffset += G6;
                                                                                                                                                                                                                                                                                                                  -1644        }
                                                                                                                                                                                                                                                                                                                  -1645        //return NumberTools.bounce(5.0 + 13.5 * n);
                                                                                                                                                                                                                                                                                                                  -1646        return NumberTools.bounce(10.0 + 16.25 * n);
                                                                                                                                                                                                                                                                                                                  -1647    }
                                                                                                                                                                                                                                                                                                                  -1648
                                                                                                                                                                                                                                                                                                                  -1649}
                                                                                                                                                                                                                                                                                                                  +1617    public static double noise(final float x, final float y, final float z, final float w, final float u, final float v, final int seed) {
                                                                                                                                                                                                                                                                                                                  +1618
                                                                                                                                                                                                                                                                                                                  +1619        final float s = (x + y + z + w + u + v) * F6;
                                                                                                                                                                                                                                                                                                                  +1620
                                                                                                                                                                                                                                                                                                                  +1621        final int skewX = fastFloor(x + s), skewY = fastFloor(y + s), skewZ = fastFloor(z + s),
                                                                                                                                                                                                                                                                                                                  +1622                skewW = fastFloor(w + s), skewU = fastFloor(u + s), skewV = fastFloor(v + s);
                                                                                                                                                                                                                                                                                                                  +1623        final int[] intLoc = MeadNoise.intLoc, distOrder = MeadNoise.distOrder;
                                                                                                                                                                                                                                                                                                                  +1624        intLoc[0] = skewX;
                                                                                                                                                                                                                                                                                                                  +1625        intLoc[1] = skewY;
                                                                                                                                                                                                                                                                                                                  +1626        intLoc[2] = skewZ;
                                                                                                                                                                                                                                                                                                                  +1627        intLoc[3] = skewW;
                                                                                                                                                                                                                                                                                                                  +1628        intLoc[4] = skewU;
                                                                                                                                                                                                                                                                                                                  +1629        intLoc[5] = skewV;
                                                                                                                                                                                                                                                                                                                  +1630
                                                                                                                                                                                                                                                                                                                  +1631        final float unskew = (skewX + skewY + skewZ + skewW + skewU + skewV) * G6;
                                                                                                                                                                                                                                                                                                                  +1632        final float[] cellDist = MeadNoise.cellDist, gradient6DLUT = MeadNoise.gradient6DLUT;
                                                                                                                                                                                                                                                                                                                  +1633        cellDist[0] = x - skewX + unskew;
                                                                                                                                                                                                                                                                                                                  +1634        cellDist[1] = y - skewY + unskew;
                                                                                                                                                                                                                                                                                                                  +1635        cellDist[2] = z - skewZ + unskew;
                                                                                                                                                                                                                                                                                                                  +1636        cellDist[3] = w - skewW + unskew;
                                                                                                                                                                                                                                                                                                                  +1637        cellDist[4] = u - skewU + unskew;
                                                                                                                                                                                                                                                                                                                  +1638        cellDist[5] = v - skewV + unskew;
                                                                                                                                                                                                                                                                                                                  +1639
                                                                                                                                                                                                                                                                                                                  +1640        int o0 = (cellDist[0]<cellDist[1]?1:0)+(cellDist[0]<cellDist[2]?1:0)+(cellDist[0]<cellDist[3]?1:0)+(cellDist[0]<cellDist[4]?1:0)+(cellDist[0]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  +1641        int o1 = (cellDist[1]<=cellDist[0]?1:0)+(cellDist[1]<cellDist[2]?1:0)+(cellDist[1]<cellDist[3]?1:0)+(cellDist[1]<cellDist[4]?1:0)+(cellDist[1]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  +1642        int o2 = (cellDist[2]<=cellDist[0]?1:0)+(cellDist[2]<=cellDist[1]?1:0)+(cellDist[2]<cellDist[3]?1:0)+(cellDist[2]<cellDist[4]?1:0)+(cellDist[2]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  +1643        int o3 = (cellDist[3]<=cellDist[0]?1:0)+(cellDist[3]<=cellDist[1]?1:0)+(cellDist[3]<=cellDist[2]?1:0)+(cellDist[3]<cellDist[4]?1:0)+(cellDist[3]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  +1644        int o4 = (cellDist[4]<=cellDist[0]?1:0)+(cellDist[4]<=cellDist[1]?1:0)+(cellDist[4]<=cellDist[2]?1:0)+(cellDist[4]<=cellDist[3]?1:0)+(cellDist[4]<cellDist[5]?1:0);
                                                                                                                                                                                                                                                                                                                  +1645        int o5 = 15-(o0+o1+o2+o3+o4);
                                                                                                                                                                                                                                                                                                                  +1646
                                                                                                                                                                                                                                                                                                                  +1647        distOrder[o0]=0;
                                                                                                                                                                                                                                                                                                                  +1648        distOrder[o1]=1;
                                                                                                                                                                                                                                                                                                                  +1649        distOrder[o2]=2;
                                                                                                                                                                                                                                                                                                                  +1650        distOrder[o3]=3;
                                                                                                                                                                                                                                                                                                                  +1651        distOrder[o4]=4;
                                                                                                                                                                                                                                                                                                                  +1652        distOrder[o5]=5;
                                                                                                                                                                                                                                                                                                                  +1653
                                                                                                                                                                                                                                                                                                                  +1654        float n = 0f;
                                                                                                                                                                                                                                                                                                                  +1655        float skewOffset = 0f;
                                                                                                                                                                                                                                                                                                                  +1656
                                                                                                                                                                                                                                                                                                                  +1657        for (int c = -1; c < 6; c++) {
                                                                                                                                                                                                                                                                                                                  +1658            if (c != -1) intLoc[distOrder[c]]++;
                                                                                                                                                                                                                                                                                                                  +1659
                                                                                                                                                                                                                                                                                                                  +1660            m[0] = cellDist[0] - (intLoc[0] - skewX) + skewOffset;
                                                                                                                                                                                                                                                                                                                  +1661            m[1] = cellDist[1] - (intLoc[1] - skewY) + skewOffset;
                                                                                                                                                                                                                                                                                                                  +1662            m[2] = cellDist[2] - (intLoc[2] - skewZ) + skewOffset;
                                                                                                                                                                                                                                                                                                                  +1663            m[3] = cellDist[3] - (intLoc[3] - skewW) + skewOffset;
                                                                                                                                                                                                                                                                                                                  +1664            m[4] = cellDist[4] - (intLoc[4] - skewU) + skewOffset;
                                                                                                                                                                                                                                                                                                                  +1665            m[5] = cellDist[5] - (intLoc[5] - skewV) + skewOffset;
                                                                                                                                                                                                                                                                                                                  +1666
                                                                                                                                                                                                                                                                                                                  +1667            float tc = LIMIT6;
                                                                                                                                                                                                                                                                                                                  +1668
                                                                                                                                                                                                                                                                                                                  +1669            for (int d = 0; d < 6; d++) {
                                                                                                                                                                                                                                                                                                                  +1670                tc -= m[d] * m[d];
                                                                                                                                                                                                                                                                                                                  +1671            }
                                                                                                                                                                                                                                                                                                                  +1672
                                                                                                                                                                                                                                                                                                                  +1673            if (tc > 0f) {
                                                                                                                                                                                                                                                                                                                  +1674                final int h = hash(intLoc[0], intLoc[1], intLoc[2], intLoc[3],
                                                                                                                                                                                                                                                                                                                  +1675                        intLoc[4], intLoc[5], seed) * 6;
                                                                                                                                                                                                                                                                                                                  +1676                float gr = 0f;
                                                                                                                                                                                                                                                                                                                  +1677                for (int d = 0; d < 6; d++) {
                                                                                                                                                                                                                                                                                                                  +1678                    gr += gradient6DLUT[h + d] * m[d];
                                                                                                                                                                                                                                                                                                                  +1679                }
                                                                                                                                                                                                                                                                                                                  +1680
                                                                                                                                                                                                                                                                                                                  +1681                n += gr * tc * tc * tc * tc;
                                                                                                                                                                                                                                                                                                                  +1682            }
                                                                                                                                                                                                                                                                                                                  +1683            skewOffset += G6;
                                                                                                                                                                                                                                                                                                                  +1684        }
                                                                                                                                                                                                                                                                                                                  +1685        //return NumberTools.bounce(5.0 + 13.5 * n);
                                                                                                                                                                                                                                                                                                                  +1686        return NumberTools.bounce(10.0 + 16.25 * n);
                                                                                                                                                                                                                                                                                                                  +1687    }
                                                                                                                                                                                                                                                                                                                  +1688
                                                                                                                                                                                                                                                                                                                  +1689}
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/RNG.CustomRandom.html b/docs/squidlib-util/src-html/squidpony/squidmath/RNG.CustomRandom.html
                                                                                                                                                                                                                                                                                                                  index 41bcbe3455..3e2b7daded 100644
                                                                                                                                                                                                                                                                                                                  --- a/docs/squidlib-util/src-html/squidpony/squidmath/RNG.CustomRandom.html
                                                                                                                                                                                                                                                                                                                  +++ b/docs/squidlib-util/src-html/squidpony/squidmath/RNG.CustomRandom.html
                                                                                                                                                                                                                                                                                                                  @@ -9,1089 +9,1091 @@
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  001package squidpony.squidmath;
                                                                                                                                                                                                                                                                                                                   002
                                                                                                                                                                                                                                                                                                                   003import squidpony.ArrayTools;
                                                                                                                                                                                                                                                                                                                  -004import squidpony.annotation.GwtIncompatible;
                                                                                                                                                                                                                                                                                                                  -005
                                                                                                                                                                                                                                                                                                                  -006import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  -007import java.util.*;
                                                                                                                                                                                                                                                                                                                  -008
                                                                                                                                                                                                                                                                                                                  -009/**
                                                                                                                                                                                                                                                                                                                  -010 * A wrapper class for working with random number generators in a more friendly way.
                                                                                                                                                                                                                                                                                                                  -011 * <p>
                                                                                                                                                                                                                                                                                                                  -012 * Includes methods for getting values between two numbers and for getting
                                                                                                                                                                                                                                                                                                                  -013 * random elements from a collection or array. There are methods to shuffle
                                                                                                                                                                                                                                                                                                                  -014 * a collection and to get a random ordering that can be applied as one shuffle
                                                                                                                                                                                                                                                                                                                  -015 * across multiple collections, such as via {@link OrderedMap#reorder(int...)},
                                                                                                                                                                                                                                                                                                                  -016 * {@link ArrayTools#reorder(ArrayList, int...)}, and so on. You can construct
                                                                                                                                                                                                                                                                                                                  -017 * an RNG with all sorts of RandomnessSource implementations, and choosing them
                                                                                                                                                                                                                                                                                                                  -018 * is usually not a big concern because the default works very well.
                                                                                                                                                                                                                                                                                                                  -019 * <br>
                                                                                                                                                                                                                                                                                                                  -020 * But if you do want advice on what RandomnessSource to use... {@link LightRNG}
                                                                                                                                                                                                                                                                                                                  -021 * is the default, and is very fast, but relative to many of the others it has a
                                                                                                                                                                                                                                                                                                                  -022 * significantly shorter period (the amount of random  numbers it will go through
                                                                                                                                                                                                                                                                                                                  -023 * before repeating the sequence), at {@code pow(2, 64)} as opposed to
                                                                                                                                                                                                                                                                                                                  -024 * {@link XoRoRNG}'s {@code pow(2, 128) - 1}, . {@link LapRNG} is about twice as
                                                                                                                                                                                                                                                                                                                  -025 * fast as LightRNG, but that's all it's good at; it fails quality tests almost
                                                                                                                                                                                                                                                                                                                  -026 * all around, though it can fool a human observer, and has a period that's only
                                                                                                                                                                                                                                                                                                                  -027 * barely better than LightRNG at {@code pow(2, 65)}. LightRNG also allows the
                                                                                                                                                                                                                                                                                                                  -028 * current RNG state to be retrieved and altered with {@code getState()} and
                                                                                                                                                                                                                                                                                                                  -029 * {@code setState()}, and the subclass of RNG, {@link StatefulRNG}, usually uses
                                                                                                                                                                                                                                                                                                                  -030 * LightRNG to handle random number generation when the state may need to be
                                                                                                                                                                                                                                                                                                                  -031 * saved and reloaded. For most cases, you should decide between LightRNG, XoRoRNG,
                                                                                                                                                                                                                                                                                                                  -032 * and LapRNG based on your priorities. LightRNG is the best if you want good
                                                                                                                                                                                                                                                                                                                  -033 * speed, good quality of randomness, and expect to either generate less than
                                                                                                                                                                                                                                                                                                                  -034 * 18446744073709551616 numbers or don't care if patterns appear after you generate
                                                                                                                                                                                                                                                                                                                  -035 * that many numbers, or if you need an RNG that can skip backwards or jump forwards
                                                                                                                                                                                                                                                                                                                  -036 * without incurring speed penalties. XoRoRNG is best if you want good speed and
                                                                                                                                                                                                                                                                                                                  -037 * quality but need to generate more than 18446744073709551616 numbers, though less
                                                                                                                                                                                                                                                                                                                  -038 * than 340282366920938463463374607431768211456 numbers. LapRNG is best if you only
                                                                                                                                                                                                                                                                                                                  -039 * care about getting random numbers quickly, and don't expect their quality to be
                                                                                                                                                                                                                                                                                                                  -040 * scrutinized; it can generate 36893488147419103232 numbers before the entire cycle
                                                                                                                                                                                                                                                                                                                  -041 * repeats, but patterns can easily appear before that.
                                                                                                                                                                                                                                                                                                                  -042 * <br>
                                                                                                                                                                                                                                                                                                                  -043 * There are many more RandomnessSource implementations! If XoRoRNG's tremendous
                                                                                                                                                                                                                                                                                                                  -044 * period is not enough, then we also supply {@link LongPeriodRNG}, which has a
                                                                                                                                                                                                                                                                                                                  -045 * period of {@code pow(2, 1024) - 1}, and {@link BeardRNG}, which has an unknown
                                                                                                                                                                                                                                                                                                                  -046 * exact period but is likely to be very large, since it has 4 times as much state
                                                                                                                                                                                                                                                                                                                  -047 * as LongPeriodRNG and so could have at most a period of {@code pow(2, 4096)}.
                                                                                                                                                                                                                                                                                                                  -048 * You might want significantly less predictable random results, which
                                                                                                                                                                                                                                                                                                                  -049 * {@link IsaacRNG} can provide, along with a large period. The quality of
                                                                                                                                                                                                                                                                                                                  -050 * {@link PermutedRNG} is also good, usually, and it has a sound basis in PCG-Random,
                                                                                                                                                                                                                                                                                                                  -051 * an involved library with many variants on its RNGs. There may be reasons why
                                                                                                                                                                                                                                                                                                                  -052 * you would want a random number generator that uses 32-bit math instead of the
                                                                                                                                                                                                                                                                                                                  -053 * more common 64-bit math, but using a 32-bit int on desktop and Android won't act
                                                                                                                                                                                                                                                                                                                  -054 * the same as that same 32-bit int on GWT. Since GWT is stuck with JavaScript's
                                                                                                                                                                                                                                                                                                                  -055 * annoying implementation of ints with doubles, overflow (which is needed for an
                                                                                                                                                                                                                                                                                                                  -056 * RNG) doesn't work at all with ints, but does with GWT's implementation of longs.
                                                                                                                                                                                                                                                                                                                  -057 * 32-bit math generators were a major part of SquidLib's development at one point
                                                                                                                                                                                                                                                                                                                  -058 * before the discrepancies between desktop and GWT were discovered; they include
                                                                                                                                                                                                                                                                                                                  -059 * {@link Light32RNG} (same algorithm as LightRNG, shrunk down to use ints),
                                                                                                                                                                                                                                                                                                                  -060 * {@link BardRNG} (a huge-period RNG like BeardRNG), {@link Isaac32RNG} (32-bit
                                                                                                                                                                                                                                                                                                                  -061 * variant on IsaacRNG), {@link PintRNG} (based on PermutedRNG, using PCG-Random),
                                                                                                                                                                                                                                                                                                                  -062 * and {@link FlapRNG} (like Lap, only good for speed). Now, any code that targets
                                                                                                                                                                                                                                                                                                                  -063 * non-GWT platforms is free to use them, though they are often slower when they
                                                                                                                                                                                                                                                                                                                  -064 * need to generate longs (which is often), but they should not be used in code
                                                                                                                                                                                                                                                                                                                  -065 * that targets GWT.
                                                                                                                                                                                                                                                                                                                  -066 * @author Eben Howard - http://squidpony.com - howard@squidpony.com
                                                                                                                                                                                                                                                                                                                  -067 * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  -068 * @author smelC
                                                                                                                                                                                                                                                                                                                  -069 */
                                                                                                                                                                                                                                                                                                                  -070public class RNG implements Serializable {
                                                                                                                                                                                                                                                                                                                  -071
                                                                                                                                                                                                                                                                                                                  -072    /**
                                                                                                                                                                                                                                                                                                                  -073     * A very small multiplier used to reduce random numbers to from the {@code [0.0,9007199254740991.0)} range to the
                                                                                                                                                                                                                                                                                                                  -074     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0 / (1 << 53)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  -075     * source uses the hexadecimal double literal {@code 0x1p-53}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  -076     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  -077     */
                                                                                                                                                                                                                                                                                                                  -078        protected static final double DOUBLE_UNIT = 0x1p-53; // more people should know about hex double literals!
                                                                                                                                                                                                                                                                                                                  -079    /**
                                                                                                                                                                                                                                                                                                                  -080     * A very small multiplier used to reduce random numbers to from the {@code [0.0,16777216.0)} range to the
                                                                                                                                                                                                                                                                                                                  -081     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0f / (1 << 24)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  -082     * source uses the hexadecimal double literal {@code 0x1p-24f}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  -083     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  -084     */
                                                                                                                                                                                                                                                                                                                  -085        protected static final float FLOAT_UNIT = 0x1p-24f;
                                                                                                                                                                                                                                                                                                                  -086        protected RandomnessSource random;
                                                                                                                                                                                                                                                                                                                  -087        protected double nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  -088        protected boolean haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  -089        protected Random ran = null;
                                                                                                                                                                                                                                                                                                                  -090
                                                                                                                                                                                                                                                                                                                  -091    private static final long serialVersionUID = 2352426757973945149L;
                                                                                                                                                                                                                                                                                                                  +004
                                                                                                                                                                                                                                                                                                                  +005import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  +006import java.util.*;
                                                                                                                                                                                                                                                                                                                  +007
                                                                                                                                                                                                                                                                                                                  +008/**
                                                                                                                                                                                                                                                                                                                  +009 * A wrapper class for working with random number generators in a more friendly way.
                                                                                                                                                                                                                                                                                                                  +010 * <p>
                                                                                                                                                                                                                                                                                                                  +011 * Includes methods for getting values between two numbers and for getting
                                                                                                                                                                                                                                                                                                                  +012 * random elements from a collection or array. There are methods to shuffle
                                                                                                                                                                                                                                                                                                                  +013 * a collection and to get a random ordering that can be applied as one shuffle
                                                                                                                                                                                                                                                                                                                  +014 * across multiple collections, such as via {@link OrderedMap#reorder(int...)},
                                                                                                                                                                                                                                                                                                                  +015 * {@link ArrayTools#reorder(ArrayList, int...)}, and so on. You can construct
                                                                                                                                                                                                                                                                                                                  +016 * an RNG with all sorts of RandomnessSource implementations, and choosing them
                                                                                                                                                                                                                                                                                                                  +017 * is usually not a big concern because the default works very well.
                                                                                                                                                                                                                                                                                                                  +018 * <br>
                                                                                                                                                                                                                                                                                                                  +019 * But if you do want advice on what RandomnessSource to use... {@link LightRNG}
                                                                                                                                                                                                                                                                                                                  +020 * is the default, and is very fast, but relative to many of the others it has a
                                                                                                                                                                                                                                                                                                                  +021 * significantly shorter period (the amount of random  numbers it will go through
                                                                                                                                                                                                                                                                                                                  +022 * before repeating the sequence), at {@code pow(2, 64)} as opposed to
                                                                                                                                                                                                                                                                                                                  +023 * {@link XoRoRNG}'s {@code pow(2, 128) - 1}, . {@link LapRNG} is about twice as
                                                                                                                                                                                                                                                                                                                  +024 * fast as LightRNG, but that's all it's good at; it fails quality tests almost
                                                                                                                                                                                                                                                                                                                  +025 * all around, though it can fool a human observer, and has a period that's only
                                                                                                                                                                                                                                                                                                                  +026 * barely better than LightRNG at {@code pow(2, 65)}. LightRNG also allows the
                                                                                                                                                                                                                                                                                                                  +027 * current RNG state to be retrieved and altered with {@code getState()} and
                                                                                                                                                                                                                                                                                                                  +028 * {@code setState()}, and the subclass of RNG, {@link StatefulRNG}, usually uses
                                                                                                                                                                                                                                                                                                                  +029 * LightRNG to handle random number generation when the state may need to be
                                                                                                                                                                                                                                                                                                                  +030 * saved and reloaded. For most cases, you should decide between LightRNG, XoRoRNG,
                                                                                                                                                                                                                                                                                                                  +031 * and LapRNG based on your priorities. LightRNG is the best if you want good
                                                                                                                                                                                                                                                                                                                  +032 * speed, good quality of randomness, and expect to either generate less than
                                                                                                                                                                                                                                                                                                                  +033 * 18446744073709551616 numbers or don't care if patterns appear after you generate
                                                                                                                                                                                                                                                                                                                  +034 * that many numbers, or if you need an RNG that can skip backwards or jump forwards
                                                                                                                                                                                                                                                                                                                  +035 * without incurring speed penalties. XoRoRNG is best if you want good speed and
                                                                                                                                                                                                                                                                                                                  +036 * quality but need to generate more than 18446744073709551616 numbers, though less
                                                                                                                                                                                                                                                                                                                  +037 * than 340282366920938463463374607431768211456 numbers. LapRNG is best if you only
                                                                                                                                                                                                                                                                                                                  +038 * care about getting random numbers quickly, and don't expect their quality to be
                                                                                                                                                                                                                                                                                                                  +039 * scrutinized; it can generate 36893488147419103232 numbers before the entire cycle
                                                                                                                                                                                                                                                                                                                  +040 * repeats, but patterns can easily appear before that.
                                                                                                                                                                                                                                                                                                                  +041 * <br>
                                                                                                                                                                                                                                                                                                                  +042 * There are many more RandomnessSource implementations! If XoRoRNG's tremendous
                                                                                                                                                                                                                                                                                                                  +043 * period is not enough, then we also supply {@link LongPeriodRNG}, which has a
                                                                                                                                                                                                                                                                                                                  +044 * period of {@code pow(2, 1024) - 1}, and {@link BeardRNG}, which has an unknown
                                                                                                                                                                                                                                                                                                                  +045 * exact period but is likely to be very large, since it has 4 times as much state
                                                                                                                                                                                                                                                                                                                  +046 * as LongPeriodRNG and so could have at most a period of {@code pow(2, 4096)}.
                                                                                                                                                                                                                                                                                                                  +047 * You might want significantly less predictable random results, which
                                                                                                                                                                                                                                                                                                                  +048 * {@link IsaacRNG} can provide, along with a large period. The quality of
                                                                                                                                                                                                                                                                                                                  +049 * {@link PermutedRNG} is also good, usually, and it has a sound basis in PCG-Random,
                                                                                                                                                                                                                                                                                                                  +050 * an involved library with many variants on its RNGs. There may be reasons why
                                                                                                                                                                                                                                                                                                                  +051 * you would want a random number generator that uses 32-bit math instead of the
                                                                                                                                                                                                                                                                                                                  +052 * more common 64-bit math, but using a 32-bit int on desktop and Android won't act
                                                                                                                                                                                                                                                                                                                  +053 * the same as that same 32-bit int on GWT. Since GWT is stuck with JavaScript's
                                                                                                                                                                                                                                                                                                                  +054 * annoying implementation of ints with doubles, overflow (which is needed for an
                                                                                                                                                                                                                                                                                                                  +055 * RNG) doesn't work at all with ints, but does with GWT's implementation of longs.
                                                                                                                                                                                                                                                                                                                  +056 * 32-bit math generators were a major part of SquidLib's development at one point
                                                                                                                                                                                                                                                                                                                  +057 * before the discrepancies between desktop and GWT were discovered; they include
                                                                                                                                                                                                                                                                                                                  +058 * {@link Light32RNG} (same algorithm as LightRNG, shrunk down to use ints),
                                                                                                                                                                                                                                                                                                                  +059 * {@link BardRNG} (a huge-period RNG like BeardRNG), {@link Isaac32RNG} (32-bit
                                                                                                                                                                                                                                                                                                                  +060 * variant on IsaacRNG), {@link PintRNG} (based on PermutedRNG, using PCG-Random),
                                                                                                                                                                                                                                                                                                                  +061 * and {@link FlapRNG} (like Lap, only good for speed). Now, any code that targets
                                                                                                                                                                                                                                                                                                                  +062 * non-GWT platforms is free to use them, though they are often slower when they
                                                                                                                                                                                                                                                                                                                  +063 * need to generate longs (which is often), but they should not be used in code
                                                                                                                                                                                                                                                                                                                  +064 * that targets GWT.
                                                                                                                                                                                                                                                                                                                  +065 * @author Eben Howard - http://squidpony.com - howard@squidpony.com
                                                                                                                                                                                                                                                                                                                  +066 * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  +067 * @author smelC
                                                                                                                                                                                                                                                                                                                  +068 */
                                                                                                                                                                                                                                                                                                                  +069public class RNG implements Serializable {
                                                                                                                                                                                                                                                                                                                  +070
                                                                                                                                                                                                                                                                                                                  +071    /**
                                                                                                                                                                                                                                                                                                                  +072     * A very small multiplier used to reduce random numbers to from the {@code [0.0,9007199254740991.0)} range to the
                                                                                                                                                                                                                                                                                                                  +073     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0 / (1 << 53)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  +074     * source uses the hexadecimal double literal {@code 0x1p-53}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  +075     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  +076     */
                                                                                                                                                                                                                                                                                                                  +077        protected static final double DOUBLE_UNIT = 0x1p-53; // more people should know about hex double literals!
                                                                                                                                                                                                                                                                                                                  +078    /**
                                                                                                                                                                                                                                                                                                                  +079     * A very small multiplier used to reduce random numbers to from the {@code [0.0,16777216.0)} range to the
                                                                                                                                                                                                                                                                                                                  +080     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0f / (1 << 24)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  +081     * source uses the hexadecimal double literal {@code 0x1p-24f}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  +082     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  +083     */
                                                                                                                                                                                                                                                                                                                  +084        protected static final float FLOAT_UNIT = 0x1p-24f;
                                                                                                                                                                                                                                                                                                                  +085        protected RandomnessSource random;
                                                                                                                                                                                                                                                                                                                  +086        protected double nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  +087        protected boolean haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  +088        protected Random ran = null;
                                                                                                                                                                                                                                                                                                                  +089
                                                                                                                                                                                                                                                                                                                  +090    private static final long serialVersionUID = 2352426757973945149L;
                                                                                                                                                                                                                                                                                                                  +091
                                                                                                                                                                                                                                                                                                                   092
                                                                                                                                                                                                                                                                                                                  -093
                                                                                                                                                                                                                                                                                                                  -094    /**
                                                                                                                                                                                                                                                                                                                  -095     * Default constructor; uses SplitMix64, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  -096     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -097     * <br>
                                                                                                                                                                                                                                                                                                                  -098     * Compatibility note: previous versions of SquidLib used Mersenne Twister by default. Due to the incompatibility
                                                                                                                                                                                                                                                                                                                  -099     * of the threads used by this Mersenne Twister implementation with GWT and HTML5 applications, the randomness
                                                                                                                                                                                                                                                                                                                  -100     * algorithm has been changed to a faster, more compatible algorithm, though it does suffer from a much lower
                                                                                                                                                                                                                                                                                                                  -101     * period. If you need drastically larger periods than 2^64, you can pass a LongPeriodRNG (or MersenneTwister on
                                                                                                                                                                                                                                                                                                                  -102     * targets other than HTML) object to the constructor that takes a RandomnessSource. If you don't know what the
                                                                                                                                                                                                                                                                                                                  -103     * period of a PRNG is, you probably don't need to worry about it; it's mainly relevant to heavily multi-threaded
                                                                                                                                                                                                                                                                                                                  -104     * applications anyway. The addition of LongPeriodRNG on March 21, 2016 should help to take the part of a fast,
                                                                                                                                                                                                                                                                                                                  -105     * large-period RNG, which MersenneTwister is unable to act as on GWT. The default may change again some time after
                                                                                                                                                                                                                                                                                                                  -106     * May 1, 2016, now that we have XoRoRNG, which is approximately as fast as LightRNG and has a substantially better
                                                                                                                                                                                                                                                                                                                  -107     * period (pow(2, 128) - 1).
                                                                                                                                                                                                                                                                                                                  -108     */
                                                                                                                                                                                                                                                                                                                  -109    public RNG() {
                                                                                                                                                                                                                                                                                                                  -110        this(new LightRNG());
                                                                                                                                                                                                                                                                                                                  -111    }
                                                                                                                                                                                                                                                                                                                  -112
                                                                                                                                                                                                                                                                                                                  -113    /**
                                                                                                                                                                                                                                                                                                                  -114     * Seeded constructor; uses LightRNG, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  -115     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -116     */
                                                                                                                                                                                                                                                                                                                  -117    public RNG(long seed) {
                                                                                                                                                                                                                                                                                                                  -118        this(new LightRNG(seed));
                                                                                                                                                                                                                                                                                                                  -119    }
                                                                                                                                                                                                                                                                                                                  -120
                                                                                                                                                                                                                                                                                                                  -121    /**
                                                                                                                                                                                                                                                                                                                  -122     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  -123     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  -124     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -125     */
                                                                                                                                                                                                                                                                                                                  -126    public RNG(String seedString) {
                                                                                                                                                                                                                                                                                                                  -127        this(new LightRNG(CrossHash.hash(seedString)));
                                                                                                                                                                                                                                                                                                                  -128    }
                                                                                                                                                                                                                                                                                                                  -129
                                                                                                                                                                                                                                                                                                                  -130    /**
                                                                                                                                                                                                                                                                                                                  -131     * Uses the provided source of randomness for all calculations. This
                                                                                                                                                                                                                                                                                                                  -132     * constructor should be used if an alternate RandomnessSource other than LightRNG is desirable.
                                                                                                                                                                                                                                                                                                                  -133     *
                                                                                                                                                                                                                                                                                                                  -134     * @param random the source of pseudo-randomness, such as a MersenneTwister or SobolQRNG object
                                                                                                                                                                                                                                                                                                                  -135     */
                                                                                                                                                                                                                                                                                                                  -136    public RNG(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -137        this.random = random;
                                                                                                                                                                                                                                                                                                                  -138    }
                                                                                                                                                                                                                                                                                                                  -139
                                                                                                                                                                                                                                                                                                                  -140    /**
                                                                                                                                                                                                                                                                                                                  -141     * A subclass of java.util.Random that uses a RandomnessSource supplied by the user instead of the default.
                                                                                                                                                                                                                                                                                                                  -142     *
                                                                                                                                                                                                                                                                                                                  -143     * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  -144     */
                                                                                                                                                                                                                                                                                                                  -145    public static class CustomRandom extends Random {
                                                                                                                                                                                                                                                                                                                  -146
                                                                                                                                                                                                                                                                                                                  -147        private static final long serialVersionUID = 8211985716129281944L;
                                                                                                                                                                                                                                                                                                                  -148        private final RandomnessSource randomnessSource;
                                                                                                                                                                                                                                                                                                                  -149
                                                                                                                                                                                                                                                                                                                  -150        /**
                                                                                                                                                                                                                                                                                                                  -151         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  -152         * a LightRNG with a random seed.
                                                                                                                                                                                                                                                                                                                  -153         */
                                                                                                                                                                                                                                                                                                                  -154        public CustomRandom() {
                                                                                                                                                                                                                                                                                                                  -155            randomnessSource = new LightRNG();
                                                                                                                                                                                                                                                                                                                  -156        }
                                                                                                                                                                                                                                                                                                                  -157
                                                                                                                                                                                                                                                                                                                  -158        /**
                                                                                                                                                                                                                                                                                                                  -159         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  -160         * the seed of the given RandomnessSource if it has been seeded.
                                                                                                                                                                                                                                                                                                                  -161         *
                                                                                                                                                                                                                                                                                                                  -162         * @param randomnessSource a way to get random bits, supplied by RNG
                                                                                                                                                                                                                                                                                                                  -163         */
                                                                                                                                                                                                                                                                                                                  -164        public CustomRandom(RandomnessSource randomnessSource) {
                                                                                                                                                                                                                                                                                                                  -165            this.randomnessSource = randomnessSource;
                                                                                                                                                                                                                                                                                                                  -166        }
                                                                                                                                                                                                                                                                                                                  -167
                                                                                                                                                                                                                                                                                                                  -168        /**
                                                                                                                                                                                                                                                                                                                  -169         * Generates the next pseudorandom number. Subclasses should
                                                                                                                                                                                                                                                                                                                  -170         * override this, as this is used by all other methods.
                                                                                                                                                                                                                                                                                                                  -171         * <p>
                                                                                                                                                                                                                                                                                                                  -172         * <p>The general contract of {@code next} is that it returns an
                                                                                                                                                                                                                                                                                                                  -173         * {@code int} value and if the argument {@code bits} is between
                                                                                                                                                                                                                                                                                                                  -174         * {@code 1} and {@code 32} (inclusive), then that many low-order
                                                                                                                                                                                                                                                                                                                  -175         * bits of the returned value will be (approximately) independently
                                                                                                                                                                                                                                                                                                                  -176         * chosen bit values, each of which is (approximately) equally
                                                                                                                                                                                                                                                                                                                  -177         * likely to be {@code 0} or {@code 1}. The method {@code next} is
                                                                                                                                                                                                                                                                                                                  -178         * implemented by class {@code Random} by atomically updating the seed to
                                                                                                                                                                                                                                                                                                                  -179         * <pre>{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}</pre>
                                                                                                                                                                                                                                                                                                                  -180         * and returning
                                                                                                                                                                                                                                                                                                                  -181         * <pre>{@code (int)(seed >>> (48 - bits))}.</pre>
                                                                                                                                                                                                                                                                                                                  -182         *
                                                                                                                                                                                                                                                                                                                  -183         * This is a linear congruential pseudorandom number generator, as
                                                                                                                                                                                                                                                                                                                  -184         * defined by D. H. Lehmer and described by Donald E. Knuth in
                                                                                                                                                                                                                                                                                                                  -185         * <i>The Art of Computer Programming,</i> Volume 3:
                                                                                                                                                                                                                                                                                                                  -186         * <i>Seminumerical Algorithms</i>, section 3.2.1.
                                                                                                                                                                                                                                                                                                                  -187         *
                                                                                                                                                                                                                                                                                                                  -188         * @param bits random bits
                                                                                                                                                                                                                                                                                                                  -189         * @return the next pseudorandom value from this random number
                                                                                                                                                                                                                                                                                                                  -190         * generator's sequence
                                                                                                                                                                                                                                                                                                                  -191         * @since 1.1
                                                                                                                                                                                                                                                                                                                  -192         */
                                                                                                                                                                                                                                                                                                                  -193        @Override
                                                                                                                                                                                                                                                                                                                  -194        protected int next(int bits) {
                                                                                                                                                                                                                                                                                                                  -195            return randomnessSource.next(bits);
                                                                                                                                                                                                                                                                                                                  -196        }
                                                                                                                                                                                                                                                                                                                  -197    }
                                                                                                                                                                                                                                                                                                                  -198
                                                                                                                                                                                                                                                                                                                  -199    /**
                                                                                                                                                                                                                                                                                                                  -200     * @return a Random instance that can be used for legacy compatibility
                                                                                                                                                                                                                                                                                                                  -201     */
                                                                                                                                                                                                                                                                                                                  -202    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  -203        if (ran == null) {
                                                                                                                                                                                                                                                                                                                  -204            ran = new CustomRandom(random);
                                                                                                                                                                                                                                                                                                                  -205        }
                                                                                                                                                                                                                                                                                                                  -206        return ran;
                                                                                                                                                                                                                                                                                                                  -207    }
                                                                                                                                                                                                                                                                                                                  -208
                                                                                                                                                                                                                                                                                                                  -209    /**
                                                                                                                                                                                                                                                                                                                  -210     * Returns a value from an even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  -211     * (exclusive).
                                                                                                                                                                                                                                                                                                                  -212     *
                                                                                                                                                                                                                                                                                                                  -213     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -214     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -215     * @return the found value
                                                                                                                                                                                                                                                                                                                  -216     */
                                                                                                                                                                                                                                                                                                                  -217    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  -218        return min + (max - min) * nextDouble();
                                                                                                                                                                                                                                                                                                                  -219    }
                                                                                                                                                                                                                                                                                                                  -220
                                                                                                                                                                                                                                                                                                                  -221    /**
                                                                                                                                                                                                                                                                                                                  -222     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -223     * <p>
                                                                                                                                                                                                                                                                                                                  -224     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -225     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -226     *
                                                                                                                                                                                                                                                                                                                  -227     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -228     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -229     * @return the found value
                                                                                                                                                                                                                                                                                                                  -230     */
                                                                                                                                                                                                                                                                                                                  -231    public int between(int min, int max) {
                                                                                                                                                                                                                                                                                                                  -232        return nextInt(max - min) + min;
                                                                                                                                                                                                                                                                                                                  -233    }
                                                                                                                                                                                                                                                                                                                  -234
                                                                                                                                                                                                                                                                                                                  -235    /**
                                                                                                                                                                                                                                                                                                                  -236     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -237     * <p>
                                                                                                                                                                                                                                                                                                                  -238     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -239     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -240     *
                                                                                                                                                                                                                                                                                                                  -241     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -242     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -243     * @return the found value
                                                                                                                                                                                                                                                                                                                  -244     */
                                                                                                                                                                                                                                                                                                                  -245    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  -246        return nextLong(max - min) + min;
                                                                                                                                                                                                                                                                                                                  -247    }
                                                                                                                                                                                                                                                                                                                  -248
                                                                                                                                                                                                                                                                                                                  -249    /**
                                                                                                                                                                                                                                                                                                                  -250     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  -251     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  -252     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  -253     * <p>
                                                                                                                                                                                                                                                                                                                  -254     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -255     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -256     * <p>
                                                                                                                                                                                                                                                                                                                  -257     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  -258     *
                                                                                                                                                                                                                                                                                                                  -259     * @param min     the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -260     * @param max     the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -261     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  -262     * @return the found value
                                                                                                                                                                                                                                                                                                                  -263     */
                                                                                                                                                                                                                                                                                                                  -264    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  -265        int sum = 0;
                                                                                                                                                                                                                                                                                                                  -266        for (int i = 0; i < samples; i++) {
                                                                                                                                                                                                                                                                                                                  -267            sum += between(min, max);
                                                                                                                                                                                                                                                                                                                  -268        }
                                                                                                                                                                                                                                                                                                                  -269
                                                                                                                                                                                                                                                                                                                  -270        return Math.round((float) sum / samples);
                                                                                                                                                                                                                                                                                                                  -271    }
                                                                                                                                                                                                                                                                                                                  -272
                                                                                                                                                                                                                                                                                                                  -273    /**
                                                                                                                                                                                                                                                                                                                  -274     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  -275     * type.
                                                                                                                                                                                                                                                                                                                  -276     *
                                                                                                                                                                                                                                                                                                                  -277     * @param <T>   the type of the returned object
                                                                                                                                                                                                                                                                                                                  -278     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  -279     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -280     */
                                                                                                                                                                                                                                                                                                                  -281    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  -282        if (array.length < 1) {
                                                                                                                                                                                                                                                                                                                  -283            return null;
                                                                                                                                                                                                                                                                                                                  -284        }
                                                                                                                                                                                                                                                                                                                  -285        return array[nextInt(array.length)];
                                                                                                                                                                                                                                                                                                                  -286    }
                                                                                                                                                                                                                                                                                                                  -287
                                                                                                                                                                                                                                                                                                                  -288    /**
                                                                                                                                                                                                                                                                                                                  -289     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  -290     * then null is returned.
                                                                                                                                                                                                                                                                                                                  -291     *
                                                                                                                                                                                                                                                                                                                  -292     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  -293     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  -294     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -295     */
                                                                                                                                                                                                                                                                                                                  -296    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -297        if (list.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  -298            return null;
                                                                                                                                                                                                                                                                                                                  -299        }
                                                                                                                                                                                                                                                                                                                  -300        return list.get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  -301    }
                                                                                                                                                                                                                                                                                                                  -302
                                                                                                                                                                                                                                                                                                                  -303    /**
                                                                                                                                                                                                                                                                                                                  -304     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  -305     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  -306     * <p>
                                                                                                                                                                                                                                                                                                                  +093    /**
                                                                                                                                                                                                                                                                                                                  +094     * Default constructor; uses SplitMix64, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  +095     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +096     * <br>
                                                                                                                                                                                                                                                                                                                  +097     * Compatibility note: previous versions of SquidLib used Mersenne Twister by default. Due to the incompatibility
                                                                                                                                                                                                                                                                                                                  +098     * of the threads used by this Mersenne Twister implementation with GWT and HTML5 applications, the randomness
                                                                                                                                                                                                                                                                                                                  +099     * algorithm has been changed to a faster, more compatible algorithm, though it does suffer from a much lower
                                                                                                                                                                                                                                                                                                                  +100     * period. If you need drastically larger periods than 2^64, you can pass a LongPeriodRNG (or MersenneTwister on
                                                                                                                                                                                                                                                                                                                  +101     * targets other than HTML) object to the constructor that takes a RandomnessSource. If you don't know what the
                                                                                                                                                                                                                                                                                                                  +102     * period of a PRNG is, you probably don't need to worry about it; it's mainly relevant to heavily multi-threaded
                                                                                                                                                                                                                                                                                                                  +103     * applications anyway. The addition of LongPeriodRNG on March 21, 2016 should help to take the part of a fast,
                                                                                                                                                                                                                                                                                                                  +104     * large-period RNG, which MersenneTwister is unable to act as on GWT. The default may change again some time after
                                                                                                                                                                                                                                                                                                                  +105     * May 1, 2016, now that we have XoRoRNG, which is approximately as fast as LightRNG and has a substantially better
                                                                                                                                                                                                                                                                                                                  +106     * period (pow(2, 128) - 1). It may change instead to the newer ThrustRNG, which is extremely similar to LightRNG
                                                                                                                                                                                                                                                                                                                  +107     * except that it has slightly better statistical quality (both excellent) and is a fair amount faster (its period
                                                                                                                                                                                                                                                                                                                  +108     * remains at pow(2, 64)).
                                                                                                                                                                                                                                                                                                                  +109     */
                                                                                                                                                                                                                                                                                                                  +110    public RNG() {
                                                                                                                                                                                                                                                                                                                  +111        this(new LightRNG());
                                                                                                                                                                                                                                                                                                                  +112    }
                                                                                                                                                                                                                                                                                                                  +113
                                                                                                                                                                                                                                                                                                                  +114    /**
                                                                                                                                                                                                                                                                                                                  +115     * Seeded constructor; uses LightRNG, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  +116     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +117     */
                                                                                                                                                                                                                                                                                                                  +118    public RNG(long seed) {
                                                                                                                                                                                                                                                                                                                  +119        this(new LightRNG(seed));
                                                                                                                                                                                                                                                                                                                  +120    }
                                                                                                                                                                                                                                                                                                                  +121
                                                                                                                                                                                                                                                                                                                  +122    /**
                                                                                                                                                                                                                                                                                                                  +123     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  +124     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  +125     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +126     */
                                                                                                                                                                                                                                                                                                                  +127    public RNG(CharSequence seedString) {
                                                                                                                                                                                                                                                                                                                  +128        this(new LightRNG(CrossHash.hash(seedString)));
                                                                                                                                                                                                                                                                                                                  +129    }
                                                                                                                                                                                                                                                                                                                  +130
                                                                                                                                                                                                                                                                                                                  +131    /**
                                                                                                                                                                                                                                                                                                                  +132     * Uses the provided source of randomness for all calculations. This
                                                                                                                                                                                                                                                                                                                  +133     * constructor should be used if an alternate RandomnessSource other than LightRNG is desirable.
                                                                                                                                                                                                                                                                                                                  +134     * If the parameter is null, this is equivalent to using {@link #RNG()} as the constructor.
                                                                                                                                                                                                                                                                                                                  +135     * @param random the source of pseudo-randomness, such as a MersenneTwister or SobolQRNG object
                                                                                                                                                                                                                                                                                                                  +136     */
                                                                                                                                                                                                                                                                                                                  +137    public RNG(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +138        this.random = (random == null) ? new LightRNG() : random;
                                                                                                                                                                                                                                                                                                                  +139    }
                                                                                                                                                                                                                                                                                                                  +140
                                                                                                                                                                                                                                                                                                                  +141    /**
                                                                                                                                                                                                                                                                                                                  +142     * A subclass of java.util.Random that uses a RandomnessSource supplied by the user instead of the default.
                                                                                                                                                                                                                                                                                                                  +143     *
                                                                                                                                                                                                                                                                                                                  +144     * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  +145     */
                                                                                                                                                                                                                                                                                                                  +146    public static class CustomRandom extends Random {
                                                                                                                                                                                                                                                                                                                  +147
                                                                                                                                                                                                                                                                                                                  +148        private static final long serialVersionUID = 8211985716129281944L;
                                                                                                                                                                                                                                                                                                                  +149        private final RandomnessSource randomnessSource;
                                                                                                                                                                                                                                                                                                                  +150
                                                                                                                                                                                                                                                                                                                  +151        /**
                                                                                                                                                                                                                                                                                                                  +152         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  +153         * a LightRNG with a random seed.
                                                                                                                                                                                                                                                                                                                  +154         */
                                                                                                                                                                                                                                                                                                                  +155        public CustomRandom() {
                                                                                                                                                                                                                                                                                                                  +156            randomnessSource = new LightRNG();
                                                                                                                                                                                                                                                                                                                  +157        }
                                                                                                                                                                                                                                                                                                                  +158
                                                                                                                                                                                                                                                                                                                  +159        /**
                                                                                                                                                                                                                                                                                                                  +160         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  +161         * the seed of the given RandomnessSource if it has been seeded.
                                                                                                                                                                                                                                                                                                                  +162         *
                                                                                                                                                                                                                                                                                                                  +163         * @param randomnessSource a way to get random bits, supplied by RNG
                                                                                                                                                                                                                                                                                                                  +164         */
                                                                                                                                                                                                                                                                                                                  +165        public CustomRandom(RandomnessSource randomnessSource) {
                                                                                                                                                                                                                                                                                                                  +166            this.randomnessSource = randomnessSource;
                                                                                                                                                                                                                                                                                                                  +167        }
                                                                                                                                                                                                                                                                                                                  +168
                                                                                                                                                                                                                                                                                                                  +169        /**
                                                                                                                                                                                                                                                                                                                  +170         * Generates the next pseudorandom number. Subclasses should
                                                                                                                                                                                                                                                                                                                  +171         * override this, as this is used by all other methods.
                                                                                                                                                                                                                                                                                                                  +172         * <p>
                                                                                                                                                                                                                                                                                                                  +173         * <p>The general contract of {@code next} is that it returns an
                                                                                                                                                                                                                                                                                                                  +174         * {@code int} value and if the argument {@code bits} is between
                                                                                                                                                                                                                                                                                                                  +175         * {@code 1} and {@code 32} (inclusive), then that many low-order
                                                                                                                                                                                                                                                                                                                  +176         * bits of the returned value will be (approximately) independently
                                                                                                                                                                                                                                                                                                                  +177         * chosen bit values, each of which is (approximately) equally
                                                                                                                                                                                                                                                                                                                  +178         * likely to be {@code 0} or {@code 1}. The method {@code next} is
                                                                                                                                                                                                                                                                                                                  +179         * implemented by class {@code Random} by atomically updating the seed to
                                                                                                                                                                                                                                                                                                                  +180         * <pre>{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}</pre>
                                                                                                                                                                                                                                                                                                                  +181         * and returning
                                                                                                                                                                                                                                                                                                                  +182         * <pre>{@code (int)(seed >>> (48 - bits))}.</pre>
                                                                                                                                                                                                                                                                                                                  +183         *
                                                                                                                                                                                                                                                                                                                  +184         * This is a linear congruential pseudorandom number generator, as
                                                                                                                                                                                                                                                                                                                  +185         * defined by D. H. Lehmer and described by Donald E. Knuth in
                                                                                                                                                                                                                                                                                                                  +186         * <i>The Art of Computer Programming,</i> Volume 3:
                                                                                                                                                                                                                                                                                                                  +187         * <i>Seminumerical Algorithms</i>, section 3.2.1.
                                                                                                                                                                                                                                                                                                                  +188         *
                                                                                                                                                                                                                                                                                                                  +189         * @param bits random bits
                                                                                                                                                                                                                                                                                                                  +190         * @return the next pseudorandom value from this random number
                                                                                                                                                                                                                                                                                                                  +191         * generator's sequence
                                                                                                                                                                                                                                                                                                                  +192         * @since 1.1
                                                                                                                                                                                                                                                                                                                  +193         */
                                                                                                                                                                                                                                                                                                                  +194        @Override
                                                                                                                                                                                                                                                                                                                  +195        protected int next(int bits) {
                                                                                                                                                                                                                                                                                                                  +196            return randomnessSource.next(bits);
                                                                                                                                                                                                                                                                                                                  +197        }
                                                                                                                                                                                                                                                                                                                  +198    }
                                                                                                                                                                                                                                                                                                                  +199
                                                                                                                                                                                                                                                                                                                  +200    /**
                                                                                                                                                                                                                                                                                                                  +201     * @return a Random instance that can be used for legacy compatibility
                                                                                                                                                                                                                                                                                                                  +202     */
                                                                                                                                                                                                                                                                                                                  +203    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  +204        if (ran == null) {
                                                                                                                                                                                                                                                                                                                  +205            ran = new CustomRandom(random);
                                                                                                                                                                                                                                                                                                                  +206        }
                                                                                                                                                                                                                                                                                                                  +207        return ran;
                                                                                                                                                                                                                                                                                                                  +208    }
                                                                                                                                                                                                                                                                                                                  +209
                                                                                                                                                                                                                                                                                                                  +210    /**
                                                                                                                                                                                                                                                                                                                  +211     * Returns a value from an even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  +212     * (exclusive).
                                                                                                                                                                                                                                                                                                                  +213     *
                                                                                                                                                                                                                                                                                                                  +214     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +215     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +216     * @return the found value
                                                                                                                                                                                                                                                                                                                  +217     */
                                                                                                                                                                                                                                                                                                                  +218    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  +219        return min + (max - min) * nextDouble();
                                                                                                                                                                                                                                                                                                                  +220    }
                                                                                                                                                                                                                                                                                                                  +221
                                                                                                                                                                                                                                                                                                                  +222    /**
                                                                                                                                                                                                                                                                                                                  +223     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +224     * <p>
                                                                                                                                                                                                                                                                                                                  +225     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +226     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +227     *
                                                                                                                                                                                                                                                                                                                  +228     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +229     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +230     * @return the found value
                                                                                                                                                                                                                                                                                                                  +231     */
                                                                                                                                                                                                                                                                                                                  +232    public int between(int min, int max) {
                                                                                                                                                                                                                                                                                                                  +233        return nextInt(max - min) + min;
                                                                                                                                                                                                                                                                                                                  +234    }
                                                                                                                                                                                                                                                                                                                  +235
                                                                                                                                                                                                                                                                                                                  +236    /**
                                                                                                                                                                                                                                                                                                                  +237     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +238     * <p>
                                                                                                                                                                                                                                                                                                                  +239     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +240     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +241     *
                                                                                                                                                                                                                                                                                                                  +242     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +243     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +244     * @return the found value
                                                                                                                                                                                                                                                                                                                  +245     */
                                                                                                                                                                                                                                                                                                                  +246    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  +247        return nextLong(max - min) + min;
                                                                                                                                                                                                                                                                                                                  +248    }
                                                                                                                                                                                                                                                                                                                  +249
                                                                                                                                                                                                                                                                                                                  +250    /**
                                                                                                                                                                                                                                                                                                                  +251     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  +252     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  +253     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  +254     * <p>
                                                                                                                                                                                                                                                                                                                  +255     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +256     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +257     * <p>
                                                                                                                                                                                                                                                                                                                  +258     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  +259     *
                                                                                                                                                                                                                                                                                                                  +260     * @param min     the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +261     * @param max     the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +262     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  +263     * @return the found value
                                                                                                                                                                                                                                                                                                                  +264     */
                                                                                                                                                                                                                                                                                                                  +265    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  +266        int sum = 0;
                                                                                                                                                                                                                                                                                                                  +267        for (int i = 0; i < samples; i++) {
                                                                                                                                                                                                                                                                                                                  +268            sum += between(min, max);
                                                                                                                                                                                                                                                                                                                  +269        }
                                                                                                                                                                                                                                                                                                                  +270
                                                                                                                                                                                                                                                                                                                  +271        return Math.round((float) sum / samples);
                                                                                                                                                                                                                                                                                                                  +272    }
                                                                                                                                                                                                                                                                                                                  +273
                                                                                                                                                                                                                                                                                                                  +274    /**
                                                                                                                                                                                                                                                                                                                  +275     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  +276     * type.
                                                                                                                                                                                                                                                                                                                  +277     *
                                                                                                                                                                                                                                                                                                                  +278     * @param <T>   the type of the returned object
                                                                                                                                                                                                                                                                                                                  +279     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  +280     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +281     */
                                                                                                                                                                                                                                                                                                                  +282    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  +283        if (array.length < 1) {
                                                                                                                                                                                                                                                                                                                  +284            return null;
                                                                                                                                                                                                                                                                                                                  +285        }
                                                                                                                                                                                                                                                                                                                  +286        return array[nextInt(array.length)];
                                                                                                                                                                                                                                                                                                                  +287    }
                                                                                                                                                                                                                                                                                                                  +288
                                                                                                                                                                                                                                                                                                                  +289    /**
                                                                                                                                                                                                                                                                                                                  +290     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  +291     * then null is returned.
                                                                                                                                                                                                                                                                                                                  +292     *
                                                                                                                                                                                                                                                                                                                  +293     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  +294     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  +295     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +296     */
                                                                                                                                                                                                                                                                                                                  +297    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  +298        if (list.isEmpty()) {
                                                                                                                                                                                                                                                                                                                  +299            return null;
                                                                                                                                                                                                                                                                                                                  +300        }
                                                                                                                                                                                                                                                                                                                  +301        return list.get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  +302    }
                                                                                                                                                                                                                                                                                                                  +303
                                                                                                                                                                                                                                                                                                                  +304    /**
                                                                                                                                                                                                                                                                                                                  +305     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  +306     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                   307     * <p>
                                                                                                                                                                                                                                                                                                                  -308     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  -309     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  -310     * </p>
                                                                                                                                                                                                                                                                                                                  -311     *
                                                                                                                                                                                                                                                                                                                  -312     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  -313     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -314     */
                                                                                                                                                                                                                                                                                                                  -315    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  -316        if (set.size <= 0) {
                                                                                                                                                                                                                                                                                                                  -317            throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element");
                                                                                                                                                                                                                                                                                                                  -318        }
                                                                                                                                                                                                                                                                                                                  -319        int n = nextInt(set.size);
                                                                                                                                                                                                                                                                                                                  -320        short s = 0;
                                                                                                                                                                                                                                                                                                                  -321        ShortSet.ShortSetIterator ssi = set.iterator();
                                                                                                                                                                                                                                                                                                                  -322        while (n-- >= 0 && ssi.hasNext)
                                                                                                                                                                                                                                                                                                                  -323            s = ssi.next();
                                                                                                                                                                                                                                                                                                                  -324        ssi.reset();
                                                                                                                                                                                                                                                                                                                  -325        return s;
                                                                                                                                                                                                                                                                                                                  -326    }
                                                                                                                                                                                                                                                                                                                  -327
                                                                                                                                                                                                                                                                                                                  -328    /**
                                                                                                                                                                                                                                                                                                                  -329     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  -330     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  -331     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  -332     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  -333     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  -334     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  -335     * <p>
                                                                                                                                                                                                                                                                                                                  +308     * <p>
                                                                                                                                                                                                                                                                                                                  +309     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  +310     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  +311     * </p>
                                                                                                                                                                                                                                                                                                                  +312     *
                                                                                                                                                                                                                                                                                                                  +313     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  +314     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +315     */
                                                                                                                                                                                                                                                                                                                  +316    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  +317        if (set.size <= 0) {
                                                                                                                                                                                                                                                                                                                  +318            throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element");
                                                                                                                                                                                                                                                                                                                  +319        }
                                                                                                                                                                                                                                                                                                                  +320        int n = nextInt(set.size);
                                                                                                                                                                                                                                                                                                                  +321        short s = 0;
                                                                                                                                                                                                                                                                                                                  +322        ShortSet.ShortSetIterator ssi = set.iterator();
                                                                                                                                                                                                                                                                                                                  +323        while (n-- >= 0 && ssi.hasNext)
                                                                                                                                                                                                                                                                                                                  +324            s = ssi.next();
                                                                                                                                                                                                                                                                                                                  +325        ssi.reset();
                                                                                                                                                                                                                                                                                                                  +326        return s;
                                                                                                                                                                                                                                                                                                                  +327    }
                                                                                                                                                                                                                                                                                                                  +328
                                                                                                                                                                                                                                                                                                                  +329    /**
                                                                                                                                                                                                                                                                                                                  +330     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  +331     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  +332     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  +333     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  +334     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  +335     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                   336     * <p>
                                                                                                                                                                                                                                                                                                                  -337     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  -338     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  -339     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  -340     * </p>
                                                                                                                                                                                                                                                                                                                  -341     *
                                                                                                                                                                                                                                                                                                                  -342     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  -343     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  -344     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -345     */
                                                                                                                                                                                                                                                                                                                  -346    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  -347        if (coll.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  -348            return null;
                                                                                                                                                                                                                                                                                                                  -349        }
                                                                                                                                                                                                                                                                                                                  -350        int n = nextInt(coll.size());
                                                                                                                                                                                                                                                                                                                  -351        T t = null;
                                                                                                                                                                                                                                                                                                                  -352        Iterator<T> it = coll.iterator();
                                                                                                                                                                                                                                                                                                                  -353        while (n-- >= 0 && it.hasNext())
                                                                                                                                                                                                                                                                                                                  -354            t = it.next();
                                                                                                                                                                                                                                                                                                                  -355        return t;
                                                                                                                                                                                                                                                                                                                  -356    }
                                                                                                                                                                                                                                                                                                                  -357
                                                                                                                                                                                                                                                                                                                  -358        /*
                                                                                                                                                                                                                                                                                                                  -359     * Returns a random elements from the provided queue. If the queue is empty
                                                                                                                                                                                                                                                                                                                  -360         * then null is returned.
                                                                                                                                                                                                                                                                                                                  -361         *
                                                                                                                                                                                                                                                                                                                  -362         * <p>
                                                                                                                                                                                                                                                                                                                  -363         * Requires iterating through a random amount of the elements in set, so
                                                                                                                                                                                                                                                                                                                  -364         * performance depends on the size of set but is likely to be decent. This
                                                                                                                                                                                                                                                                                                                  -365         * is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  -366         * </p>
                                                                                                                                                                                                                                                                                                                  -367         *
                                                                                                                                                                                                                                                                                                                  -368         * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -369         * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  -370         * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -371         */
                                                                                                                                                                                                                                                                                                                  -372        /*
                                                                                                                                                                                                                                                                                                                  -373        public <T> T getRandomElement(Queue<T> list) {
                                                                                                                                                                                                                                                                                                                  -374                if (list.isEmpty()) {
                                                                                                                                                                                                                                                                                                                  -375                        return null;
                                                                                                                                                                                                                                                                                                                  -376                }
                                                                                                                                                                                                                                                                                                                  -377                return new ArrayList<>(list).get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  -378        }*/
                                                                                                                                                                                                                                                                                                                  -379
                                                                                                                                                                                                                                                                                                                  -380    /**
                                                                                                                                                                                                                                                                                                                  -381     * Given a {@link List} l, this selects a random element of l to be the first value in the returned list l2. It
                                                                                                                                                                                                                                                                                                                  -382     * retains the order of elements in l after that random element and makes them follow the first element in l2, and
                                                                                                                                                                                                                                                                                                                  -383     * loops around to use elements from the start of l after it has placed the last element of l into l2.
                                                                                                                                                                                                                                                                                                                  -384     * <br>
                                                                                                                                                                                                                                                                                                                  -385     * Essentially, it does what it says on the tin. It randomly rotates the List l.
                                                                                                                                                                                                                                                                                                                  +337     * <p>
                                                                                                                                                                                                                                                                                                                  +338     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  +339     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  +340     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  +341     * </p>
                                                                                                                                                                                                                                                                                                                  +342     *
                                                                                                                                                                                                                                                                                                                  +343     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  +344     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  +345     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +346     */
                                                                                                                                                                                                                                                                                                                  +347    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  +348        int n;
                                                                                                                                                                                                                                                                                                                  +349        if ((n = coll.size()) <= 0) {
                                                                                                                                                                                                                                                                                                                  +350            return null;
                                                                                                                                                                                                                                                                                                                  +351        }
                                                                                                                                                                                                                                                                                                                  +352        n = nextInt(n);
                                                                                                                                                                                                                                                                                                                  +353        T t = null;
                                                                                                                                                                                                                                                                                                                  +354        Iterator<T> it = coll.iterator();
                                                                                                                                                                                                                                                                                                                  +355        while (n-- >= 0 && it.hasNext())
                                                                                                                                                                                                                                                                                                                  +356            t = it.next();
                                                                                                                                                                                                                                                                                                                  +357        return t;
                                                                                                                                                                                                                                                                                                                  +358    }
                                                                                                                                                                                                                                                                                                                  +359
                                                                                                                                                                                                                                                                                                                  +360        /*
                                                                                                                                                                                                                                                                                                                  +361     * Returns a random elements from the provided queue. If the queue is empty
                                                                                                                                                                                                                                                                                                                  +362         * then null is returned.
                                                                                                                                                                                                                                                                                                                  +363         *
                                                                                                                                                                                                                                                                                                                  +364         * <p>
                                                                                                                                                                                                                                                                                                                  +365         * Requires iterating through a random amount of the elements in set, so
                                                                                                                                                                                                                                                                                                                  +366         * performance depends on the size of set but is likely to be decent. This
                                                                                                                                                                                                                                                                                                                  +367         * is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  +368         * </p>
                                                                                                                                                                                                                                                                                                                  +369         *
                                                                                                                                                                                                                                                                                                                  +370         * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +371         * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  +372         * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +373         */
                                                                                                                                                                                                                                                                                                                  +374        /*
                                                                                                                                                                                                                                                                                                                  +375        public <T> T getRandomElement(Queue<T> list) {
                                                                                                                                                                                                                                                                                                                  +376                if (list.isEmpty()) {
                                                                                                                                                                                                                                                                                                                  +377                        return null;
                                                                                                                                                                                                                                                                                                                  +378                }
                                                                                                                                                                                                                                                                                                                  +379                return new ArrayList<>(list).get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  +380        }*/
                                                                                                                                                                                                                                                                                                                  +381
                                                                                                                                                                                                                                                                                                                  +382    /**
                                                                                                                                                                                                                                                                                                                  +383     * Given a {@link List} l, this selects a random element of l to be the first value in the returned list l2. It
                                                                                                                                                                                                                                                                                                                  +384     * retains the order of elements in l after that random element and makes them follow the first element in l2, and
                                                                                                                                                                                                                                                                                                                  +385     * loops around to use elements from the start of l after it has placed the last element of l into l2.
                                                                                                                                                                                                                                                                                                                   386     * <br>
                                                                                                                                                                                                                                                                                                                  -387     * If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable()
                                                                                                                                                                                                                                                                                                                  -388     * should have better performance.
                                                                                                                                                                                                                                                                                                                  -389     *
                                                                                                                                                                                                                                                                                                                  -390     * @param l   A {@link List} that will not be modified by this method. All elements of this parameter will be
                                                                                                                                                                                                                                                                                                                  -391     *            shared with the returned List.
                                                                                                                                                                                                                                                                                                                  -392     * @param <T> No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                                                                                                                                                                                                                                                  -393     * @return A shallow copy of {@code l} that has been rotated so its first element has been randomly chosen
                                                                                                                                                                                                                                                                                                                  -394     * from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last
                                                                                                                                                                                                                                                                                                                  -395     * element of l, then element 1, etc.
                                                                                                                                                                                                                                                                                                                  -396     */
                                                                                                                                                                                                                                                                                                                  -397    @GwtIncompatible /* Because of Collections.rotate */
                                                                                                                                                                                                                                                                                                                  -398    public <T> List<T> randomRotation(final List<T> l) {
                                                                                                                                                                                                                                                                                                                  -399        final int sz = l.size();
                                                                                                                                                                                                                                                                                                                  -400        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  -401            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  -402
                                                                                                                                                                                                                                                                                                                  -403                /*
                                                                                                                                                                                                                                                                                                                  -404                 * Collections.rotate should prefer the best-performing way to rotate l,
                                                                                                                                                                                                                                                                                                                  -405                 * which would be an in-place modification for ArrayLists and an append
                                                                                                                                                                                                                                                                                                                  -406                 * to a sublist for Lists that don't support efficient random access.
                                                                                                                                                                                                                                                                                                                  -407                 */
                                                                                                                                                                                                                                                                                                                  -408        List<T> l2 = new ArrayList<>(l);
                                                                                                                                                                                                                                                                                                                  -409        Collections.rotate(l2, nextInt(sz));
                                                                                                                                                                                                                                                                                                                  -410        return l2;
                                                                                                                                                                                                                                                                                                                  -411    }
                                                                                                                                                                                                                                                                                                                  -412
                                                                                                                                                                                                                                                                                                                  -413    /**
                                                                                                                                                                                                                                                                                                                  -414     * Get an Iterable that starts at a random location in list and continues on through list in its current order.
                                                                                                                                                                                                                                                                                                                  -415     * Loops around to the beginning after it gets to the end, stops when it returns to the starting location.
                                                                                                                                                                                                                                                                                                                  -416     * <br>
                                                                                                                                                                                                                                                                                                                  -417     * You should not modify {@code list} while you use the returned reference. And there'll be no
                                                                                                                                                                                                                                                                                                                  -418     * ConcurrentModificationException to detect such erroneous uses.
                                                                                                                                                                                                                                                                                                                  -419     *
                                                                                                                                                                                                                                                                                                                  -420     * @param list A list <b>with a constant-time {@link List#get(int)} method</b> (otherwise performance degrades).
                                                                                                                                                                                                                                                                                                                  -421     * @return An {@link Iterable} that iterates over {@code list} but start at
                                                                                                                                                                                                                                                                                                                  -422     * a random index. If the chosen index is {@code i}, the iterator
                                                                                                                                                                                                                                                                                                                  -423     * will return:
                                                                                                                                                                                                                                                                                                                  -424     * {@code list[i]; list[i+1]; ...; list[list.length() - 1]; list[0]; list[i-1]}
                                                                                                                                                                                                                                                                                                                  -425     */
                                                                                                                                                                                                                                                                                                                  -426    public <T> Iterable<T> getRandomStartIterable(final List<T> list) {
                                                                                                                                                                                                                                                                                                                  -427        final int sz = list.size();
                                                                                                                                                                                                                                                                                                                  -428        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  -429            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  -430
                                                                                                                                                                                                                                                                                                                  -431                /*
                                                                                                                                                                                                                                                                                                                  -432                 * Here's a tricky bit: Defining 'start' here means that every Iterator
                                                                                                                                                                                                                                                                                                                  -433                 * returned by the returned Iterable will have the same iteration order.
                                                                                                                                                                                                                                                                                                                  -434                 * In other words, if you use more than once the returned Iterable,
                                                                                                                                                                                                                                                                                                                  -435                 * you'll will see elements in the same order every time, which is
                                                                                                                                                                                                                                                                                                                  -436                 * desirable.
                                                                                                                                                                                                                                                                                                                  -437                 */
                                                                                                                                                                                                                                                                                                                  -438        final int start = nextInt(sz);
                                                                                                                                                                                                                                                                                                                  -439
                                                                                                                                                                                                                                                                                                                  -440        return new Iterable<T>() {
                                                                                                                                                                                                                                                                                                                  -441            @Override
                                                                                                                                                                                                                                                                                                                  -442            public Iterator<T> iterator() {
                                                                                                                                                                                                                                                                                                                  -443                return new Iterator<T>() {
                                                                                                                                                                                                                                                                                                                  -444
                                                                                                                                                                                                                                                                                                                  -445                    int next = -1;
                                                                                                                                                                                                                                                                                                                  +387     * Essentially, it does what it says on the tin. It randomly rotates the List l.
                                                                                                                                                                                                                                                                                                                  +388     * <br>
                                                                                                                                                                                                                                                                                                                  +389     * If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable()
                                                                                                                                                                                                                                                                                                                  +390     * should have better performance. This was GWT incompatible before GWT 2.8.0 became the version SquidLib uses; now
                                                                                                                                                                                                                                                                                                                  +391     * this method works fine with GWT.
                                                                                                                                                                                                                                                                                                                  +392     *
                                                                                                                                                                                                                                                                                                                  +393     * @param l   A {@link List} that will not be modified by this method. All elements of this parameter will be
                                                                                                                                                                                                                                                                                                                  +394     *            shared with the returned List.
                                                                                                                                                                                                                                                                                                                  +395     * @param <T> No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                                                                                                                                                                                                                                                  +396     * @return A shallow copy of {@code l} that has been rotated so its first element has been randomly chosen
                                                                                                                                                                                                                                                                                                                  +397     * from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last
                                                                                                                                                                                                                                                                                                                  +398     * element of l, then element 1, etc.
                                                                                                                                                                                                                                                                                                                  +399     */
                                                                                                                                                                                                                                                                                                                  +400    public <T> List<T> randomRotation(final List<T> l) {
                                                                                                                                                                                                                                                                                                                  +401        final int sz = l.size();
                                                                                                                                                                                                                                                                                                                  +402        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  +403            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  +404
                                                                                                                                                                                                                                                                                                                  +405                /*
                                                                                                                                                                                                                                                                                                                  +406                 * Collections.rotate should prefer the best-performing way to rotate l,
                                                                                                                                                                                                                                                                                                                  +407                 * which would be an in-place modification for ArrayLists and an append
                                                                                                                                                                                                                                                                                                                  +408                 * to a sublist for Lists that don't support efficient random access.
                                                                                                                                                                                                                                                                                                                  +409                 */
                                                                                                                                                                                                                                                                                                                  +410        List<T> l2 = new ArrayList<>(l);
                                                                                                                                                                                                                                                                                                                  +411        Collections.rotate(l2, nextInt(sz));
                                                                                                                                                                                                                                                                                                                  +412        return l2;
                                                                                                                                                                                                                                                                                                                  +413    }
                                                                                                                                                                                                                                                                                                                  +414
                                                                                                                                                                                                                                                                                                                  +415    /**
                                                                                                                                                                                                                                                                                                                  +416     * Get an Iterable that starts at a random location in list and continues on through list in its current order.
                                                                                                                                                                                                                                                                                                                  +417     * Loops around to the beginning after it gets to the end, stops when it returns to the starting location.
                                                                                                                                                                                                                                                                                                                  +418     * <br>
                                                                                                                                                                                                                                                                                                                  +419     * You should not modify {@code list} while you use the returned reference. And there'll be no
                                                                                                                                                                                                                                                                                                                  +420     * ConcurrentModificationException to detect such erroneous uses.
                                                                                                                                                                                                                                                                                                                  +421     *
                                                                                                                                                                                                                                                                                                                  +422     * @param list A list <b>with a constant-time {@link List#get(int)} method</b> (otherwise performance degrades).
                                                                                                                                                                                                                                                                                                                  +423     * @return An {@link Iterable} that iterates over {@code list} but start at
                                                                                                                                                                                                                                                                                                                  +424     * a random index. If the chosen index is {@code i}, the iterator
                                                                                                                                                                                                                                                                                                                  +425     * will return:
                                                                                                                                                                                                                                                                                                                  +426     * {@code list[i]; list[i+1]; ...; list[list.length() - 1]; list[0]; list[i-1]}
                                                                                                                                                                                                                                                                                                                  +427     */
                                                                                                                                                                                                                                                                                                                  +428    public <T> Iterable<T> getRandomStartIterable(final List<T> list) {
                                                                                                                                                                                                                                                                                                                  +429        final int sz = list.size();
                                                                                                                                                                                                                                                                                                                  +430        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  +431            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  +432
                                                                                                                                                                                                                                                                                                                  +433                /*
                                                                                                                                                                                                                                                                                                                  +434                 * Here's a tricky bit: Defining 'start' here means that every Iterator
                                                                                                                                                                                                                                                                                                                  +435                 * returned by the returned Iterable will have the same iteration order.
                                                                                                                                                                                                                                                                                                                  +436                 * In other words, if you use more than once the returned Iterable,
                                                                                                                                                                                                                                                                                                                  +437                 * you'll will see elements in the same order every time, which is
                                                                                                                                                                                                                                                                                                                  +438                 * desirable.
                                                                                                                                                                                                                                                                                                                  +439                 */
                                                                                                                                                                                                                                                                                                                  +440        final int start = nextInt(sz);
                                                                                                                                                                                                                                                                                                                  +441
                                                                                                                                                                                                                                                                                                                  +442        return new Iterable<T>() {
                                                                                                                                                                                                                                                                                                                  +443            @Override
                                                                                                                                                                                                                                                                                                                  +444            public Iterator<T> iterator() {
                                                                                                                                                                                                                                                                                                                  +445                return new Iterator<T>() {
                                                                                                                                                                                                                                                                                                                   446
                                                                                                                                                                                                                                                                                                                  -447                    @Override
                                                                                                                                                                                                                                                                                                                  -448                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  -449                        return next != start;
                                                                                                                                                                                                                                                                                                                  -450                    }
                                                                                                                                                                                                                                                                                                                  -451
                                                                                                                                                                                                                                                                                                                  -452                    @Override
                                                                                                                                                                                                                                                                                                                  -453                    public T next() {
                                                                                                                                                                                                                                                                                                                  -454                        if (next == start)
                                                                                                                                                                                                                                                                                                                  -455                            throw new NoSuchElementException("Iteration terminated; check hasNext() before next()");
                                                                                                                                                                                                                                                                                                                  -456                        if (next == -1)
                                                                                                                                                                                                                                                                                                                  -457                                        /* First call */
                                                                                                                                                                                                                                                                                                                  -458                            next = start;
                                                                                                                                                                                                                                                                                                                  -459                        final T result = list.get(next);
                                                                                                                                                                                                                                                                                                                  -460                        if (next == sz - 1)
                                                                                                                                                                                                                                                                                                                  -461                                        /*
                                                                                                                                                                                                                                                                                                                  -462                                         * Reached the list's end, let's continue from the list's
                                                                                                                                                                                                                                                                                                                  -463                                         * left.
                                                                                                                                                                                                                                                                                                                  -464                                         */
                                                                                                                                                                                                                                                                                                                  -465                            next = 0;
                                                                                                                                                                                                                                                                                                                  -466                        else
                                                                                                                                                                                                                                                                                                                  -467                            next++;
                                                                                                                                                                                                                                                                                                                  -468                        return result;
                                                                                                                                                                                                                                                                                                                  -469                    }
                                                                                                                                                                                                                                                                                                                  -470
                                                                                                                                                                                                                                                                                                                  -471                    @Override
                                                                                                                                                                                                                                                                                                                  -472                    public void remove() {
                                                                                                                                                                                                                                                                                                                  -473                        throw new UnsupportedOperationException("Remove is not supported from a randomStartIterable");
                                                                                                                                                                                                                                                                                                                  -474                    }
                                                                                                                                                                                                                                                                                                                  -475
                                                                                                                                                                                                                                                                                                                  -476                    @Override
                                                                                                                                                                                                                                                                                                                  -477                    public String toString() {
                                                                                                                                                                                                                                                                                                                  -478                        return "RandomStartIterator at index " + next;
                                                                                                                                                                                                                                                                                                                  -479                    }
                                                                                                                                                                                                                                                                                                                  -480                };
                                                                                                                                                                                                                                                                                                                  -481            }
                                                                                                                                                                                                                                                                                                                  -482        };
                                                                                                                                                                                                                                                                                                                  -483    }
                                                                                                                                                                                                                                                                                                                  -484
                                                                                                                                                                                                                                                                                                                  -485    /**
                                                                                                                                                                                                                                                                                                                  -486     * Use that to get random cells in a rectangular map.
                                                                                                                                                                                                                                                                                                                  -487     *
                                                                                                                                                                                                                                                                                                                  -488     * @param width  The map's width (bounds the x-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  -489     * @param height The map's height (bounds the y-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  -490     * @param size   The number of elements in the returned iterable or anything
                                                                                                                                                                                                                                                                                                                  -491     *               negative for no bound (in which case the iterator is infinite, it's
                                                                                                                                                                                                                                                                                                                  -492     *               up to you to bound your iteration).
                                                                                                                                                                                                                                                                                                                  -493     * @return An iterable that returns random cells in the rectangle (0,0)
                                                                                                                                                                                                                                                                                                                  -494     * (inclusive) .. (width, height) (exclusive).
                                                                                                                                                                                                                                                                                                                  -495     */
                                                                                                                                                                                                                                                                                                                  -496    public Iterable<Coord> getRandomCellsIterable(final int width, final int height, final int size) {
                                                                                                                                                                                                                                                                                                                  -497        return new Iterable<Coord>() {
                                                                                                                                                                                                                                                                                                                  -498            @Override
                                                                                                                                                                                                                                                                                                                  -499            public Iterator<Coord> iterator() {
                                                                                                                                                                                                                                                                                                                  -500                return new Iterator<Coord>() {
                                                                                                                                                                                                                                                                                                                  -501
                                                                                                                                                                                                                                                                                                                  -502                    /**
                                                                                                                                                                                                                                                                                                                  -503                     * The number of elements returned so far
                                                                                                                                                                                                                                                                                                                  -504                     */
                                                                                                                                                                                                                                                                                                                  -505                    int returned = 0;
                                                                                                                                                                                                                                                                                                                  -506
                                                                                                                                                                                                                                                                                                                  -507                    @Override
                                                                                                                                                                                                                                                                                                                  -508                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  -509                        return size < 0 || returned < size;
                                                                                                                                                                                                                                                                                                                  -510                    }
                                                                                                                                                                                                                                                                                                                  -511
                                                                                                                                                                                                                                                                                                                  -512                    @Override
                                                                                                                                                                                                                                                                                                                  -513                    public Coord next() {
                                                                                                                                                                                                                                                                                                                  -514                        if (!hasNext())
                                                                                                                                                                                                                                                                                                                  -515                            throw new NoSuchElementException();
                                                                                                                                                                                                                                                                                                                  -516                        returned++;
                                                                                                                                                                                                                                                                                                                  -517                        return nextCoord(width, height);
                                                                                                                                                                                                                                                                                                                  -518                    }
                                                                                                                                                                                                                                                                                                                  -519
                                                                                                                                                                                                                                                                                                                  -520                    @Override
                                                                                                                                                                                                                                                                                                                  -521                    public void remove() {
                                                                                                                                                                                                                                                                                                                  -522                        throw new UnsupportedOperationException();
                                                                                                                                                                                                                                                                                                                  -523                    }
                                                                                                                                                                                                                                                                                                                  -524                };
                                                                                                                                                                                                                                                                                                                  -525            }
                                                                                                                                                                                                                                                                                                                  -526        };
                                                                                                                                                                                                                                                                                                                  -527    }
                                                                                                                                                                                                                                                                                                                  -528
                                                                                                                                                                                                                                                                                                                  -529    /**
                                                                                                                                                                                                                                                                                                                  -530     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  -531     * random order, with the array containing {@code width * height} items.
                                                                                                                                                                                                                                                                                                                  -532     *
                                                                                                                                                                                                                                                                                                                  -533     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  -534     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  -535     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  -536     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  -537     * @return an array containing {@code width * height} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  -538     */
                                                                                                                                                                                                                                                                                                                  -539    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height) {
                                                                                                                                                                                                                                                                                                                  -540        if (width <= 0 || height <= 0)
                                                                                                                                                                                                                                                                                                                  -541            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  -542        return getRandomUniqueCells(startX, startY, width, height, new Coord[width * height]);
                                                                                                                                                                                                                                                                                                                  -543    }
                                                                                                                                                                                                                                                                                                                  -544
                                                                                                                                                                                                                                                                                                                  -545    /**
                                                                                                                                                                                                                                                                                                                  -546     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  -547     * random order, with the array containing {@code Math.min(width * height, size)} items. If size is less than width
                                                                                                                                                                                                                                                                                                                  -548     * times height, then not all Coords in the space will be used.
                                                                                                                                                                                                                                                                                                                  -549     *
                                                                                                                                                                                                                                                                                                                  -550     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  -551     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  -552     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  -553     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  -554     * @param size   the size of the array to return; only matters if it is smaller than {@code width * height}
                                                                                                                                                                                                                                                                                                                  -555     * @return an array containing {@code Math.min(width * height, size)} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  -556     */
                                                                                                                                                                                                                                                                                                                  -557    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  -558                                        final int size) {
                                                                                                                                                                                                                                                                                                                  -559        if (width <= 0 || height <= 0 || size <= 0)
                                                                                                                                                                                                                                                                                                                  -560            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  -561        return getRandomUniqueCells(startX, startY, width, height, new Coord[Math.min(width * height, size)]);
                                                                                                                                                                                                                                                                                                                  -562    }
                                                                                                                                                                                                                                                                                                                  -563
                                                                                                                                                                                                                                                                                                                  -564    /**
                                                                                                                                                                                                                                                                                                                  -565     * Assigns to dest an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height)
                                                                                                                                                                                                                                                                                                                  -566     * exclusive, in a random order, with dest after this is called containing the lesser of {@code width * height} or
                                                                                                                                                                                                                                                                                                                  -567     * {@code dest.length} items. This will not allocate a new array for dest, but will create a temporary int array for
                                                                                                                                                                                                                                                                                                                  -568     * handling the shuffle.
                                                                                                                                                                                                                                                                                                                  -569     *
                                                                                                                                                                                                                                                                                                                  -570     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  -571     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  -572     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  -573     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  -574     * @param dest   a Coord array that will be modified to contain randomly-ordered Coords, but will not be resized
                                                                                                                                                                                                                                                                                                                  -575     * @return dest, now with up to its first {@code width * height} items assigned to random Coords inside the given bounds
                                                                                                                                                                                                                                                                                                                  -576     */
                                                                                                                                                                                                                                                                                                                  -577    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  -578                                        final Coord[] dest) {
                                                                                                                                                                                                                                                                                                                  -579        if (width <= 0 || height <= 0 || dest == null || dest.length <= 0)
                                                                                                                                                                                                                                                                                                                  -580            return dest;
                                                                                                                                                                                                                                                                                                                  -581        int[] o = randomOrdering(width * height);
                                                                                                                                                                                                                                                                                                                  -582        for (int i = 0; i < o.length && i < dest.length; i++) {
                                                                                                                                                                                                                                                                                                                  -583            dest[i] = Coord.get(startX + o[i] % width, startY + o[i] / width);
                                                                                                                                                                                                                                                                                                                  -584        }
                                                                                                                                                                                                                                                                                                                  -585        return dest;
                                                                                                                                                                                                                                                                                                                  -586    }
                                                                                                                                                                                                                                                                                                                  -587
                                                                                                                                                                                                                                                                                                                  -588    /**
                                                                                                                                                                                                                                                                                                                  -589     * Shuffle an array using the Fisher-Yates algorithm and returns a shuffled copy.
                                                                                                                                                                                                                                                                                                                  -590     * GWT-compatible since GWT 2.8.0, which is the default if you use libGDX 1.9.5 or higher.
                                                                                                                                                                                                                                                                                                                  -591     * <br>
                                                                                                                                                                                                                                                                                                                  -592     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -593     *
                                                                                                                                                                                                                                                                                                                  -594     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -595     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -596     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  -597     */
                                                                                                                                                                                                                                                                                                                  -598    public <T> T[] shuffle(final T[] elements) {
                                                                                                                                                                                                                                                                                                                  -599        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  -600        final T[] array = Arrays.copyOf(elements, n);
                                                                                                                                                                                                                                                                                                                  -601        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -602            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  -603            T t = array[r];
                                                                                                                                                                                                                                                                                                                  -604            if (r != i)
                                                                                                                                                                                                                                                                                                                  -605                array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  -606            array[i] = t;
                                                                                                                                                                                                                                                                                                                  -607        }
                                                                                                                                                                                                                                                                                                                  -608        return array;
                                                                                                                                                                                                                                                                                                                  -609    }
                                                                                                                                                                                                                                                                                                                  -610
                                                                                                                                                                                                                                                                                                                  -611    /**
                                                                                                                                                                                                                                                                                                                  -612     * Shuffles an array in place using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  -613     * If you don't want the array modified, use {@link #shuffle(Object[], Object[])}.
                                                                                                                                                                                                                                                                                                                  -614     * Unlike {@link #shuffle(Object[])}, this is GWT-compatible.
                                                                                                                                                                                                                                                                                                                  -615     * <br>
                                                                                                                                                                                                                                                                                                                  -616     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -617     *
                                                                                                                                                                                                                                                                                                                  -618     * @param elements an array of T; <b>will</b> be modified
                                                                                                                                                                                                                                                                                                                  -619     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -620     * @return elements after shuffling it in-place
                                                                                                                                                                                                                                                                                                                  -621     */
                                                                                                                                                                                                                                                                                                                  -622    public <T> T[] shuffleInPlace(T[] elements) {
                                                                                                                                                                                                                                                                                                                  -623        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  -624        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -625            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  -626            T t = elements[r];
                                                                                                                                                                                                                                                                                                                  -627            if (r != i)
                                                                                                                                                                                                                                                                                                                  -628                elements[r] = elements[i];
                                                                                                                                                                                                                                                                                                                  -629            elements[i] = t;
                                                                                                                                                                                                                                                                                                                  -630        }
                                                                                                                                                                                                                                                                                                                  -631        return elements;
                                                                                                                                                                                                                                                                                                                  -632    }
                                                                                                                                                                                                                                                                                                                  -633
                                                                                                                                                                                                                                                                                                                  -634    /**
                                                                                                                                                                                                                                                                                                                  -635     * Shuffle an array using the Fisher-Yates algorithm. DO NOT give the same array for both elements and
                                                                                                                                                                                                                                                                                                                  -636     * dest, since the prior contents of dest are rearranged before elements is used, and if they refer to the same
                                                                                                                                                                                                                                                                                                                  -637     * array, then you can end up with bizarre bugs where one previously-unique item shows up dozens of times. If
                                                                                                                                                                                                                                                                                                                  -638     * possible, create a new array with the same length as elements and pass it in as dest; the returned value can be
                                                                                                                                                                                                                                                                                                                  -639     * assigned to whatever you want and will have the same items as the newly-formed array.
                                                                                                                                                                                                                                                                                                                  -640     * <br>
                                                                                                                                                                                                                                                                                                                  -641     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -642     *
                                                                                                                                                                                                                                                                                                                  -643     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -644     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -645     * @param dest     Where to put the shuffle. If it does not have the same length as {@code elements}, this will use the
                                                                                                                                                                                                                                                                                                                  -646     *                 randomPortion method of this class to fill the smaller dest. MUST NOT be the same array as elements!
                                                                                                                                                                                                                                                                                                                  -647     * @return {@code dest} after modifications
                                                                                                                                                                                                                                                                                                                  -648     */
                                                                                                                                                                                                                                                                                                                  -649    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  -650        if (dest.length != elements.length)
                                                                                                                                                                                                                                                                                                                  -651            return randomPortion(elements, dest);
                                                                                                                                                                                                                                                                                                                  -652        System.arraycopy(elements, 0, dest, 0, elements.length);
                                                                                                                                                                                                                                                                                                                  -653        shuffleInPlace(dest);
                                                                                                                                                                                                                                                                                                                  -654        return dest;
                                                                                                                                                                                                                                                                                                                  -655    }
                                                                                                                                                                                                                                                                                                                  -656
                                                                                                                                                                                                                                                                                                                  -657    /**
                                                                                                                                                                                                                                                                                                                  -658     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                                                                                                                                                                                  -659     *
                                                                                                                                                                                                                                                                                                                  -660     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -661     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -662     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  -663     */
                                                                                                                                                                                                                                                                                                                  -664    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  -665        return shuffle(elements, null);
                                                                                                                                                                                                                                                                                                                  -666    }
                                                                                                                                                                                                                                                                                                                  -667
                                                                                                                                                                                                                                                                                                                  -668    /**
                                                                                                                                                                                                                                                                                                                  -669     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm. The result
                                                                                                                                                                                                                                                                                                                  -670     * is allocated if {@code buf} is null or if {@code buf} isn't empty,
                                                                                                                                                                                                                                                                                                                  -671     * otherwise {@code elements} is poured into {@code buf}.
                                                                                                                                                                                                                                                                                                                  -672     *
                                                                                                                                                                                                                                                                                                                  -673     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -674     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -675     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  -676     */
                                                                                                                                                                                                                                                                                                                  -677    public <T> ArrayList<T> shuffle(Collection<T> elements, /*@Nullable*/ ArrayList<T> buf) {
                                                                                                                                                                                                                                                                                                                  -678        final ArrayList<T> al;
                                                                                                                                                                                                                                                                                                                  -679        if (buf == null || !buf.isEmpty())
                                                                                                                                                                                                                                                                                                                  -680            al = new ArrayList<>(elements);
                                                                                                                                                                                                                                                                                                                  -681        else {
                                                                                                                                                                                                                                                                                                                  -682            al = buf;
                                                                                                                                                                                                                                                                                                                  -683            al.addAll(elements);
                                                                                                                                                                                                                                                                                                                  -684        }
                                                                                                                                                                                                                                                                                                                  -685        int n = al.size();
                                                                                                                                                                                                                                                                                                                  -686        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -687            Collections.swap(al, i + nextInt(n - i), i);
                                                                                                                                                                                                                                                                                                                  -688        }
                                                                                                                                                                                                                                                                                                                  -689        return al;
                                                                                                                                                                                                                                                                                                                  -690    }
                                                                                                                                                                                                                                                                                                                  -691
                                                                                                                                                                                                                                                                                                                  -692    /**
                                                                                                                                                                                                                                                                                                                  -693     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  -694     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  -695     *
                                                                                                                                                                                                                                                                                                                  -696     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  -697     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  -698     */
                                                                                                                                                                                                                                                                                                                  -699    public int[] randomOrdering(int length) {
                                                                                                                                                                                                                                                                                                                  -700        if (length <= 0)
                                                                                                                                                                                                                                                                                                                  -701            return new int[0];
                                                                                                                                                                                                                                                                                                                  -702        return randomOrdering(length, new int[length]);
                                                                                                                                                                                                                                                                                                                  -703    }
                                                                                                                                                                                                                                                                                                                  -704
                                                                                                                                                                                                                                                                                                                  -705    /**
                                                                                                                                                                                                                                                                                                                  -706     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive) and stores it in
                                                                                                                                                                                                                                                                                                                  -707     * the dest parameter, avoiding allocations.
                                                                                                                                                                                                                                                                                                                  -708     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  -709     *
                                                                                                                                                                                                                                                                                                                  -710     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  -711     * @param dest   the destination array; will be modified
                                                                                                                                                                                                                                                                                                                  -712     * @return dest, filled with a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  -713     */
                                                                                                                                                                                                                                                                                                                  -714    public int[] randomOrdering(int length, int[] dest) {
                                                                                                                                                                                                                                                                                                                  -715        if (dest == null) return null;
                                                                                                                                                                                                                                                                                                                  -716
                                                                                                                                                                                                                                                                                                                  -717        final int n = Math.min(length, dest.length);
                                                                                                                                                                                                                                                                                                                  -718        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  -719            dest[i] = i;
                                                                                                                                                                                                                                                                                                                  -720        }
                                                                                                                                                                                                                                                                                                                  -721        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -722            int r = i + nextIntHasty(n - i),
                                                                                                                                                                                                                                                                                                                  -723                    t = dest[r];
                                                                                                                                                                                                                                                                                                                  -724            if (r != i)
                                                                                                                                                                                                                                                                                                                  -725                dest[r] = dest[i];
                                                                                                                                                                                                                                                                                                                  -726            dest[i] = t;
                                                                                                                                                                                                                                                                                                                  -727        }
                                                                                                                                                                                                                                                                                                                  -728        return dest;
                                                                                                                                                                                                                                                                                                                  -729    }
                                                                                                                                                                                                                                                                                                                  -730
                                                                                                                                                                                                                                                                                                                  -731    /**
                                                                                                                                                                                                                                                                                                                  -732     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  -733     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  -734     * generating random indices for data's elements, but only as much as needed, assigning the copied section to output
                                                                                                                                                                                                                                                                                                                  -735     * and not modifying data.
                                                                                                                                                                                                                                                                                                                  -736     * <br>
                                                                                                                                                                                                                                                                                                                  -737     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  -738     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  -739     *
                                                                                                                                                                                                                                                                                                                  -740     * @param data   an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -741     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  -742     * @param <T>    can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -743     * @return an array of T that has length equal to output's length and may contain unchanged elements (null if output
                                                                                                                                                                                                                                                                                                                  -744     * was empty) if data is shorter than output
                                                                                                                                                                                                                                                                                                                  -745     */
                                                                                                                                                                                                                                                                                                                  -746    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  -747        int length = data.length;
                                                                                                                                                                                                                                                                                                                  -748        int n = Math.min(length, output.length);
                                                                                                                                                                                                                                                                                                                  -749        int[] mapping = ArrayTools.range(n);
                                                                                                                                                                                                                                                                                                                  -750        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  -751            int r = nextIntHasty(length);
                                                                                                                                                                                                                                                                                                                  -752            output[i] = data[mapping[r]];
                                                                                                                                                                                                                                                                                                                  -753            mapping[r] = mapping[--length];
                                                                                                                                                                                                                                                                                                                  -754        }
                                                                                                                                                                                                                                                                                                                  -755
                                                                                                                                                                                                                                                                                                                  -756        return output;
                                                                                                                                                                                                                                                                                                                  -757    }
                                                                                                                                                                                                                                                                                                                  -758
                                                                                                                                                                                                                                                                                                                  -759    /**
                                                                                                                                                                                                                                                                                                                  -760     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  -761     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  -762     *
                                                                                                                                                                                                                                                                                                                  -763     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -764     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  -765     * @param <T>   can be any non-primitive type
                                                                                                                                                                                                                                                                                                                  -766     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  -767     */
                                                                                                                                                                                                                                                                                                                  -768    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  -769        return shuffle(data).subList(0, Math.min(count, data.size()));
                                                                                                                                                                                                                                                                                                                  -770    }
                                                                                                                                                                                                                                                                                                                  -771
                                                                                                                                                                                                                                                                                                                  -772    /**
                                                                                                                                                                                                                                                                                                                  -773     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  -774     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  -775     *
                                                                                                                                                                                                                                                                                                                  -776     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  -777     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  -778     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  -779     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  -780     */
                                                                                                                                                                                                                                                                                                                  -781    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  -782        if (end <= start || start < 0)
                                                                                                                                                                                                                                                                                                                  -783            return new int[0];
                                                                                                                                                                                                                                                                                                                  -784
                                                                                                                                                                                                                                                                                                                  -785        int n = end - start;
                                                                                                                                                                                                                                                                                                                  -786        int[] data = new int[n];
                                                                                                                                                                                                                                                                                                                  -787
                                                                                                                                                                                                                                                                                                                  -788        for (int e = start, i = 0; e < end; e++) {
                                                                                                                                                                                                                                                                                                                  -789            data[i++] = e;
                                                                                                                                                                                                                                                                                                                  -790        }
                                                                                                                                                                                                                                                                                                                  -791
                                                                                                                                                                                                                                                                                                                  -792        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -793            int r = i + nextInt(n - i), t = data[r];
                                                                                                                                                                                                                                                                                                                  -794            if (r != i)
                                                                                                                                                                                                                                                                                                                  -795                data[r] = data[i];
                                                                                                                                                                                                                                                                                                                  -796            data[i] = t;
                                                                                                                                                                                                                                                                                                                  -797        }
                                                                                                                                                                                                                                                                                                                  -798        int[] array = new int[Math.min(count, n)];
                                                                                                                                                                                                                                                                                                                  -799        System.arraycopy(data, 0, array, 0, Math.min(count, n));
                                                                                                                                                                                                                                                                                                                  -800        return array;
                                                                                                                                                                                                                                                                                                                  -801    }
                                                                                                                                                                                                                                                                                                                  -802
                                                                                                                                                                                                                                                                                                                  -803    /**
                                                                                                                                                                                                                                                                                                                  -804     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  -805     */
                                                                                                                                                                                                                                                                                                                  -806    public double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  -807        if (haveNextNextGaussian) {
                                                                                                                                                                                                                                                                                                                  -808            haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  -809            return nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  -810        } else {
                                                                                                                                                                                                                                                                                                                  -811            double v1, v2, s;
                                                                                                                                                                                                                                                                                                                  -812            do {
                                                                                                                                                                                                                                                                                                                  -813                v1 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  -814                v2 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  -815                s = v1 * v1 + v2 * v2;
                                                                                                                                                                                                                                                                                                                  -816            } while (s >= 1 || s == 0);
                                                                                                                                                                                                                                                                                                                  -817            double multiplier = Math.sqrt(-2 * Math.log(s) / s);
                                                                                                                                                                                                                                                                                                                  -818            nextNextGaussian = v2 * multiplier;
                                                                                                                                                                                                                                                                                                                  -819            haveNextNextGaussian = true;
                                                                                                                                                                                                                                                                                                                  -820            return v1 * multiplier;
                                                                                                                                                                                                                                                                                                                  -821        }
                                                                                                                                                                                                                                                                                                                  -822    }
                                                                                                                                                                                                                                                                                                                  -823
                                                                                                                                                                                                                                                                                                                  -824    /**
                                                                                                                                                                                                                                                                                                                  -825     * This returns a maximum of 0.9999999999999999 because that is the largest
                                                                                                                                                                                                                                                                                                                  -826     * Double value that is less than 1.0
                                                                                                                                                                                                                                                                                                                  -827     *
                                                                                                                                                                                                                                                                                                                  -828     * @return a value between 0 (inclusive) and 0.9999999999999999 (inclusive)
                                                                                                                                                                                                                                                                                                                  -829     */
                                                                                                                                                                                                                                                                                                                  -830    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  -831        return (random.nextLong() & 0x1fffffffffffffL) * DOUBLE_UNIT;
                                                                                                                                                                                                                                                                                                                  -832        // consider changing to this in a future version; it will break compatibility but should be fast/correct
                                                                                                                                                                                                                                                                                                                  -833        //return Double.longBitsToDouble(0x3FF0000000000000L | random.nextLong() >>> 12) - 1.0;
                                                                                                                                                                                                                                                                                                                  -834    }
                                                                                                                                                                                                                                                                                                                  -835
                                                                                                                                                                                                                                                                                                                  -836    /**
                                                                                                                                                                                                                                                                                                                  -837     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -838     *
                                                                                                                                                                                                                                                                                                                  -839     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  -840     */
                                                                                                                                                                                                                                                                                                                  -841    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  -842        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  -843    }
                                                                                                                                                                                                                                                                                                                  -844
                                                                                                                                                                                                                                                                                                                  -845    /**
                                                                                                                                                                                                                                                                                                                  -846     * This returns a maximum of 0.99999994 because that is the largest Float
                                                                                                                                                                                                                                                                                                                  -847     * value that is less than 1.0f
                                                                                                                                                                                                                                                                                                                  -848     *
                                                                                                                                                                                                                                                                                                                  -849     * @return a value between 0 (inclusive) and 0.99999994 (inclusive)
                                                                                                                                                                                                                                                                                                                  -850     */
                                                                                                                                                                                                                                                                                                                  -851    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  -852        return next(24) * FLOAT_UNIT;
                                                                                                                                                                                                                                                                                                                  -853    }
                                                                                                                                                                                                                                                                                                                  -854
                                                                                                                                                                                                                                                                                                                  -855    /**
                                                                                                                                                                                                                                                                                                                  -856     * Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                                                                                                                                                                                  -857     *
                                                                                                                                                                                                                                                                                                                  -858     * @return a random boolean.
                                                                                                                                                                                                                                                                                                                  -859     */
                                                                                                                                                                                                                                                                                                                  -860    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  -861        return nextLong() < 0L;
                                                                                                                                                                                                                                                                                                                  -862    }
                                                                                                                                                                                                                                                                                                                  -863
                                                                                                                                                                                                                                                                                                                  -864    /**
                                                                                                                                                                                                                                                                                                                  -865     * Get a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  -866     *
                                                                                                                                                                                                                                                                                                                  -867     * @return a 64-bit random long.
                                                                                                                                                                                                                                                                                                                  -868     */
                                                                                                                                                                                                                                                                                                                  -869    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  -870        return random.nextLong();
                                                                                                                                                                                                                                                                                                                  -871    }
                                                                                                                                                                                                                                                                                                                  -872
                                                                                                                                                                                                                                                                                                                  -873    /**
                                                                                                                                                                                                                                                                                                                  -874     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -875     * negative.
                                                                                                                                                                                                                                                                                                                  -876     *
                                                                                                                                                                                                                                                                                                                  -877     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -878     * @return the found number
                                                                                                                                                                                                                                                                                                                  -879     */
                                                                                                                                                                                                                                                                                                                  -880    public long nextLong(final long bound) {
                                                                                                                                                                                                                                                                                                                  -881        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  -882        long threshold = (0x7fffffffffffffffL - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  -883        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  -884            long bits = random.nextLong() & 0x7fffffffffffffffL;
                                                                                                                                                                                                                                                                                                                  -885            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  -886                return bits % bound;
                                                                                                                                                                                                                                                                                                                  -887        }
                                                                                                                                                                                                                                                                                                                  -888    }
                                                                                                                                                                                                                                                                                                                  -889
                                                                                                                                                                                                                                                                                                                  -890    /**
                                                                                                                                                                                                                                                                                                                  -891     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -892     * negative.
                                                                                                                                                                                                                                                                                                                  -893     *
                                                                                                                                                                                                                                                                                                                  -894     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -895     * @return the found number
                                                                                                                                                                                                                                                                                                                  -896     */
                                                                                                                                                                                                                                                                                                                  -897    public int nextInt(final int bound) {
                                                                                                                                                                                                                                                                                                                  -898        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  -899        int threshold = (0x7fffffff - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  -900        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  -901            int bits = random.next(31);
                                                                                                                                                                                                                                                                                                                  -902            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  -903                return bits % bound;
                                                                                                                                                                                                                                                                                                                  -904        }
                                                                                                                                                                                                                                                                                                                  -905    }
                                                                                                                                                                                                                                                                                                                  -906
                                                                                                                                                                                                                                                                                                                  -907    /**
                                                                                                                                                                                                                                                                                                                  -908     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  -909     * Uses an aggressively optimized technique that has some bias, but mostly for values of
                                                                                                                                                                                                                                                                                                                  -910     * bound over 1 billion. This method is considered "hasty" since it should be faster than
                                                                                                                                                                                                                                                                                                                  -911     * nextInt() but gives up some statistical quality to do so. It also has undefined behavior
                                                                                                                                                                                                                                                                                                                  -912     * if bound is negative, though it will probably produce a negative number (just how
                                                                                                                                                                                                                                                                                                                  -913     * negative is an open question).
                                                                                                                                                                                                                                                                                                                  -914     * <br>
                                                                                                                                                                                                                                                                                                                  -915     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  -916     *
                                                                                                                                                                                                                                                                                                                  -917     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  -918     * @return the found number
                                                                                                                                                                                                                                                                                                                  -919     */
                                                                                                                                                                                                                                                                                                                  -920    public int nextIntHasty(final int bound) {
                                                                                                                                                                                                                                                                                                                  -921        return (int) ((bound * (random.nextLong() & 0x7FFFFFFFL)) >> 31);
                                                                                                                                                                                                                                                                                                                  -922    }
                                                                                                                                                                                                                                                                                                                  -923
                                                                                                                                                                                                                                                                                                                  -924    /**
                                                                                                                                                                                                                                                                                                                  -925     * Generates random bytes and places them into the given byte array, modifying it in-place.
                                                                                                                                                                                                                                                                                                                  -926     * The number of random bytes produced is equal to the length of the byte array. Unlike the
                                                                                                                                                                                                                                                                                                                  -927     * method in java.util.Random, this generates 8 bytes at a time, which can be more efficient
                                                                                                                                                                                                                                                                                                                  -928     * with many RandomnessSource types than the JDK's method that generates 4 bytes at a time.
                                                                                                                                                                                                                                                                                                                  -929     * <br>
                                                                                                                                                                                                                                                                                                                  -930     * Adapted from code in the JavaDocs of {@link Random#nextBytes(byte[])}.
                                                                                                                                                                                                                                                                                                                  +447                    int next = -1;
                                                                                                                                                                                                                                                                                                                  +448
                                                                                                                                                                                                                                                                                                                  +449                    @Override
                                                                                                                                                                                                                                                                                                                  +450                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  +451                        return next != start;
                                                                                                                                                                                                                                                                                                                  +452                    }
                                                                                                                                                                                                                                                                                                                  +453
                                                                                                                                                                                                                                                                                                                  +454                    @Override
                                                                                                                                                                                                                                                                                                                  +455                    public T next() {
                                                                                                                                                                                                                                                                                                                  +456                        if (next == start)
                                                                                                                                                                                                                                                                                                                  +457                            throw new NoSuchElementException("Iteration terminated; check hasNext() before next()");
                                                                                                                                                                                                                                                                                                                  +458                        if (next == -1)
                                                                                                                                                                                                                                                                                                                  +459                                        /* First call */
                                                                                                                                                                                                                                                                                                                  +460                            next = start;
                                                                                                                                                                                                                                                                                                                  +461                        final T result = list.get(next);
                                                                                                                                                                                                                                                                                                                  +462                        if (next == sz - 1)
                                                                                                                                                                                                                                                                                                                  +463                                        /*
                                                                                                                                                                                                                                                                                                                  +464                                         * Reached the list's end, let's continue from the list's
                                                                                                                                                                                                                                                                                                                  +465                                         * left.
                                                                                                                                                                                                                                                                                                                  +466                                         */
                                                                                                                                                                                                                                                                                                                  +467                            next = 0;
                                                                                                                                                                                                                                                                                                                  +468                        else
                                                                                                                                                                                                                                                                                                                  +469                            next++;
                                                                                                                                                                                                                                                                                                                  +470                        return result;
                                                                                                                                                                                                                                                                                                                  +471                    }
                                                                                                                                                                                                                                                                                                                  +472
                                                                                                                                                                                                                                                                                                                  +473                    @Override
                                                                                                                                                                                                                                                                                                                  +474                    public void remove() {
                                                                                                                                                                                                                                                                                                                  +475                        throw new UnsupportedOperationException("Remove is not supported from a randomStartIterable");
                                                                                                                                                                                                                                                                                                                  +476                    }
                                                                                                                                                                                                                                                                                                                  +477
                                                                                                                                                                                                                                                                                                                  +478                    @Override
                                                                                                                                                                                                                                                                                                                  +479                    public String toString() {
                                                                                                                                                                                                                                                                                                                  +480                        return "RandomStartIterator at index " + next;
                                                                                                                                                                                                                                                                                                                  +481                    }
                                                                                                                                                                                                                                                                                                                  +482                };
                                                                                                                                                                                                                                                                                                                  +483            }
                                                                                                                                                                                                                                                                                                                  +484        };
                                                                                                                                                                                                                                                                                                                  +485    }
                                                                                                                                                                                                                                                                                                                  +486
                                                                                                                                                                                                                                                                                                                  +487    /**
                                                                                                                                                                                                                                                                                                                  +488     * Use that to get random cells in a rectangular map.
                                                                                                                                                                                                                                                                                                                  +489     *
                                                                                                                                                                                                                                                                                                                  +490     * @param width  The map's width (bounds the x-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  +491     * @param height The map's height (bounds the y-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  +492     * @param size   The number of elements in the returned iterable or anything
                                                                                                                                                                                                                                                                                                                  +493     *               negative for no bound (in which case the iterator is infinite, it's
                                                                                                                                                                                                                                                                                                                  +494     *               up to you to bound your iteration).
                                                                                                                                                                                                                                                                                                                  +495     * @return An iterable that returns random cells in the rectangle (0,0)
                                                                                                                                                                                                                                                                                                                  +496     * (inclusive) .. (width, height) (exclusive).
                                                                                                                                                                                                                                                                                                                  +497     */
                                                                                                                                                                                                                                                                                                                  +498    public Iterable<Coord> getRandomCellsIterable(final int width, final int height, final int size) {
                                                                                                                                                                                                                                                                                                                  +499        return new Iterable<Coord>() {
                                                                                                                                                                                                                                                                                                                  +500            @Override
                                                                                                                                                                                                                                                                                                                  +501            public Iterator<Coord> iterator() {
                                                                                                                                                                                                                                                                                                                  +502                return new Iterator<Coord>() {
                                                                                                                                                                                                                                                                                                                  +503
                                                                                                                                                                                                                                                                                                                  +504                    /**
                                                                                                                                                                                                                                                                                                                  +505                     * The number of elements returned so far
                                                                                                                                                                                                                                                                                                                  +506                     */
                                                                                                                                                                                                                                                                                                                  +507                    int returned = 0;
                                                                                                                                                                                                                                                                                                                  +508
                                                                                                                                                                                                                                                                                                                  +509                    @Override
                                                                                                                                                                                                                                                                                                                  +510                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  +511                        return size < 0 || returned < size;
                                                                                                                                                                                                                                                                                                                  +512                    }
                                                                                                                                                                                                                                                                                                                  +513
                                                                                                                                                                                                                                                                                                                  +514                    @Override
                                                                                                                                                                                                                                                                                                                  +515                    public Coord next() {
                                                                                                                                                                                                                                                                                                                  +516                        if (!hasNext())
                                                                                                                                                                                                                                                                                                                  +517                            throw new NoSuchElementException();
                                                                                                                                                                                                                                                                                                                  +518                        returned++;
                                                                                                                                                                                                                                                                                                                  +519                        return nextCoord(width, height);
                                                                                                                                                                                                                                                                                                                  +520                    }
                                                                                                                                                                                                                                                                                                                  +521
                                                                                                                                                                                                                                                                                                                  +522                    @Override
                                                                                                                                                                                                                                                                                                                  +523                    public void remove() {
                                                                                                                                                                                                                                                                                                                  +524                        throw new UnsupportedOperationException();
                                                                                                                                                                                                                                                                                                                  +525                    }
                                                                                                                                                                                                                                                                                                                  +526                };
                                                                                                                                                                                                                                                                                                                  +527            }
                                                                                                                                                                                                                                                                                                                  +528        };
                                                                                                                                                                                                                                                                                                                  +529    }
                                                                                                                                                                                                                                                                                                                  +530
                                                                                                                                                                                                                                                                                                                  +531    /**
                                                                                                                                                                                                                                                                                                                  +532     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  +533     * random order, with the array containing {@code width * height} items.
                                                                                                                                                                                                                                                                                                                  +534     *
                                                                                                                                                                                                                                                                                                                  +535     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  +536     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  +537     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  +538     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  +539     * @return an array containing {@code width * height} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  +540     */
                                                                                                                                                                                                                                                                                                                  +541    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height) {
                                                                                                                                                                                                                                                                                                                  +542        if (width <= 0 || height <= 0)
                                                                                                                                                                                                                                                                                                                  +543            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  +544        return getRandomUniqueCells(startX, startY, width, height, new Coord[width * height]);
                                                                                                                                                                                                                                                                                                                  +545    }
                                                                                                                                                                                                                                                                                                                  +546
                                                                                                                                                                                                                                                                                                                  +547    /**
                                                                                                                                                                                                                                                                                                                  +548     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  +549     * random order, with the array containing {@code Math.min(width * height, size)} items. If size is less than width
                                                                                                                                                                                                                                                                                                                  +550     * times height, then not all Coords in the space will be used.
                                                                                                                                                                                                                                                                                                                  +551     *
                                                                                                                                                                                                                                                                                                                  +552     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  +553     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  +554     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  +555     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  +556     * @param size   the size of the array to return; only matters if it is smaller than {@code width * height}
                                                                                                                                                                                                                                                                                                                  +557     * @return an array containing {@code Math.min(width * height, size)} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  +558     */
                                                                                                                                                                                                                                                                                                                  +559    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  +560                                        final int size) {
                                                                                                                                                                                                                                                                                                                  +561        if (width <= 0 || height <= 0 || size <= 0)
                                                                                                                                                                                                                                                                                                                  +562            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  +563        return getRandomUniqueCells(startX, startY, width, height, new Coord[Math.min(width * height, size)]);
                                                                                                                                                                                                                                                                                                                  +564    }
                                                                                                                                                                                                                                                                                                                  +565
                                                                                                                                                                                                                                                                                                                  +566    /**
                                                                                                                                                                                                                                                                                                                  +567     * Assigns to dest an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height)
                                                                                                                                                                                                                                                                                                                  +568     * exclusive, in a random order, with dest after this is called containing the lesser of {@code width * height} or
                                                                                                                                                                                                                                                                                                                  +569     * {@code dest.length} items. This will not allocate a new array for dest, but will create a temporary int array for
                                                                                                                                                                                                                                                                                                                  +570     * handling the shuffle.
                                                                                                                                                                                                                                                                                                                  +571     *
                                                                                                                                                                                                                                                                                                                  +572     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  +573     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  +574     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  +575     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  +576     * @param dest   a Coord array that will be modified to contain randomly-ordered Coords, but will not be resized
                                                                                                                                                                                                                                                                                                                  +577     * @return dest, now with up to its first {@code width * height} items assigned to random Coords inside the given bounds
                                                                                                                                                                                                                                                                                                                  +578     */
                                                                                                                                                                                                                                                                                                                  +579    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  +580                                        final Coord[] dest) {
                                                                                                                                                                                                                                                                                                                  +581        if (width <= 0 || height <= 0 || dest == null || dest.length <= 0)
                                                                                                                                                                                                                                                                                                                  +582            return dest;
                                                                                                                                                                                                                                                                                                                  +583        int[] o = randomOrdering(width * height);
                                                                                                                                                                                                                                                                                                                  +584        for (int i = 0; i < o.length && i < dest.length; i++) {
                                                                                                                                                                                                                                                                                                                  +585            dest[i] = Coord.get(startX + o[i] % width, startY + o[i] / width);
                                                                                                                                                                                                                                                                                                                  +586        }
                                                                                                                                                                                                                                                                                                                  +587        return dest;
                                                                                                                                                                                                                                                                                                                  +588    }
                                                                                                                                                                                                                                                                                                                  +589
                                                                                                                                                                                                                                                                                                                  +590    /**
                                                                                                                                                                                                                                                                                                                  +591     * Shuffle an array using the Fisher-Yates algorithm and returns a shuffled copy.
                                                                                                                                                                                                                                                                                                                  +592     * GWT-compatible since GWT 2.8.0, which is the default if you use libGDX 1.9.5 or higher.
                                                                                                                                                                                                                                                                                                                  +593     * <br>
                                                                                                                                                                                                                                                                                                                  +594     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  +595     *
                                                                                                                                                                                                                                                                                                                  +596     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +597     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +598     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  +599     */
                                                                                                                                                                                                                                                                                                                  +600    public <T> T[] shuffle(final T[] elements) {
                                                                                                                                                                                                                                                                                                                  +601        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  +602        final T[] array = Arrays.copyOf(elements, n);
                                                                                                                                                                                                                                                                                                                  +603        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +604            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  +605            T t = array[r];
                                                                                                                                                                                                                                                                                                                  +606            if (r != i)
                                                                                                                                                                                                                                                                                                                  +607                array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  +608            array[i] = t;
                                                                                                                                                                                                                                                                                                                  +609        }
                                                                                                                                                                                                                                                                                                                  +610        return array;
                                                                                                                                                                                                                                                                                                                  +611    }
                                                                                                                                                                                                                                                                                                                  +612
                                                                                                                                                                                                                                                                                                                  +613    /**
                                                                                                                                                                                                                                                                                                                  +614     * Shuffles an array in place using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  +615     * If you don't want the array modified, use {@link #shuffle(Object[], Object[])}.
                                                                                                                                                                                                                                                                                                                  +616     * Unlike {@link #shuffle(Object[])}, this is GWT-compatible.
                                                                                                                                                                                                                                                                                                                  +617     * <br>
                                                                                                                                                                                                                                                                                                                  +618     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  +619     *
                                                                                                                                                                                                                                                                                                                  +620     * @param elements an array of T; <b>will</b> be modified
                                                                                                                                                                                                                                                                                                                  +621     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +622     * @return elements after shuffling it in-place
                                                                                                                                                                                                                                                                                                                  +623     */
                                                                                                                                                                                                                                                                                                                  +624    public <T> T[] shuffleInPlace(T[] elements) {
                                                                                                                                                                                                                                                                                                                  +625        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  +626        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +627            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  +628            T t = elements[r];
                                                                                                                                                                                                                                                                                                                  +629            if (r != i)
                                                                                                                                                                                                                                                                                                                  +630                elements[r] = elements[i];
                                                                                                                                                                                                                                                                                                                  +631            elements[i] = t;
                                                                                                                                                                                                                                                                                                                  +632        }
                                                                                                                                                                                                                                                                                                                  +633        return elements;
                                                                                                                                                                                                                                                                                                                  +634    }
                                                                                                                                                                                                                                                                                                                  +635
                                                                                                                                                                                                                                                                                                                  +636    /**
                                                                                                                                                                                                                                                                                                                  +637     * Shuffle an array using the Fisher-Yates algorithm. DO NOT give the same array for both elements and
                                                                                                                                                                                                                                                                                                                  +638     * dest, since the prior contents of dest are rearranged before elements is used, and if they refer to the same
                                                                                                                                                                                                                                                                                                                  +639     * array, then you can end up with bizarre bugs where one previously-unique item shows up dozens of times. If
                                                                                                                                                                                                                                                                                                                  +640     * possible, create a new array with the same length as elements and pass it in as dest; the returned value can be
                                                                                                                                                                                                                                                                                                                  +641     * assigned to whatever you want and will have the same items as the newly-formed array.
                                                                                                                                                                                                                                                                                                                  +642     * <br>
                                                                                                                                                                                                                                                                                                                  +643     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  +644     *
                                                                                                                                                                                                                                                                                                                  +645     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +646     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +647     * @param dest     Where to put the shuffle. If it does not have the same length as {@code elements}, this will use the
                                                                                                                                                                                                                                                                                                                  +648     *                 randomPortion method of this class to fill the smaller dest. MUST NOT be the same array as elements!
                                                                                                                                                                                                                                                                                                                  +649     * @return {@code dest} after modifications
                                                                                                                                                                                                                                                                                                                  +650     */
                                                                                                                                                                                                                                                                                                                  +651    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  +652        if (dest.length != elements.length)
                                                                                                                                                                                                                                                                                                                  +653            return randomPortion(elements, dest);
                                                                                                                                                                                                                                                                                                                  +654        System.arraycopy(elements, 0, dest, 0, elements.length);
                                                                                                                                                                                                                                                                                                                  +655        shuffleInPlace(dest);
                                                                                                                                                                                                                                                                                                                  +656        return dest;
                                                                                                                                                                                                                                                                                                                  +657    }
                                                                                                                                                                                                                                                                                                                  +658
                                                                                                                                                                                                                                                                                                                  +659    /**
                                                                                                                                                                                                                                                                                                                  +660     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                                                                                                                                                                                  +661     *
                                                                                                                                                                                                                                                                                                                  +662     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +663     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +664     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  +665     */
                                                                                                                                                                                                                                                                                                                  +666    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  +667        return shuffle(elements, null);
                                                                                                                                                                                                                                                                                                                  +668    }
                                                                                                                                                                                                                                                                                                                  +669
                                                                                                                                                                                                                                                                                                                  +670    /**
                                                                                                                                                                                                                                                                                                                  +671     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm. The result
                                                                                                                                                                                                                                                                                                                  +672     * is allocated if {@code buf} is null or if {@code buf} isn't empty,
                                                                                                                                                                                                                                                                                                                  +673     * otherwise {@code elements} is poured into {@code buf}.
                                                                                                                                                                                                                                                                                                                  +674     *
                                                                                                                                                                                                                                                                                                                  +675     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +676     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +677     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  +678     */
                                                                                                                                                                                                                                                                                                                  +679    public <T> ArrayList<T> shuffle(Collection<T> elements, /*@Nullable*/ ArrayList<T> buf) {
                                                                                                                                                                                                                                                                                                                  +680        final ArrayList<T> al;
                                                                                                                                                                                                                                                                                                                  +681        if (buf == null || !buf.isEmpty())
                                                                                                                                                                                                                                                                                                                  +682            al = new ArrayList<>(elements);
                                                                                                                                                                                                                                                                                                                  +683        else {
                                                                                                                                                                                                                                                                                                                  +684            al = buf;
                                                                                                                                                                                                                                                                                                                  +685            al.addAll(elements);
                                                                                                                                                                                                                                                                                                                  +686        }
                                                                                                                                                                                                                                                                                                                  +687        int n = al.size();
                                                                                                                                                                                                                                                                                                                  +688        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +689            Collections.swap(al, i + nextInt(n - i), i);
                                                                                                                                                                                                                                                                                                                  +690        }
                                                                                                                                                                                                                                                                                                                  +691        return al;
                                                                                                                                                                                                                                                                                                                  +692    }
                                                                                                                                                                                                                                                                                                                  +693
                                                                                                                                                                                                                                                                                                                  +694    /**
                                                                                                                                                                                                                                                                                                                  +695     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  +696     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  +697     *
                                                                                                                                                                                                                                                                                                                  +698     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  +699     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  +700     */
                                                                                                                                                                                                                                                                                                                  +701    public int[] randomOrdering(int length) {
                                                                                                                                                                                                                                                                                                                  +702        if (length <= 0)
                                                                                                                                                                                                                                                                                                                  +703            return new int[0];
                                                                                                                                                                                                                                                                                                                  +704        return randomOrdering(length, new int[length]);
                                                                                                                                                                                                                                                                                                                  +705    }
                                                                                                                                                                                                                                                                                                                  +706
                                                                                                                                                                                                                                                                                                                  +707    /**
                                                                                                                                                                                                                                                                                                                  +708     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive) and stores it in
                                                                                                                                                                                                                                                                                                                  +709     * the dest parameter, avoiding allocations.
                                                                                                                                                                                                                                                                                                                  +710     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  +711     *
                                                                                                                                                                                                                                                                                                                  +712     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  +713     * @param dest   the destination array; will be modified
                                                                                                                                                                                                                                                                                                                  +714     * @return dest, filled with a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  +715     */
                                                                                                                                                                                                                                                                                                                  +716    public int[] randomOrdering(int length, int[] dest) {
                                                                                                                                                                                                                                                                                                                  +717        if (dest == null) return null;
                                                                                                                                                                                                                                                                                                                  +718
                                                                                                                                                                                                                                                                                                                  +719        final int n = Math.min(length, dest.length);
                                                                                                                                                                                                                                                                                                                  +720        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  +721            dest[i] = i;
                                                                                                                                                                                                                                                                                                                  +722        }
                                                                                                                                                                                                                                                                                                                  +723        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +724            int r = i + nextIntHasty(n - i),
                                                                                                                                                                                                                                                                                                                  +725                    t = dest[r];
                                                                                                                                                                                                                                                                                                                  +726            if (r != i)
                                                                                                                                                                                                                                                                                                                  +727                dest[r] = dest[i];
                                                                                                                                                                                                                                                                                                                  +728            dest[i] = t;
                                                                                                                                                                                                                                                                                                                  +729        }
                                                                                                                                                                                                                                                                                                                  +730        return dest;
                                                                                                                                                                                                                                                                                                                  +731    }
                                                                                                                                                                                                                                                                                                                  +732
                                                                                                                                                                                                                                                                                                                  +733    /**
                                                                                                                                                                                                                                                                                                                  +734     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  +735     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  +736     * generating random indices for data's elements, but only as much as needed, assigning the copied section to output
                                                                                                                                                                                                                                                                                                                  +737     * and not modifying data.
                                                                                                                                                                                                                                                                                                                  +738     * <br>
                                                                                                                                                                                                                                                                                                                  +739     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  +740     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  +741     *
                                                                                                                                                                                                                                                                                                                  +742     * @param data   an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +743     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  +744     * @param <T>    can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +745     * @return an array of T that has length equal to output's length and may contain unchanged elements (null if output
                                                                                                                                                                                                                                                                                                                  +746     * was empty) if data is shorter than output
                                                                                                                                                                                                                                                                                                                  +747     */
                                                                                                                                                                                                                                                                                                                  +748    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  +749        int length = data.length;
                                                                                                                                                                                                                                                                                                                  +750        int n = Math.min(length, output.length);
                                                                                                                                                                                                                                                                                                                  +751        int[] mapping = ArrayTools.range(n);
                                                                                                                                                                                                                                                                                                                  +752        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  +753            int r = nextIntHasty(length);
                                                                                                                                                                                                                                                                                                                  +754            output[i] = data[mapping[r]];
                                                                                                                                                                                                                                                                                                                  +755            mapping[r] = mapping[--length];
                                                                                                                                                                                                                                                                                                                  +756        }
                                                                                                                                                                                                                                                                                                                  +757
                                                                                                                                                                                                                                                                                                                  +758        return output;
                                                                                                                                                                                                                                                                                                                  +759    }
                                                                                                                                                                                                                                                                                                                  +760
                                                                                                                                                                                                                                                                                                                  +761    /**
                                                                                                                                                                                                                                                                                                                  +762     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  +763     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  +764     *
                                                                                                                                                                                                                                                                                                                  +765     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +766     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  +767     * @param <T>   can be any non-primitive type
                                                                                                                                                                                                                                                                                                                  +768     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  +769     */
                                                                                                                                                                                                                                                                                                                  +770    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  +771        return shuffle(data).subList(0, Math.min(count, data.size()));
                                                                                                                                                                                                                                                                                                                  +772    }
                                                                                                                                                                                                                                                                                                                  +773
                                                                                                                                                                                                                                                                                                                  +774    /**
                                                                                                                                                                                                                                                                                                                  +775     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  +776     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  +777     *
                                                                                                                                                                                                                                                                                                                  +778     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  +779     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  +780     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  +781     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  +782     */
                                                                                                                                                                                                                                                                                                                  +783    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  +784        if (end <= start || start < 0)
                                                                                                                                                                                                                                                                                                                  +785            return new int[0];
                                                                                                                                                                                                                                                                                                                  +786
                                                                                                                                                                                                                                                                                                                  +787        int n = end - start;
                                                                                                                                                                                                                                                                                                                  +788        int[] data = new int[n];
                                                                                                                                                                                                                                                                                                                  +789
                                                                                                                                                                                                                                                                                                                  +790        for (int e = start, i = 0; e < end; e++) {
                                                                                                                                                                                                                                                                                                                  +791            data[i++] = e;
                                                                                                                                                                                                                                                                                                                  +792        }
                                                                                                                                                                                                                                                                                                                  +793
                                                                                                                                                                                                                                                                                                                  +794        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +795            int r = i + nextInt(n - i), t = data[r];
                                                                                                                                                                                                                                                                                                                  +796            if (r != i)
                                                                                                                                                                                                                                                                                                                  +797                data[r] = data[i];
                                                                                                                                                                                                                                                                                                                  +798            data[i] = t;
                                                                                                                                                                                                                                                                                                                  +799        }
                                                                                                                                                                                                                                                                                                                  +800        int[] array = new int[Math.min(count, n)];
                                                                                                                                                                                                                                                                                                                  +801        System.arraycopy(data, 0, array, 0, Math.min(count, n));
                                                                                                                                                                                                                                                                                                                  +802        return array;
                                                                                                                                                                                                                                                                                                                  +803    }
                                                                                                                                                                                                                                                                                                                  +804
                                                                                                                                                                                                                                                                                                                  +805    /**
                                                                                                                                                                                                                                                                                                                  +806     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  +807     */
                                                                                                                                                                                                                                                                                                                  +808    public double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  +809        if (haveNextNextGaussian) {
                                                                                                                                                                                                                                                                                                                  +810            haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  +811            return nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  +812        } else {
                                                                                                                                                                                                                                                                                                                  +813            double v1, v2, s;
                                                                                                                                                                                                                                                                                                                  +814            do {
                                                                                                                                                                                                                                                                                                                  +815                v1 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  +816                v2 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  +817                s = v1 * v1 + v2 * v2;
                                                                                                                                                                                                                                                                                                                  +818            } while (s >= 1 || s == 0);
                                                                                                                                                                                                                                                                                                                  +819            double multiplier = Math.sqrt(-2 * Math.log(s) / s);
                                                                                                                                                                                                                                                                                                                  +820            nextNextGaussian = v2 * multiplier;
                                                                                                                                                                                                                                                                                                                  +821            haveNextNextGaussian = true;
                                                                                                                                                                                                                                                                                                                  +822            return v1 * multiplier;
                                                                                                                                                                                                                                                                                                                  +823        }
                                                                                                                                                                                                                                                                                                                  +824    }
                                                                                                                                                                                                                                                                                                                  +825
                                                                                                                                                                                                                                                                                                                  +826    /**
                                                                                                                                                                                                                                                                                                                  +827     * This returns a maximum of 0.9999999999999999 because that is the largest
                                                                                                                                                                                                                                                                                                                  +828     * Double value that is less than 1.0
                                                                                                                                                                                                                                                                                                                  +829     *
                                                                                                                                                                                                                                                                                                                  +830     * @return a value between 0 (inclusive) and 0.9999999999999999 (inclusive)
                                                                                                                                                                                                                                                                                                                  +831     */
                                                                                                                                                                                                                                                                                                                  +832    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  +833        return (random.nextLong() & 0x1fffffffffffffL) * DOUBLE_UNIT;
                                                                                                                                                                                                                                                                                                                  +834        // consider changing to this in a future version; it will break compatibility but should be fast/correct
                                                                                                                                                                                                                                                                                                                  +835        //return Double.longBitsToDouble(0x3FF0000000000000L | random.nextLong() >>> 12) - 1.0;
                                                                                                                                                                                                                                                                                                                  +836    }
                                                                                                                                                                                                                                                                                                                  +837
                                                                                                                                                                                                                                                                                                                  +838    /**
                                                                                                                                                                                                                                                                                                                  +839     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +840     *
                                                                                                                                                                                                                                                                                                                  +841     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  +842     */
                                                                                                                                                                                                                                                                                                                  +843    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  +844        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  +845    }
                                                                                                                                                                                                                                                                                                                  +846
                                                                                                                                                                                                                                                                                                                  +847    /**
                                                                                                                                                                                                                                                                                                                  +848     * This returns a maximum of 0.99999994 because that is the largest Float
                                                                                                                                                                                                                                                                                                                  +849     * value that is less than 1.0f
                                                                                                                                                                                                                                                                                                                  +850     *
                                                                                                                                                                                                                                                                                                                  +851     * @return a value between 0 (inclusive) and 0.99999994 (inclusive)
                                                                                                                                                                                                                                                                                                                  +852     */
                                                                                                                                                                                                                                                                                                                  +853    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  +854        return next(24) * FLOAT_UNIT;
                                                                                                                                                                                                                                                                                                                  +855    }
                                                                                                                                                                                                                                                                                                                  +856
                                                                                                                                                                                                                                                                                                                  +857    /**
                                                                                                                                                                                                                                                                                                                  +858     * Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                                                                                                                                                                                  +859     *
                                                                                                                                                                                                                                                                                                                  +860     * @return a random boolean.
                                                                                                                                                                                                                                                                                                                  +861     */
                                                                                                                                                                                                                                                                                                                  +862    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  +863        return nextLong() < 0L;
                                                                                                                                                                                                                                                                                                                  +864    }
                                                                                                                                                                                                                                                                                                                  +865
                                                                                                                                                                                                                                                                                                                  +866    /**
                                                                                                                                                                                                                                                                                                                  +867     * Get a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  +868     *
                                                                                                                                                                                                                                                                                                                  +869     * @return a 64-bit random long.
                                                                                                                                                                                                                                                                                                                  +870     */
                                                                                                                                                                                                                                                                                                                  +871    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  +872        return random.nextLong();
                                                                                                                                                                                                                                                                                                                  +873    }
                                                                                                                                                                                                                                                                                                                  +874
                                                                                                                                                                                                                                                                                                                  +875    /**
                                                                                                                                                                                                                                                                                                                  +876     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +877     * negative.
                                                                                                                                                                                                                                                                                                                  +878     *
                                                                                                                                                                                                                                                                                                                  +879     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +880     * @return the found number
                                                                                                                                                                                                                                                                                                                  +881     */
                                                                                                                                                                                                                                                                                                                  +882    public long nextLong(final long bound) {
                                                                                                                                                                                                                                                                                                                  +883        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  +884        long threshold = (0x7fffffffffffffffL - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  +885        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  +886            long bits = random.nextLong() & 0x7fffffffffffffffL;
                                                                                                                                                                                                                                                                                                                  +887            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  +888                return bits % bound;
                                                                                                                                                                                                                                                                                                                  +889        }
                                                                                                                                                                                                                                                                                                                  +890    }
                                                                                                                                                                                                                                                                                                                  +891
                                                                                                                                                                                                                                                                                                                  +892    /**
                                                                                                                                                                                                                                                                                                                  +893     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +894     * negative.
                                                                                                                                                                                                                                                                                                                  +895     *
                                                                                                                                                                                                                                                                                                                  +896     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +897     * @return the found number
                                                                                                                                                                                                                                                                                                                  +898     */
                                                                                                                                                                                                                                                                                                                  +899    public int nextInt(final int bound) {
                                                                                                                                                                                                                                                                                                                  +900        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  +901        int threshold = (0x7fffffff - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  +902        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  +903            int bits = random.next(31);
                                                                                                                                                                                                                                                                                                                  +904            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  +905                return bits % bound;
                                                                                                                                                                                                                                                                                                                  +906        }
                                                                                                                                                                                                                                                                                                                  +907    }
                                                                                                                                                                                                                                                                                                                  +908
                                                                                                                                                                                                                                                                                                                  +909    /**
                                                                                                                                                                                                                                                                                                                  +910     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  +911     * Uses an aggressively optimized technique that has some bias, but mostly for values of
                                                                                                                                                                                                                                                                                                                  +912     * bound over 1 billion. This method is considered "hasty" since it should be faster than
                                                                                                                                                                                                                                                                                                                  +913     * nextInt() but gives up some statistical quality to do so. It also has undefined behavior
                                                                                                                                                                                                                                                                                                                  +914     * if bound is negative, though it will probably produce a negative number (just how
                                                                                                                                                                                                                                                                                                                  +915     * negative is an open question).
                                                                                                                                                                                                                                                                                                                  +916     * <br>
                                                                                                                                                                                                                                                                                                                  +917     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  +918     *
                                                                                                                                                                                                                                                                                                                  +919     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  +920     * @return the found number
                                                                                                                                                                                                                                                                                                                  +921     */
                                                                                                                                                                                                                                                                                                                  +922    public int nextIntHasty(final int bound) {
                                                                                                                                                                                                                                                                                                                  +923        return (int) ((bound * (random.nextLong() & 0x7FFFFFFFL)) >> 31);
                                                                                                                                                                                                                                                                                                                  +924    }
                                                                                                                                                                                                                                                                                                                  +925
                                                                                                                                                                                                                                                                                                                  +926    /**
                                                                                                                                                                                                                                                                                                                  +927     * Generates random bytes and places them into the given byte array, modifying it in-place.
                                                                                                                                                                                                                                                                                                                  +928     * The number of random bytes produced is equal to the length of the byte array. Unlike the
                                                                                                                                                                                                                                                                                                                  +929     * method in java.util.Random, this generates 8 bytes at a time, which can be more efficient
                                                                                                                                                                                                                                                                                                                  +930     * with many RandomnessSource types than the JDK's method that generates 4 bytes at a time.
                                                                                                                                                                                                                                                                                                                   931     * <br>
                                                                                                                                                                                                                                                                                                                  -932     * @param  bytes the byte array to fill with random bytes; cannot be null, will be modified
                                                                                                                                                                                                                                                                                                                  -933     * @throws NullPointerException if the byte array is null
                                                                                                                                                                                                                                                                                                                  -934     */
                                                                                                                                                                                                                                                                                                                  -935    public void nextBytes(final byte[] bytes) {
                                                                                                                                                                                                                                                                                                                  -936        for (int i = 0; i < bytes.length; )
                                                                                                                                                                                                                                                                                                                  -937            for (long r = random.nextLong(), n = Math.min(bytes.length - i, 8); n-- > 0; r >>>= 8)
                                                                                                                                                                                                                                                                                                                  -938                bytes[i++] = (byte) r;
                                                                                                                                                                                                                                                                                                                  -939    }
                                                                                                                                                                                                                                                                                                                  -940    /**
                                                                                                                                                                                                                                                                                                                  -941     * Gets a random Coord that has x between 0 (inclusive) and width (exclusive) and y between 0 (inclusive)
                                                                                                                                                                                                                                                                                                                  -942     * and height (exclusive). This makes one call to randomLong to generate (more than) 31 random bits for
                                                                                                                                                                                                                                                                                                                  -943     * each axis, and should be very fast. Remember that Coord values are cached in a pool that starts able to
                                                                                                                                                                                                                                                                                                                  -944     * hold up to 255 x and 255 y for positive values, and the pool should be grown with the static method
                                                                                                                                                                                                                                                                                                                  -945     * Coord.expandPool() in order to efficiently use larger Coord values. If width and height are very large,
                                                                                                                                                                                                                                                                                                                  -946     * greater than 100,000 for either, this particular method may show bias toward certain positions due to
                                                                                                                                                                                                                                                                                                                  -947     * the "hasty" technique used to reduce the random numbers to the given size, but because most maps in
                                                                                                                                                                                                                                                                                                                  -948     * tile-based games are relatively small, this technique should be fine.
                                                                                                                                                                                                                                                                                                                  -949     * <br>
                                                                                                                                                                                                                                                                                                                  -950     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  -951     *
                                                                                                                                                                                                                                                                                                                  -952     * @param width  the upper bound (exclusive) for x coordinates
                                                                                                                                                                                                                                                                                                                  -953     * @param height the upper bound (exclusive) for y coordinates
                                                                                                                                                                                                                                                                                                                  -954     * @return a random Coord between (0,0) inclusive and (width,height) exclusive
                                                                                                                                                                                                                                                                                                                  -955     */
                                                                                                                                                                                                                                                                                                                  -956    public Coord nextCoord(int width, int height) {
                                                                                                                                                                                                                                                                                                                  -957        final long n = random.nextLong();
                                                                                                                                                                                                                                                                                                                  -958        return Coord.get((int) ((width * (n >>> 33)) >> 31), (int) ((height * (n & 0x7FFFFFFFL)) >> 31));
                                                                                                                                                                                                                                                                                                                  -959    }
                                                                                                                                                                                                                                                                                                                  -960
                                                                                                                                                                                                                                                                                                                  -961    /**
                                                                                                                                                                                                                                                                                                                  -962     * Get a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  -963     *
                                                                                                                                                                                                                                                                                                                  -964     * @return a 32-bit random int.
                                                                                                                                                                                                                                                                                                                  -965     */
                                                                                                                                                                                                                                                                                                                  -966    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  -967        return next(32);
                                                                                                                                                                                                                                                                                                                  -968    }
                                                                                                                                                                                                                                                                                                                  -969
                                                                                                                                                                                                                                                                                                                  -970    /**
                                                                                                                                                                                                                                                                                                                  -971     * Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -972     *
                                                                                                                                                                                                                                                                                                                  -973     * @param bits 1 to 32
                                                                                                                                                                                                                                                                                                                  -974     * @return a random number that fits in the specified number of bits.
                                                                                                                                                                                                                                                                                                                  -975     */
                                                                                                                                                                                                                                                                                                                  -976    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  -977        return random.next(bits);
                                                                                                                                                                                                                                                                                                                  -978    }
                                                                                                                                                                                                                                                                                                                  -979
                                                                                                                                                                                                                                                                                                                  -980    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  -981        return random;
                                                                                                                                                                                                                                                                                                                  -982    }
                                                                                                                                                                                                                                                                                                                  -983
                                                                                                                                                                                                                                                                                                                  -984    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -985        this.random = random;
                                                                                                                                                                                                                                                                                                                  -986    }
                                                                                                                                                                                                                                                                                                                  -987
                                                                                                                                                                                                                                                                                                                  -988    /**
                                                                                                                                                                                                                                                                                                                  -989     * Creates a copy of this RNG; it will generate the same random numbers, given the same calls in order, as this RNG
                                                                                                                                                                                                                                                                                                                  -990     * at the point copy() is called. The copy will not share references with this RNG.
                                                                                                                                                                                                                                                                                                                  -991     *
                                                                                                                                                                                                                                                                                                                  -992     * @return a copy of this RNG
                                                                                                                                                                                                                                                                                                                  -993     */
                                                                                                                                                                                                                                                                                                                  -994    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  -995        return new RNG(random.copy());
                                                                                                                                                                                                                                                                                                                  -996    }
                                                                                                                                                                                                                                                                                                                  -997
                                                                                                                                                                                                                                                                                                                  -998    /**
                                                                                                                                                                                                                                                                                                                  -999     * Generates a random 64-bit long with a number of '1' bits (Hamming weight) approximately equal to bitCount.
                                                                                                                                                                                                                                                                                                                  -1000     * For example, calling this with a parameter of 32 will be equivalent to calling nextLong() on this object's
                                                                                                                                                                                                                                                                                                                  -1001     * RandomnessSource (it doesn't consider overridden nextLong() methods, where present, on subclasses of RNG).
                                                                                                                                                                                                                                                                                                                  -1002     * Calling this with a parameter of 16 will have on average 16 of the 64 bits in the returned long set to '1',
                                                                                                                                                                                                                                                                                                                  -1003     * distributed pseudo-randomly, while a parameter of 47 will have on average 47 bits set. This can be useful for
                                                                                                                                                                                                                                                                                                                  -1004     * certain code that uses bits to represent data but needs a different ratio of set bits to unset bits than 1:1.
                                                                                                                                                                                                                                                                                                                  -1005     * <br>
                                                                                                                                                                                                                                                                                                                  -1006     * Implementors should limit any overriding method to calling and returning super(), potentially storing any extra
                                                                                                                                                                                                                                                                                                                  -1007     * information they need to internally, but should not change the result. This works based on a delicate balance of
                                                                                                                                                                                                                                                                                                                  -1008     * the RandomnessSource producing bits with an even 50% chance of being set, regardless of position, and RNG
                                                                                                                                                                                                                                                                                                                  -1009     * subclasses that alter the odds won't work as expected here, particularly if those subclasses use doubles
                                                                                                                                                                                                                                                                                                                  -1010     * internally (which almost always produce less than 64 random bits). You should definitely avoid using certain
                                                                                                                                                                                                                                                                                                                  -1011     * RandomnessSources that aren't properly pseudo-random, such as any QRNG class (SobolQRNG and VanDerCorputQRNG,
                                                                                                                                                                                                                                                                                                                  -1012     * pretty much), since these won't fill all 64 bits with equal likelihood.
                                                                                                                                                                                                                                                                                                                  -1013     *
                                                                                                                                                                                                                                                                                                                  -1014     * @param bitCount an int, only considered if between 0 and 64, that is the average number of bits to set
                                                                                                                                                                                                                                                                                                                  -1015     * @return a 64-bit long that, on average, should have bitCount bits set to 1, potentially anywhere in the long
                                                                                                                                                                                                                                                                                                                  -1016     */
                                                                                                                                                                                                                                                                                                                  -1017    public long approximateBits(int bitCount) {
                                                                                                                                                                                                                                                                                                                  -1018        if (bitCount <= 0)
                                                                                                                                                                                                                                                                                                                  -1019            return 0L;
                                                                                                                                                                                                                                                                                                                  -1020        if (bitCount >= 64)
                                                                                                                                                                                                                                                                                                                  -1021            return -1L;
                                                                                                                                                                                                                                                                                                                  -1022        if (bitCount == 32)
                                                                                                                                                                                                                                                                                                                  -1023            return random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1024        boolean high = bitCount > 32;
                                                                                                                                                                                                                                                                                                                  -1025        int altered = (high ? 64 - bitCount : bitCount), lsb = Integer.lowestOneBit(altered);
                                                                                                                                                                                                                                                                                                                  -1026        long data = random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1027        for (int i = lsb << 1; i <= 16; i <<= 1) {
                                                                                                                                                                                                                                                                                                                  -1028            if ((altered & i) == 0)
                                                                                                                                                                                                                                                                                                                  -1029                data &= random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1030            else
                                                                                                                                                                                                                                                                                                                  -1031                data |= random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1032        }
                                                                                                                                                                                                                                                                                                                  -1033        return high ? ~(random.nextLong() & data) : (random.nextLong() & data);
                                                                                                                                                                                                                                                                                                                  -1034    }
                                                                                                                                                                                                                                                                                                                  -1035
                                                                                                                                                                                                                                                                                                                  -1036    /**
                                                                                                                                                                                                                                                                                                                  -1037     * Gets a somewhat-random long with exactly 32 bits set; in each pair of bits starting at bit 0 and bit 1, then bit
                                                                                                                                                                                                                                                                                                                  -1038     * 2 and bit 3, up to bit 62 and bit 3, one bit will be 1 and one bit will be 0 in each pair.
                                                                                                                                                                                                                                                                                                                  -1039     *
                                                                                                                                                                                                                                                                                                                  -1040     * @return a random long with 32 "1" bits, distributed so exactly one bit is "1" for each pair of bits
                                                                                                                                                                                                                                                                                                                  -1041     */
                                                                                                                                                                                                                                                                                                                  -1042    public long randomInterleave() {
                                                                                                                                                                                                                                                                                                                  -1043        long bits = nextLong() & 0xFFFFFFFFL, ib = ~bits & 0xFFFFFFFFL;
                                                                                                                                                                                                                                                                                                                  -1044        bits |= (bits << 16);
                                                                                                                                                                                                                                                                                                                  -1045        ib |= (ib << 16);
                                                                                                                                                                                                                                                                                                                  -1046        bits &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  -1047        ib &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  -1048        bits |= (bits << 8);
                                                                                                                                                                                                                                                                                                                  -1049        ib |= (ib << 8);
                                                                                                                                                                                                                                                                                                                  -1050        bits &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  -1051        ib &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  -1052        bits |= (bits << 4);
                                                                                                                                                                                                                                                                                                                  -1053        ib |= (ib << 4);
                                                                                                                                                                                                                                                                                                                  -1054        bits &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  -1055        ib &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  -1056        bits |= (bits << 2);
                                                                                                                                                                                                                                                                                                                  -1057        ib |= (ib << 2);
                                                                                                                                                                                                                                                                                                                  -1058        bits &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  -1059        ib &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  -1060        bits |= (bits << 1);
                                                                                                                                                                                                                                                                                                                  -1061        ib |= (ib << 1);
                                                                                                                                                                                                                                                                                                                  -1062        bits &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  -1063        ib &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  -1064        return (bits | (ib << 1));
                                                                                                                                                                                                                                                                                                                  -1065    }
                                                                                                                                                                                                                                                                                                                  -1066
                                                                                                                                                                                                                                                                                                                  -1067    @Override
                                                                                                                                                                                                                                                                                                                  -1068    public String toString() {
                                                                                                                                                                                                                                                                                                                  -1069        return "RNG with Randomness Source " + random;
                                                                                                                                                                                                                                                                                                                  -1070    }
                                                                                                                                                                                                                                                                                                                  -1071
                                                                                                                                                                                                                                                                                                                  -1072    @Override
                                                                                                                                                                                                                                                                                                                  -1073    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  -1074        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  -1075        if (!(o instanceof RNG)) return false;
                                                                                                                                                                                                                                                                                                                  -1076
                                                                                                                                                                                                                                                                                                                  -1077        RNG rng = (RNG) o;
                                                                                                                                                                                                                                                                                                                  +932     * Adapted from code in the JavaDocs of {@link Random#nextBytes(byte[])}.
                                                                                                                                                                                                                                                                                                                  +933     * <br>
                                                                                                                                                                                                                                                                                                                  +934     * @param  bytes the byte array to fill with random bytes; cannot be null, will be modified
                                                                                                                                                                                                                                                                                                                  +935     * @throws NullPointerException if the byte array is null
                                                                                                                                                                                                                                                                                                                  +936     */
                                                                                                                                                                                                                                                                                                                  +937    public void nextBytes(final byte[] bytes) {
                                                                                                                                                                                                                                                                                                                  +938        for (int i = 0; i < bytes.length; )
                                                                                                                                                                                                                                                                                                                  +939            for (long r = random.nextLong(), n = Math.min(bytes.length - i, 8); n-- > 0; r >>>= 8)
                                                                                                                                                                                                                                                                                                                  +940                bytes[i++] = (byte) r;
                                                                                                                                                                                                                                                                                                                  +941    }
                                                                                                                                                                                                                                                                                                                  +942    /**
                                                                                                                                                                                                                                                                                                                  +943     * Gets a random Coord that has x between 0 (inclusive) and width (exclusive) and y between 0 (inclusive)
                                                                                                                                                                                                                                                                                                                  +944     * and height (exclusive). This makes one call to randomLong to generate (more than) 31 random bits for
                                                                                                                                                                                                                                                                                                                  +945     * each axis, and should be very fast. Remember that Coord values are cached in a pool that starts able to
                                                                                                                                                                                                                                                                                                                  +946     * hold up to 255 x and 255 y for positive values, and the pool should be grown with the static method
                                                                                                                                                                                                                                                                                                                  +947     * Coord.expandPool() in order to efficiently use larger Coord values. If width and height are very large,
                                                                                                                                                                                                                                                                                                                  +948     * greater than 100,000 for either, this particular method may show bias toward certain positions due to
                                                                                                                                                                                                                                                                                                                  +949     * the "hasty" technique used to reduce the random numbers to the given size, but because most maps in
                                                                                                                                                                                                                                                                                                                  +950     * tile-based games are relatively small, this technique should be fine.
                                                                                                                                                                                                                                                                                                                  +951     * <br>
                                                                                                                                                                                                                                                                                                                  +952     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  +953     *
                                                                                                                                                                                                                                                                                                                  +954     * @param width  the upper bound (exclusive) for x coordinates
                                                                                                                                                                                                                                                                                                                  +955     * @param height the upper bound (exclusive) for y coordinates
                                                                                                                                                                                                                                                                                                                  +956     * @return a random Coord between (0,0) inclusive and (width,height) exclusive
                                                                                                                                                                                                                                                                                                                  +957     */
                                                                                                                                                                                                                                                                                                                  +958    public Coord nextCoord(int width, int height) {
                                                                                                                                                                                                                                                                                                                  +959        final long n = random.nextLong();
                                                                                                                                                                                                                                                                                                                  +960        return Coord.get((int) ((width * (n >>> 33)) >> 31), (int) ((height * (n & 0x7FFFFFFFL)) >> 31));
                                                                                                                                                                                                                                                                                                                  +961    }
                                                                                                                                                                                                                                                                                                                  +962
                                                                                                                                                                                                                                                                                                                  +963    /**
                                                                                                                                                                                                                                                                                                                  +964     * Get a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  +965     *
                                                                                                                                                                                                                                                                                                                  +966     * @return a 32-bit random int.
                                                                                                                                                                                                                                                                                                                  +967     */
                                                                                                                                                                                                                                                                                                                  +968    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  +969        return next(32);
                                                                                                                                                                                                                                                                                                                  +970    }
                                                                                                                                                                                                                                                                                                                  +971
                                                                                                                                                                                                                                                                                                                  +972    /**
                                                                                                                                                                                                                                                                                                                  +973     * Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +974     *
                                                                                                                                                                                                                                                                                                                  +975     * @param bits 1 to 32
                                                                                                                                                                                                                                                                                                                  +976     * @return a random number that fits in the specified number of bits.
                                                                                                                                                                                                                                                                                                                  +977     */
                                                                                                                                                                                                                                                                                                                  +978    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  +979        return random.next(bits);
                                                                                                                                                                                                                                                                                                                  +980    }
                                                                                                                                                                                                                                                                                                                  +981
                                                                                                                                                                                                                                                                                                                  +982    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  +983        return random;
                                                                                                                                                                                                                                                                                                                  +984    }
                                                                                                                                                                                                                                                                                                                  +985
                                                                                                                                                                                                                                                                                                                  +986    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +987        this.random = random;
                                                                                                                                                                                                                                                                                                                  +988    }
                                                                                                                                                                                                                                                                                                                  +989
                                                                                                                                                                                                                                                                                                                  +990    /**
                                                                                                                                                                                                                                                                                                                  +991     * Creates a copy of this RNG; it will generate the same random numbers, given the same calls in order, as this RNG
                                                                                                                                                                                                                                                                                                                  +992     * at the point copy() is called. The copy will not share references with this RNG.
                                                                                                                                                                                                                                                                                                                  +993     *
                                                                                                                                                                                                                                                                                                                  +994     * @return a copy of this RNG
                                                                                                                                                                                                                                                                                                                  +995     */
                                                                                                                                                                                                                                                                                                                  +996    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  +997        return new RNG(random.copy());
                                                                                                                                                                                                                                                                                                                  +998    }
                                                                                                                                                                                                                                                                                                                  +999
                                                                                                                                                                                                                                                                                                                  +1000    /**
                                                                                                                                                                                                                                                                                                                  +1001     * Generates a random 64-bit long with a number of '1' bits (Hamming weight) approximately equal to bitCount.
                                                                                                                                                                                                                                                                                                                  +1002     * For example, calling this with a parameter of 32 will be equivalent to calling nextLong() on this object's
                                                                                                                                                                                                                                                                                                                  +1003     * RandomnessSource (it doesn't consider overridden nextLong() methods, where present, on subclasses of RNG).
                                                                                                                                                                                                                                                                                                                  +1004     * Calling this with a parameter of 16 will have on average 16 of the 64 bits in the returned long set to '1',
                                                                                                                                                                                                                                                                                                                  +1005     * distributed pseudo-randomly, while a parameter of 47 will have on average 47 bits set. This can be useful for
                                                                                                                                                                                                                                                                                                                  +1006     * certain code that uses bits to represent data but needs a different ratio of set bits to unset bits than 1:1.
                                                                                                                                                                                                                                                                                                                  +1007     * <br>
                                                                                                                                                                                                                                                                                                                  +1008     * Implementors should limit any overriding method to calling and returning super(), potentially storing any extra
                                                                                                                                                                                                                                                                                                                  +1009     * information they need to internally, but should not change the result. This works based on a delicate balance of
                                                                                                                                                                                                                                                                                                                  +1010     * the RandomnessSource producing bits with an even 50% chance of being set, regardless of position, and RNG
                                                                                                                                                                                                                                                                                                                  +1011     * subclasses that alter the odds won't work as expected here, particularly if those subclasses use doubles
                                                                                                                                                                                                                                                                                                                  +1012     * internally (which almost always produce less than 64 random bits). You should definitely avoid using certain
                                                                                                                                                                                                                                                                                                                  +1013     * RandomnessSources that aren't properly pseudo-random, such as any QRNG class (SobolQRNG and VanDerCorputQRNG,
                                                                                                                                                                                                                                                                                                                  +1014     * pretty much), since these won't fill all 64 bits with equal likelihood.
                                                                                                                                                                                                                                                                                                                  +1015     *
                                                                                                                                                                                                                                                                                                                  +1016     * @param bitCount an int, only considered if between 0 and 64, that is the average number of bits to set
                                                                                                                                                                                                                                                                                                                  +1017     * @return a 64-bit long that, on average, should have bitCount bits set to 1, potentially anywhere in the long
                                                                                                                                                                                                                                                                                                                  +1018     */
                                                                                                                                                                                                                                                                                                                  +1019    public long approximateBits(int bitCount) {
                                                                                                                                                                                                                                                                                                                  +1020        if (bitCount <= 0)
                                                                                                                                                                                                                                                                                                                  +1021            return 0L;
                                                                                                                                                                                                                                                                                                                  +1022        if (bitCount >= 64)
                                                                                                                                                                                                                                                                                                                  +1023            return -1L;
                                                                                                                                                                                                                                                                                                                  +1024        if (bitCount == 32)
                                                                                                                                                                                                                                                                                                                  +1025            return random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1026        boolean high = bitCount > 32;
                                                                                                                                                                                                                                                                                                                  +1027        int altered = (high ? 64 - bitCount : bitCount), lsb = Integer.lowestOneBit(altered);
                                                                                                                                                                                                                                                                                                                  +1028        long data = random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1029        for (int i = lsb << 1; i <= 16; i <<= 1) {
                                                                                                                                                                                                                                                                                                                  +1030            if ((altered & i) == 0)
                                                                                                                                                                                                                                                                                                                  +1031                data &= random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1032            else
                                                                                                                                                                                                                                                                                                                  +1033                data |= random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1034        }
                                                                                                                                                                                                                                                                                                                  +1035        return high ? ~(random.nextLong() & data) : (random.nextLong() & data);
                                                                                                                                                                                                                                                                                                                  +1036    }
                                                                                                                                                                                                                                                                                                                  +1037
                                                                                                                                                                                                                                                                                                                  +1038    /**
                                                                                                                                                                                                                                                                                                                  +1039     * Gets a somewhat-random long with exactly 32 bits set; in each pair of bits starting at bit 0 and bit 1, then bit
                                                                                                                                                                                                                                                                                                                  +1040     * 2 and bit 3, up to bit 62 and bit 3, one bit will be 1 and one bit will be 0 in each pair.
                                                                                                                                                                                                                                                                                                                  +1041     *
                                                                                                                                                                                                                                                                                                                  +1042     * @return a random long with 32 "1" bits, distributed so exactly one bit is "1" for each pair of bits
                                                                                                                                                                                                                                                                                                                  +1043     */
                                                                                                                                                                                                                                                                                                                  +1044    public long randomInterleave() {
                                                                                                                                                                                                                                                                                                                  +1045        long bits = nextLong() & 0xFFFFFFFFL, ib = ~bits & 0xFFFFFFFFL;
                                                                                                                                                                                                                                                                                                                  +1046        bits |= (bits << 16);
                                                                                                                                                                                                                                                                                                                  +1047        ib |= (ib << 16);
                                                                                                                                                                                                                                                                                                                  +1048        bits &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  +1049        ib &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  +1050        bits |= (bits << 8);
                                                                                                                                                                                                                                                                                                                  +1051        ib |= (ib << 8);
                                                                                                                                                                                                                                                                                                                  +1052        bits &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  +1053        ib &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  +1054        bits |= (bits << 4);
                                                                                                                                                                                                                                                                                                                  +1055        ib |= (ib << 4);
                                                                                                                                                                                                                                                                                                                  +1056        bits &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  +1057        ib &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  +1058        bits |= (bits << 2);
                                                                                                                                                                                                                                                                                                                  +1059        ib |= (ib << 2);
                                                                                                                                                                                                                                                                                                                  +1060        bits &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  +1061        ib &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  +1062        bits |= (bits << 1);
                                                                                                                                                                                                                                                                                                                  +1063        ib |= (ib << 1);
                                                                                                                                                                                                                                                                                                                  +1064        bits &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  +1065        ib &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  +1066        return (bits | (ib << 1));
                                                                                                                                                                                                                                                                                                                  +1067    }
                                                                                                                                                                                                                                                                                                                  +1068
                                                                                                                                                                                                                                                                                                                  +1069    @Override
                                                                                                                                                                                                                                                                                                                  +1070    public String toString() {
                                                                                                                                                                                                                                                                                                                  +1071        return "RNG with Randomness Source " + random;
                                                                                                                                                                                                                                                                                                                  +1072    }
                                                                                                                                                                                                                                                                                                                  +1073
                                                                                                                                                                                                                                                                                                                  +1074    @Override
                                                                                                                                                                                                                                                                                                                  +1075    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  +1076        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  +1077        if (!(o instanceof RNG)) return false;
                                                                                                                                                                                                                                                                                                                   1078
                                                                                                                                                                                                                                                                                                                  -1079        return random.equals(rng.random);
                                                                                                                                                                                                                                                                                                                  -1080    }
                                                                                                                                                                                                                                                                                                                  -1081
                                                                                                                                                                                                                                                                                                                  -1082    @Override
                                                                                                                                                                                                                                                                                                                  -1083    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  -1084        return random.hashCode();
                                                                                                                                                                                                                                                                                                                  -1085    }
                                                                                                                                                                                                                                                                                                                  -1086}
                                                                                                                                                                                                                                                                                                                  +1079        RNG rng = (RNG) o;
                                                                                                                                                                                                                                                                                                                  +1080
                                                                                                                                                                                                                                                                                                                  +1081        return random.equals(rng.random);
                                                                                                                                                                                                                                                                                                                  +1082    }
                                                                                                                                                                                                                                                                                                                  +1083
                                                                                                                                                                                                                                                                                                                  +1084    @Override
                                                                                                                                                                                                                                                                                                                  +1085    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  +1086        return random.hashCode();
                                                                                                                                                                                                                                                                                                                  +1087    }
                                                                                                                                                                                                                                                                                                                  +1088}
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/RNG.html b/docs/squidlib-util/src-html/squidpony/squidmath/RNG.html
                                                                                                                                                                                                                                                                                                                  index 41bcbe3455..3e2b7daded 100644
                                                                                                                                                                                                                                                                                                                  --- a/docs/squidlib-util/src-html/squidpony/squidmath/RNG.html
                                                                                                                                                                                                                                                                                                                  +++ b/docs/squidlib-util/src-html/squidpony/squidmath/RNG.html
                                                                                                                                                                                                                                                                                                                  @@ -9,1089 +9,1091 @@
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  001package squidpony.squidmath;
                                                                                                                                                                                                                                                                                                                   002
                                                                                                                                                                                                                                                                                                                   003import squidpony.ArrayTools;
                                                                                                                                                                                                                                                                                                                  -004import squidpony.annotation.GwtIncompatible;
                                                                                                                                                                                                                                                                                                                  -005
                                                                                                                                                                                                                                                                                                                  -006import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  -007import java.util.*;
                                                                                                                                                                                                                                                                                                                  -008
                                                                                                                                                                                                                                                                                                                  -009/**
                                                                                                                                                                                                                                                                                                                  -010 * A wrapper class for working with random number generators in a more friendly way.
                                                                                                                                                                                                                                                                                                                  -011 * <p>
                                                                                                                                                                                                                                                                                                                  -012 * Includes methods for getting values between two numbers and for getting
                                                                                                                                                                                                                                                                                                                  -013 * random elements from a collection or array. There are methods to shuffle
                                                                                                                                                                                                                                                                                                                  -014 * a collection and to get a random ordering that can be applied as one shuffle
                                                                                                                                                                                                                                                                                                                  -015 * across multiple collections, such as via {@link OrderedMap#reorder(int...)},
                                                                                                                                                                                                                                                                                                                  -016 * {@link ArrayTools#reorder(ArrayList, int...)}, and so on. You can construct
                                                                                                                                                                                                                                                                                                                  -017 * an RNG with all sorts of RandomnessSource implementations, and choosing them
                                                                                                                                                                                                                                                                                                                  -018 * is usually not a big concern because the default works very well.
                                                                                                                                                                                                                                                                                                                  -019 * <br>
                                                                                                                                                                                                                                                                                                                  -020 * But if you do want advice on what RandomnessSource to use... {@link LightRNG}
                                                                                                                                                                                                                                                                                                                  -021 * is the default, and is very fast, but relative to many of the others it has a
                                                                                                                                                                                                                                                                                                                  -022 * significantly shorter period (the amount of random  numbers it will go through
                                                                                                                                                                                                                                                                                                                  -023 * before repeating the sequence), at {@code pow(2, 64)} as opposed to
                                                                                                                                                                                                                                                                                                                  -024 * {@link XoRoRNG}'s {@code pow(2, 128) - 1}, . {@link LapRNG} is about twice as
                                                                                                                                                                                                                                                                                                                  -025 * fast as LightRNG, but that's all it's good at; it fails quality tests almost
                                                                                                                                                                                                                                                                                                                  -026 * all around, though it can fool a human observer, and has a period that's only
                                                                                                                                                                                                                                                                                                                  -027 * barely better than LightRNG at {@code pow(2, 65)}. LightRNG also allows the
                                                                                                                                                                                                                                                                                                                  -028 * current RNG state to be retrieved and altered with {@code getState()} and
                                                                                                                                                                                                                                                                                                                  -029 * {@code setState()}, and the subclass of RNG, {@link StatefulRNG}, usually uses
                                                                                                                                                                                                                                                                                                                  -030 * LightRNG to handle random number generation when the state may need to be
                                                                                                                                                                                                                                                                                                                  -031 * saved and reloaded. For most cases, you should decide between LightRNG, XoRoRNG,
                                                                                                                                                                                                                                                                                                                  -032 * and LapRNG based on your priorities. LightRNG is the best if you want good
                                                                                                                                                                                                                                                                                                                  -033 * speed, good quality of randomness, and expect to either generate less than
                                                                                                                                                                                                                                                                                                                  -034 * 18446744073709551616 numbers or don't care if patterns appear after you generate
                                                                                                                                                                                                                                                                                                                  -035 * that many numbers, or if you need an RNG that can skip backwards or jump forwards
                                                                                                                                                                                                                                                                                                                  -036 * without incurring speed penalties. XoRoRNG is best if you want good speed and
                                                                                                                                                                                                                                                                                                                  -037 * quality but need to generate more than 18446744073709551616 numbers, though less
                                                                                                                                                                                                                                                                                                                  -038 * than 340282366920938463463374607431768211456 numbers. LapRNG is best if you only
                                                                                                                                                                                                                                                                                                                  -039 * care about getting random numbers quickly, and don't expect their quality to be
                                                                                                                                                                                                                                                                                                                  -040 * scrutinized; it can generate 36893488147419103232 numbers before the entire cycle
                                                                                                                                                                                                                                                                                                                  -041 * repeats, but patterns can easily appear before that.
                                                                                                                                                                                                                                                                                                                  -042 * <br>
                                                                                                                                                                                                                                                                                                                  -043 * There are many more RandomnessSource implementations! If XoRoRNG's tremendous
                                                                                                                                                                                                                                                                                                                  -044 * period is not enough, then we also supply {@link LongPeriodRNG}, which has a
                                                                                                                                                                                                                                                                                                                  -045 * period of {@code pow(2, 1024) - 1}, and {@link BeardRNG}, which has an unknown
                                                                                                                                                                                                                                                                                                                  -046 * exact period but is likely to be very large, since it has 4 times as much state
                                                                                                                                                                                                                                                                                                                  -047 * as LongPeriodRNG and so could have at most a period of {@code pow(2, 4096)}.
                                                                                                                                                                                                                                                                                                                  -048 * You might want significantly less predictable random results, which
                                                                                                                                                                                                                                                                                                                  -049 * {@link IsaacRNG} can provide, along with a large period. The quality of
                                                                                                                                                                                                                                                                                                                  -050 * {@link PermutedRNG} is also good, usually, and it has a sound basis in PCG-Random,
                                                                                                                                                                                                                                                                                                                  -051 * an involved library with many variants on its RNGs. There may be reasons why
                                                                                                                                                                                                                                                                                                                  -052 * you would want a random number generator that uses 32-bit math instead of the
                                                                                                                                                                                                                                                                                                                  -053 * more common 64-bit math, but using a 32-bit int on desktop and Android won't act
                                                                                                                                                                                                                                                                                                                  -054 * the same as that same 32-bit int on GWT. Since GWT is stuck with JavaScript's
                                                                                                                                                                                                                                                                                                                  -055 * annoying implementation of ints with doubles, overflow (which is needed for an
                                                                                                                                                                                                                                                                                                                  -056 * RNG) doesn't work at all with ints, but does with GWT's implementation of longs.
                                                                                                                                                                                                                                                                                                                  -057 * 32-bit math generators were a major part of SquidLib's development at one point
                                                                                                                                                                                                                                                                                                                  -058 * before the discrepancies between desktop and GWT were discovered; they include
                                                                                                                                                                                                                                                                                                                  -059 * {@link Light32RNG} (same algorithm as LightRNG, shrunk down to use ints),
                                                                                                                                                                                                                                                                                                                  -060 * {@link BardRNG} (a huge-period RNG like BeardRNG), {@link Isaac32RNG} (32-bit
                                                                                                                                                                                                                                                                                                                  -061 * variant on IsaacRNG), {@link PintRNG} (based on PermutedRNG, using PCG-Random),
                                                                                                                                                                                                                                                                                                                  -062 * and {@link FlapRNG} (like Lap, only good for speed). Now, any code that targets
                                                                                                                                                                                                                                                                                                                  -063 * non-GWT platforms is free to use them, though they are often slower when they
                                                                                                                                                                                                                                                                                                                  -064 * need to generate longs (which is often), but they should not be used in code
                                                                                                                                                                                                                                                                                                                  -065 * that targets GWT.
                                                                                                                                                                                                                                                                                                                  -066 * @author Eben Howard - http://squidpony.com - howard@squidpony.com
                                                                                                                                                                                                                                                                                                                  -067 * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  -068 * @author smelC
                                                                                                                                                                                                                                                                                                                  -069 */
                                                                                                                                                                                                                                                                                                                  -070public class RNG implements Serializable {
                                                                                                                                                                                                                                                                                                                  -071
                                                                                                                                                                                                                                                                                                                  -072    /**
                                                                                                                                                                                                                                                                                                                  -073     * A very small multiplier used to reduce random numbers to from the {@code [0.0,9007199254740991.0)} range to the
                                                                                                                                                                                                                                                                                                                  -074     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0 / (1 << 53)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  -075     * source uses the hexadecimal double literal {@code 0x1p-53}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  -076     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  -077     */
                                                                                                                                                                                                                                                                                                                  -078        protected static final double DOUBLE_UNIT = 0x1p-53; // more people should know about hex double literals!
                                                                                                                                                                                                                                                                                                                  -079    /**
                                                                                                                                                                                                                                                                                                                  -080     * A very small multiplier used to reduce random numbers to from the {@code [0.0,16777216.0)} range to the
                                                                                                                                                                                                                                                                                                                  -081     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0f / (1 << 24)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  -082     * source uses the hexadecimal double literal {@code 0x1p-24f}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  -083     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  -084     */
                                                                                                                                                                                                                                                                                                                  -085        protected static final float FLOAT_UNIT = 0x1p-24f;
                                                                                                                                                                                                                                                                                                                  -086        protected RandomnessSource random;
                                                                                                                                                                                                                                                                                                                  -087        protected double nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  -088        protected boolean haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  -089        protected Random ran = null;
                                                                                                                                                                                                                                                                                                                  -090
                                                                                                                                                                                                                                                                                                                  -091    private static final long serialVersionUID = 2352426757973945149L;
                                                                                                                                                                                                                                                                                                                  +004
                                                                                                                                                                                                                                                                                                                  +005import java.io.Serializable;
                                                                                                                                                                                                                                                                                                                  +006import java.util.*;
                                                                                                                                                                                                                                                                                                                  +007
                                                                                                                                                                                                                                                                                                                  +008/**
                                                                                                                                                                                                                                                                                                                  +009 * A wrapper class for working with random number generators in a more friendly way.
                                                                                                                                                                                                                                                                                                                  +010 * <p>
                                                                                                                                                                                                                                                                                                                  +011 * Includes methods for getting values between two numbers and for getting
                                                                                                                                                                                                                                                                                                                  +012 * random elements from a collection or array. There are methods to shuffle
                                                                                                                                                                                                                                                                                                                  +013 * a collection and to get a random ordering that can be applied as one shuffle
                                                                                                                                                                                                                                                                                                                  +014 * across multiple collections, such as via {@link OrderedMap#reorder(int...)},
                                                                                                                                                                                                                                                                                                                  +015 * {@link ArrayTools#reorder(ArrayList, int...)}, and so on. You can construct
                                                                                                                                                                                                                                                                                                                  +016 * an RNG with all sorts of RandomnessSource implementations, and choosing them
                                                                                                                                                                                                                                                                                                                  +017 * is usually not a big concern because the default works very well.
                                                                                                                                                                                                                                                                                                                  +018 * <br>
                                                                                                                                                                                                                                                                                                                  +019 * But if you do want advice on what RandomnessSource to use... {@link LightRNG}
                                                                                                                                                                                                                                                                                                                  +020 * is the default, and is very fast, but relative to many of the others it has a
                                                                                                                                                                                                                                                                                                                  +021 * significantly shorter period (the amount of random  numbers it will go through
                                                                                                                                                                                                                                                                                                                  +022 * before repeating the sequence), at {@code pow(2, 64)} as opposed to
                                                                                                                                                                                                                                                                                                                  +023 * {@link XoRoRNG}'s {@code pow(2, 128) - 1}, . {@link LapRNG} is about twice as
                                                                                                                                                                                                                                                                                                                  +024 * fast as LightRNG, but that's all it's good at; it fails quality tests almost
                                                                                                                                                                                                                                                                                                                  +025 * all around, though it can fool a human observer, and has a period that's only
                                                                                                                                                                                                                                                                                                                  +026 * barely better than LightRNG at {@code pow(2, 65)}. LightRNG also allows the
                                                                                                                                                                                                                                                                                                                  +027 * current RNG state to be retrieved and altered with {@code getState()} and
                                                                                                                                                                                                                                                                                                                  +028 * {@code setState()}, and the subclass of RNG, {@link StatefulRNG}, usually uses
                                                                                                                                                                                                                                                                                                                  +029 * LightRNG to handle random number generation when the state may need to be
                                                                                                                                                                                                                                                                                                                  +030 * saved and reloaded. For most cases, you should decide between LightRNG, XoRoRNG,
                                                                                                                                                                                                                                                                                                                  +031 * and LapRNG based on your priorities. LightRNG is the best if you want good
                                                                                                                                                                                                                                                                                                                  +032 * speed, good quality of randomness, and expect to either generate less than
                                                                                                                                                                                                                                                                                                                  +033 * 18446744073709551616 numbers or don't care if patterns appear after you generate
                                                                                                                                                                                                                                                                                                                  +034 * that many numbers, or if you need an RNG that can skip backwards or jump forwards
                                                                                                                                                                                                                                                                                                                  +035 * without incurring speed penalties. XoRoRNG is best if you want good speed and
                                                                                                                                                                                                                                                                                                                  +036 * quality but need to generate more than 18446744073709551616 numbers, though less
                                                                                                                                                                                                                                                                                                                  +037 * than 340282366920938463463374607431768211456 numbers. LapRNG is best if you only
                                                                                                                                                                                                                                                                                                                  +038 * care about getting random numbers quickly, and don't expect their quality to be
                                                                                                                                                                                                                                                                                                                  +039 * scrutinized; it can generate 36893488147419103232 numbers before the entire cycle
                                                                                                                                                                                                                                                                                                                  +040 * repeats, but patterns can easily appear before that.
                                                                                                                                                                                                                                                                                                                  +041 * <br>
                                                                                                                                                                                                                                                                                                                  +042 * There are many more RandomnessSource implementations! If XoRoRNG's tremendous
                                                                                                                                                                                                                                                                                                                  +043 * period is not enough, then we also supply {@link LongPeriodRNG}, which has a
                                                                                                                                                                                                                                                                                                                  +044 * period of {@code pow(2, 1024) - 1}, and {@link BeardRNG}, which has an unknown
                                                                                                                                                                                                                                                                                                                  +045 * exact period but is likely to be very large, since it has 4 times as much state
                                                                                                                                                                                                                                                                                                                  +046 * as LongPeriodRNG and so could have at most a period of {@code pow(2, 4096)}.
                                                                                                                                                                                                                                                                                                                  +047 * You might want significantly less predictable random results, which
                                                                                                                                                                                                                                                                                                                  +048 * {@link IsaacRNG} can provide, along with a large period. The quality of
                                                                                                                                                                                                                                                                                                                  +049 * {@link PermutedRNG} is also good, usually, and it has a sound basis in PCG-Random,
                                                                                                                                                                                                                                                                                                                  +050 * an involved library with many variants on its RNGs. There may be reasons why
                                                                                                                                                                                                                                                                                                                  +051 * you would want a random number generator that uses 32-bit math instead of the
                                                                                                                                                                                                                                                                                                                  +052 * more common 64-bit math, but using a 32-bit int on desktop and Android won't act
                                                                                                                                                                                                                                                                                                                  +053 * the same as that same 32-bit int on GWT. Since GWT is stuck with JavaScript's
                                                                                                                                                                                                                                                                                                                  +054 * annoying implementation of ints with doubles, overflow (which is needed for an
                                                                                                                                                                                                                                                                                                                  +055 * RNG) doesn't work at all with ints, but does with GWT's implementation of longs.
                                                                                                                                                                                                                                                                                                                  +056 * 32-bit math generators were a major part of SquidLib's development at one point
                                                                                                                                                                                                                                                                                                                  +057 * before the discrepancies between desktop and GWT were discovered; they include
                                                                                                                                                                                                                                                                                                                  +058 * {@link Light32RNG} (same algorithm as LightRNG, shrunk down to use ints),
                                                                                                                                                                                                                                                                                                                  +059 * {@link BardRNG} (a huge-period RNG like BeardRNG), {@link Isaac32RNG} (32-bit
                                                                                                                                                                                                                                                                                                                  +060 * variant on IsaacRNG), {@link PintRNG} (based on PermutedRNG, using PCG-Random),
                                                                                                                                                                                                                                                                                                                  +061 * and {@link FlapRNG} (like Lap, only good for speed). Now, any code that targets
                                                                                                                                                                                                                                                                                                                  +062 * non-GWT platforms is free to use them, though they are often slower when they
                                                                                                                                                                                                                                                                                                                  +063 * need to generate longs (which is often), but they should not be used in code
                                                                                                                                                                                                                                                                                                                  +064 * that targets GWT.
                                                                                                                                                                                                                                                                                                                  +065 * @author Eben Howard - http://squidpony.com - howard@squidpony.com
                                                                                                                                                                                                                                                                                                                  +066 * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  +067 * @author smelC
                                                                                                                                                                                                                                                                                                                  +068 */
                                                                                                                                                                                                                                                                                                                  +069public class RNG implements Serializable {
                                                                                                                                                                                                                                                                                                                  +070
                                                                                                                                                                                                                                                                                                                  +071    /**
                                                                                                                                                                                                                                                                                                                  +072     * A very small multiplier used to reduce random numbers to from the {@code [0.0,9007199254740991.0)} range to the
                                                                                                                                                                                                                                                                                                                  +073     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0 / (1 << 53)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  +074     * source uses the hexadecimal double literal {@code 0x1p-53}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  +075     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  +076     */
                                                                                                                                                                                                                                                                                                                  +077        protected static final double DOUBLE_UNIT = 0x1p-53; // more people should know about hex double literals!
                                                                                                                                                                                                                                                                                                                  +078    /**
                                                                                                                                                                                                                                                                                                                  +079     * A very small multiplier used to reduce random numbers to from the {@code [0.0,16777216.0)} range to the
                                                                                                                                                                                                                                                                                                                  +080     * {@code [0.0,1.0)} range. Equivalent to {@code 1.0f / (1 << 24)}, if that number makes more sense to you, but the
                                                                                                                                                                                                                                                                                                                  +081     * source uses the hexadecimal double literal {@code 0x1p-24f}. The hex literals are a nice "hidden feature" of Java
                                                                                                                                                                                                                                                                                                                  +082     * 5 onward, and allow exact declaration of floating-point numbers without precision loss from decimal conversion.
                                                                                                                                                                                                                                                                                                                  +083     */
                                                                                                                                                                                                                                                                                                                  +084        protected static final float FLOAT_UNIT = 0x1p-24f;
                                                                                                                                                                                                                                                                                                                  +085        protected RandomnessSource random;
                                                                                                                                                                                                                                                                                                                  +086        protected double nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  +087        protected boolean haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  +088        protected Random ran = null;
                                                                                                                                                                                                                                                                                                                  +089
                                                                                                                                                                                                                                                                                                                  +090    private static final long serialVersionUID = 2352426757973945149L;
                                                                                                                                                                                                                                                                                                                  +091
                                                                                                                                                                                                                                                                                                                   092
                                                                                                                                                                                                                                                                                                                  -093
                                                                                                                                                                                                                                                                                                                  -094    /**
                                                                                                                                                                                                                                                                                                                  -095     * Default constructor; uses SplitMix64, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  -096     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -097     * <br>
                                                                                                                                                                                                                                                                                                                  -098     * Compatibility note: previous versions of SquidLib used Mersenne Twister by default. Due to the incompatibility
                                                                                                                                                                                                                                                                                                                  -099     * of the threads used by this Mersenne Twister implementation with GWT and HTML5 applications, the randomness
                                                                                                                                                                                                                                                                                                                  -100     * algorithm has been changed to a faster, more compatible algorithm, though it does suffer from a much lower
                                                                                                                                                                                                                                                                                                                  -101     * period. If you need drastically larger periods than 2^64, you can pass a LongPeriodRNG (or MersenneTwister on
                                                                                                                                                                                                                                                                                                                  -102     * targets other than HTML) object to the constructor that takes a RandomnessSource. If you don't know what the
                                                                                                                                                                                                                                                                                                                  -103     * period of a PRNG is, you probably don't need to worry about it; it's mainly relevant to heavily multi-threaded
                                                                                                                                                                                                                                                                                                                  -104     * applications anyway. The addition of LongPeriodRNG on March 21, 2016 should help to take the part of a fast,
                                                                                                                                                                                                                                                                                                                  -105     * large-period RNG, which MersenneTwister is unable to act as on GWT. The default may change again some time after
                                                                                                                                                                                                                                                                                                                  -106     * May 1, 2016, now that we have XoRoRNG, which is approximately as fast as LightRNG and has a substantially better
                                                                                                                                                                                                                                                                                                                  -107     * period (pow(2, 128) - 1).
                                                                                                                                                                                                                                                                                                                  -108     */
                                                                                                                                                                                                                                                                                                                  -109    public RNG() {
                                                                                                                                                                                                                                                                                                                  -110        this(new LightRNG());
                                                                                                                                                                                                                                                                                                                  -111    }
                                                                                                                                                                                                                                                                                                                  -112
                                                                                                                                                                                                                                                                                                                  -113    /**
                                                                                                                                                                                                                                                                                                                  -114     * Seeded constructor; uses LightRNG, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  -115     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -116     */
                                                                                                                                                                                                                                                                                                                  -117    public RNG(long seed) {
                                                                                                                                                                                                                                                                                                                  -118        this(new LightRNG(seed));
                                                                                                                                                                                                                                                                                                                  -119    }
                                                                                                                                                                                                                                                                                                                  -120
                                                                                                                                                                                                                                                                                                                  -121    /**
                                                                                                                                                                                                                                                                                                                  -122     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  -123     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  -124     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  -125     */
                                                                                                                                                                                                                                                                                                                  -126    public RNG(String seedString) {
                                                                                                                                                                                                                                                                                                                  -127        this(new LightRNG(CrossHash.hash(seedString)));
                                                                                                                                                                                                                                                                                                                  -128    }
                                                                                                                                                                                                                                                                                                                  -129
                                                                                                                                                                                                                                                                                                                  -130    /**
                                                                                                                                                                                                                                                                                                                  -131     * Uses the provided source of randomness for all calculations. This
                                                                                                                                                                                                                                                                                                                  -132     * constructor should be used if an alternate RandomnessSource other than LightRNG is desirable.
                                                                                                                                                                                                                                                                                                                  -133     *
                                                                                                                                                                                                                                                                                                                  -134     * @param random the source of pseudo-randomness, such as a MersenneTwister or SobolQRNG object
                                                                                                                                                                                                                                                                                                                  -135     */
                                                                                                                                                                                                                                                                                                                  -136    public RNG(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -137        this.random = random;
                                                                                                                                                                                                                                                                                                                  -138    }
                                                                                                                                                                                                                                                                                                                  -139
                                                                                                                                                                                                                                                                                                                  -140    /**
                                                                                                                                                                                                                                                                                                                  -141     * A subclass of java.util.Random that uses a RandomnessSource supplied by the user instead of the default.
                                                                                                                                                                                                                                                                                                                  -142     *
                                                                                                                                                                                                                                                                                                                  -143     * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  -144     */
                                                                                                                                                                                                                                                                                                                  -145    public static class CustomRandom extends Random {
                                                                                                                                                                                                                                                                                                                  -146
                                                                                                                                                                                                                                                                                                                  -147        private static final long serialVersionUID = 8211985716129281944L;
                                                                                                                                                                                                                                                                                                                  -148        private final RandomnessSource randomnessSource;
                                                                                                                                                                                                                                                                                                                  -149
                                                                                                                                                                                                                                                                                                                  -150        /**
                                                                                                                                                                                                                                                                                                                  -151         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  -152         * a LightRNG with a random seed.
                                                                                                                                                                                                                                                                                                                  -153         */
                                                                                                                                                                                                                                                                                                                  -154        public CustomRandom() {
                                                                                                                                                                                                                                                                                                                  -155            randomnessSource = new LightRNG();
                                                                                                                                                                                                                                                                                                                  -156        }
                                                                                                                                                                                                                                                                                                                  -157
                                                                                                                                                                                                                                                                                                                  -158        /**
                                                                                                                                                                                                                                                                                                                  -159         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  -160         * the seed of the given RandomnessSource if it has been seeded.
                                                                                                                                                                                                                                                                                                                  -161         *
                                                                                                                                                                                                                                                                                                                  -162         * @param randomnessSource a way to get random bits, supplied by RNG
                                                                                                                                                                                                                                                                                                                  -163         */
                                                                                                                                                                                                                                                                                                                  -164        public CustomRandom(RandomnessSource randomnessSource) {
                                                                                                                                                                                                                                                                                                                  -165            this.randomnessSource = randomnessSource;
                                                                                                                                                                                                                                                                                                                  -166        }
                                                                                                                                                                                                                                                                                                                  -167
                                                                                                                                                                                                                                                                                                                  -168        /**
                                                                                                                                                                                                                                                                                                                  -169         * Generates the next pseudorandom number. Subclasses should
                                                                                                                                                                                                                                                                                                                  -170         * override this, as this is used by all other methods.
                                                                                                                                                                                                                                                                                                                  -171         * <p>
                                                                                                                                                                                                                                                                                                                  -172         * <p>The general contract of {@code next} is that it returns an
                                                                                                                                                                                                                                                                                                                  -173         * {@code int} value and if the argument {@code bits} is between
                                                                                                                                                                                                                                                                                                                  -174         * {@code 1} and {@code 32} (inclusive), then that many low-order
                                                                                                                                                                                                                                                                                                                  -175         * bits of the returned value will be (approximately) independently
                                                                                                                                                                                                                                                                                                                  -176         * chosen bit values, each of which is (approximately) equally
                                                                                                                                                                                                                                                                                                                  -177         * likely to be {@code 0} or {@code 1}. The method {@code next} is
                                                                                                                                                                                                                                                                                                                  -178         * implemented by class {@code Random} by atomically updating the seed to
                                                                                                                                                                                                                                                                                                                  -179         * <pre>{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}</pre>
                                                                                                                                                                                                                                                                                                                  -180         * and returning
                                                                                                                                                                                                                                                                                                                  -181         * <pre>{@code (int)(seed >>> (48 - bits))}.</pre>
                                                                                                                                                                                                                                                                                                                  -182         *
                                                                                                                                                                                                                                                                                                                  -183         * This is a linear congruential pseudorandom number generator, as
                                                                                                                                                                                                                                                                                                                  -184         * defined by D. H. Lehmer and described by Donald E. Knuth in
                                                                                                                                                                                                                                                                                                                  -185         * <i>The Art of Computer Programming,</i> Volume 3:
                                                                                                                                                                                                                                                                                                                  -186         * <i>Seminumerical Algorithms</i>, section 3.2.1.
                                                                                                                                                                                                                                                                                                                  -187         *
                                                                                                                                                                                                                                                                                                                  -188         * @param bits random bits
                                                                                                                                                                                                                                                                                                                  -189         * @return the next pseudorandom value from this random number
                                                                                                                                                                                                                                                                                                                  -190         * generator's sequence
                                                                                                                                                                                                                                                                                                                  -191         * @since 1.1
                                                                                                                                                                                                                                                                                                                  -192         */
                                                                                                                                                                                                                                                                                                                  -193        @Override
                                                                                                                                                                                                                                                                                                                  -194        protected int next(int bits) {
                                                                                                                                                                                                                                                                                                                  -195            return randomnessSource.next(bits);
                                                                                                                                                                                                                                                                                                                  -196        }
                                                                                                                                                                                                                                                                                                                  -197    }
                                                                                                                                                                                                                                                                                                                  -198
                                                                                                                                                                                                                                                                                                                  -199    /**
                                                                                                                                                                                                                                                                                                                  -200     * @return a Random instance that can be used for legacy compatibility
                                                                                                                                                                                                                                                                                                                  -201     */
                                                                                                                                                                                                                                                                                                                  -202    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  -203        if (ran == null) {
                                                                                                                                                                                                                                                                                                                  -204            ran = new CustomRandom(random);
                                                                                                                                                                                                                                                                                                                  -205        }
                                                                                                                                                                                                                                                                                                                  -206        return ran;
                                                                                                                                                                                                                                                                                                                  -207    }
                                                                                                                                                                                                                                                                                                                  -208
                                                                                                                                                                                                                                                                                                                  -209    /**
                                                                                                                                                                                                                                                                                                                  -210     * Returns a value from an even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  -211     * (exclusive).
                                                                                                                                                                                                                                                                                                                  -212     *
                                                                                                                                                                                                                                                                                                                  -213     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -214     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -215     * @return the found value
                                                                                                                                                                                                                                                                                                                  -216     */
                                                                                                                                                                                                                                                                                                                  -217    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  -218        return min + (max - min) * nextDouble();
                                                                                                                                                                                                                                                                                                                  -219    }
                                                                                                                                                                                                                                                                                                                  -220
                                                                                                                                                                                                                                                                                                                  -221    /**
                                                                                                                                                                                                                                                                                                                  -222     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -223     * <p>
                                                                                                                                                                                                                                                                                                                  -224     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -225     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -226     *
                                                                                                                                                                                                                                                                                                                  -227     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -228     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -229     * @return the found value
                                                                                                                                                                                                                                                                                                                  -230     */
                                                                                                                                                                                                                                                                                                                  -231    public int between(int min, int max) {
                                                                                                                                                                                                                                                                                                                  -232        return nextInt(max - min) + min;
                                                                                                                                                                                                                                                                                                                  -233    }
                                                                                                                                                                                                                                                                                                                  -234
                                                                                                                                                                                                                                                                                                                  -235    /**
                                                                                                                                                                                                                                                                                                                  -236     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -237     * <p>
                                                                                                                                                                                                                                                                                                                  -238     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -239     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -240     *
                                                                                                                                                                                                                                                                                                                  -241     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -242     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -243     * @return the found value
                                                                                                                                                                                                                                                                                                                  -244     */
                                                                                                                                                                                                                                                                                                                  -245    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  -246        return nextLong(max - min) + min;
                                                                                                                                                                                                                                                                                                                  -247    }
                                                                                                                                                                                                                                                                                                                  -248
                                                                                                                                                                                                                                                                                                                  -249    /**
                                                                                                                                                                                                                                                                                                                  -250     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  -251     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  -252     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  -253     * <p>
                                                                                                                                                                                                                                                                                                                  -254     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  -255     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  -256     * <p>
                                                                                                                                                                                                                                                                                                                  -257     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  -258     *
                                                                                                                                                                                                                                                                                                                  -259     * @param min     the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  -260     * @param max     the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  -261     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  -262     * @return the found value
                                                                                                                                                                                                                                                                                                                  -263     */
                                                                                                                                                                                                                                                                                                                  -264    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  -265        int sum = 0;
                                                                                                                                                                                                                                                                                                                  -266        for (int i = 0; i < samples; i++) {
                                                                                                                                                                                                                                                                                                                  -267            sum += between(min, max);
                                                                                                                                                                                                                                                                                                                  -268        }
                                                                                                                                                                                                                                                                                                                  -269
                                                                                                                                                                                                                                                                                                                  -270        return Math.round((float) sum / samples);
                                                                                                                                                                                                                                                                                                                  -271    }
                                                                                                                                                                                                                                                                                                                  -272
                                                                                                                                                                                                                                                                                                                  -273    /**
                                                                                                                                                                                                                                                                                                                  -274     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  -275     * type.
                                                                                                                                                                                                                                                                                                                  -276     *
                                                                                                                                                                                                                                                                                                                  -277     * @param <T>   the type of the returned object
                                                                                                                                                                                                                                                                                                                  -278     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  -279     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -280     */
                                                                                                                                                                                                                                                                                                                  -281    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  -282        if (array.length < 1) {
                                                                                                                                                                                                                                                                                                                  -283            return null;
                                                                                                                                                                                                                                                                                                                  -284        }
                                                                                                                                                                                                                                                                                                                  -285        return array[nextInt(array.length)];
                                                                                                                                                                                                                                                                                                                  -286    }
                                                                                                                                                                                                                                                                                                                  -287
                                                                                                                                                                                                                                                                                                                  -288    /**
                                                                                                                                                                                                                                                                                                                  -289     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  -290     * then null is returned.
                                                                                                                                                                                                                                                                                                                  -291     *
                                                                                                                                                                                                                                                                                                                  -292     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  -293     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  -294     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -295     */
                                                                                                                                                                                                                                                                                                                  -296    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  -297        if (list.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  -298            return null;
                                                                                                                                                                                                                                                                                                                  -299        }
                                                                                                                                                                                                                                                                                                                  -300        return list.get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  -301    }
                                                                                                                                                                                                                                                                                                                  -302
                                                                                                                                                                                                                                                                                                                  -303    /**
                                                                                                                                                                                                                                                                                                                  -304     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  -305     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                  -306     * <p>
                                                                                                                                                                                                                                                                                                                  +093    /**
                                                                                                                                                                                                                                                                                                                  +094     * Default constructor; uses SplitMix64, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  +095     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +096     * <br>
                                                                                                                                                                                                                                                                                                                  +097     * Compatibility note: previous versions of SquidLib used Mersenne Twister by default. Due to the incompatibility
                                                                                                                                                                                                                                                                                                                  +098     * of the threads used by this Mersenne Twister implementation with GWT and HTML5 applications, the randomness
                                                                                                                                                                                                                                                                                                                  +099     * algorithm has been changed to a faster, more compatible algorithm, though it does suffer from a much lower
                                                                                                                                                                                                                                                                                                                  +100     * period. If you need drastically larger periods than 2^64, you can pass a LongPeriodRNG (or MersenneTwister on
                                                                                                                                                                                                                                                                                                                  +101     * targets other than HTML) object to the constructor that takes a RandomnessSource. If you don't know what the
                                                                                                                                                                                                                                                                                                                  +102     * period of a PRNG is, you probably don't need to worry about it; it's mainly relevant to heavily multi-threaded
                                                                                                                                                                                                                                                                                                                  +103     * applications anyway. The addition of LongPeriodRNG on March 21, 2016 should help to take the part of a fast,
                                                                                                                                                                                                                                                                                                                  +104     * large-period RNG, which MersenneTwister is unable to act as on GWT. The default may change again some time after
                                                                                                                                                                                                                                                                                                                  +105     * May 1, 2016, now that we have XoRoRNG, which is approximately as fast as LightRNG and has a substantially better
                                                                                                                                                                                                                                                                                                                  +106     * period (pow(2, 128) - 1). It may change instead to the newer ThrustRNG, which is extremely similar to LightRNG
                                                                                                                                                                                                                                                                                                                  +107     * except that it has slightly better statistical quality (both excellent) and is a fair amount faster (its period
                                                                                                                                                                                                                                                                                                                  +108     * remains at pow(2, 64)).
                                                                                                                                                                                                                                                                                                                  +109     */
                                                                                                                                                                                                                                                                                                                  +110    public RNG() {
                                                                                                                                                                                                                                                                                                                  +111        this(new LightRNG());
                                                                                                                                                                                                                                                                                                                  +112    }
                                                                                                                                                                                                                                                                                                                  +113
                                                                                                                                                                                                                                                                                                                  +114    /**
                                                                                                                                                                                                                                                                                                                  +115     * Seeded constructor; uses LightRNG, which is of high quality, but low period (which rarely matters for games),
                                                                                                                                                                                                                                                                                                                  +116     * and has good speed, tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +117     */
                                                                                                                                                                                                                                                                                                                  +118    public RNG(long seed) {
                                                                                                                                                                                                                                                                                                                  +119        this(new LightRNG(seed));
                                                                                                                                                                                                                                                                                                                  +120    }
                                                                                                                                                                                                                                                                                                                  +121
                                                                                                                                                                                                                                                                                                                  +122    /**
                                                                                                                                                                                                                                                                                                                  +123     * String-seeded constructor; uses a platform-independent hash of the String (it does not use String.hashCode) as a
                                                                                                                                                                                                                                                                                                                  +124     * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed,
                                                                                                                                                                                                                                                                                                                  +125     * tiny state size, and excellent 64-bit number generation.
                                                                                                                                                                                                                                                                                                                  +126     */
                                                                                                                                                                                                                                                                                                                  +127    public RNG(CharSequence seedString) {
                                                                                                                                                                                                                                                                                                                  +128        this(new LightRNG(CrossHash.hash(seedString)));
                                                                                                                                                                                                                                                                                                                  +129    }
                                                                                                                                                                                                                                                                                                                  +130
                                                                                                                                                                                                                                                                                                                  +131    /**
                                                                                                                                                                                                                                                                                                                  +132     * Uses the provided source of randomness for all calculations. This
                                                                                                                                                                                                                                                                                                                  +133     * constructor should be used if an alternate RandomnessSource other than LightRNG is desirable.
                                                                                                                                                                                                                                                                                                                  +134     * If the parameter is null, this is equivalent to using {@link #RNG()} as the constructor.
                                                                                                                                                                                                                                                                                                                  +135     * @param random the source of pseudo-randomness, such as a MersenneTwister or SobolQRNG object
                                                                                                                                                                                                                                                                                                                  +136     */
                                                                                                                                                                                                                                                                                                                  +137    public RNG(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +138        this.random = (random == null) ? new LightRNG() : random;
                                                                                                                                                                                                                                                                                                                  +139    }
                                                                                                                                                                                                                                                                                                                  +140
                                                                                                                                                                                                                                                                                                                  +141    /**
                                                                                                                                                                                                                                                                                                                  +142     * A subclass of java.util.Random that uses a RandomnessSource supplied by the user instead of the default.
                                                                                                                                                                                                                                                                                                                  +143     *
                                                                                                                                                                                                                                                                                                                  +144     * @author Tommy Ettinger
                                                                                                                                                                                                                                                                                                                  +145     */
                                                                                                                                                                                                                                                                                                                  +146    public static class CustomRandom extends Random {
                                                                                                                                                                                                                                                                                                                  +147
                                                                                                                                                                                                                                                                                                                  +148        private static final long serialVersionUID = 8211985716129281944L;
                                                                                                                                                                                                                                                                                                                  +149        private final RandomnessSource randomnessSource;
                                                                                                                                                                                                                                                                                                                  +150
                                                                                                                                                                                                                                                                                                                  +151        /**
                                                                                                                                                                                                                                                                                                                  +152         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  +153         * a LightRNG with a random seed.
                                                                                                                                                                                                                                                                                                                  +154         */
                                                                                                                                                                                                                                                                                                                  +155        public CustomRandom() {
                                                                                                                                                                                                                                                                                                                  +156            randomnessSource = new LightRNG();
                                                                                                                                                                                                                                                                                                                  +157        }
                                                                                                                                                                                                                                                                                                                  +158
                                                                                                                                                                                                                                                                                                                  +159        /**
                                                                                                                                                                                                                                                                                                                  +160         * Creates a new random number generator. This constructor uses
                                                                                                                                                                                                                                                                                                                  +161         * the seed of the given RandomnessSource if it has been seeded.
                                                                                                                                                                                                                                                                                                                  +162         *
                                                                                                                                                                                                                                                                                                                  +163         * @param randomnessSource a way to get random bits, supplied by RNG
                                                                                                                                                                                                                                                                                                                  +164         */
                                                                                                                                                                                                                                                                                                                  +165        public CustomRandom(RandomnessSource randomnessSource) {
                                                                                                                                                                                                                                                                                                                  +166            this.randomnessSource = randomnessSource;
                                                                                                                                                                                                                                                                                                                  +167        }
                                                                                                                                                                                                                                                                                                                  +168
                                                                                                                                                                                                                                                                                                                  +169        /**
                                                                                                                                                                                                                                                                                                                  +170         * Generates the next pseudorandom number. Subclasses should
                                                                                                                                                                                                                                                                                                                  +171         * override this, as this is used by all other methods.
                                                                                                                                                                                                                                                                                                                  +172         * <p>
                                                                                                                                                                                                                                                                                                                  +173         * <p>The general contract of {@code next} is that it returns an
                                                                                                                                                                                                                                                                                                                  +174         * {@code int} value and if the argument {@code bits} is between
                                                                                                                                                                                                                                                                                                                  +175         * {@code 1} and {@code 32} (inclusive), then that many low-order
                                                                                                                                                                                                                                                                                                                  +176         * bits of the returned value will be (approximately) independently
                                                                                                                                                                                                                                                                                                                  +177         * chosen bit values, each of which is (approximately) equally
                                                                                                                                                                                                                                                                                                                  +178         * likely to be {@code 0} or {@code 1}. The method {@code next} is
                                                                                                                                                                                                                                                                                                                  +179         * implemented by class {@code Random} by atomically updating the seed to
                                                                                                                                                                                                                                                                                                                  +180         * <pre>{@code (seed * 0x5DEECE66DL + 0xBL) & ((1L << 48) - 1)}</pre>
                                                                                                                                                                                                                                                                                                                  +181         * and returning
                                                                                                                                                                                                                                                                                                                  +182         * <pre>{@code (int)(seed >>> (48 - bits))}.</pre>
                                                                                                                                                                                                                                                                                                                  +183         *
                                                                                                                                                                                                                                                                                                                  +184         * This is a linear congruential pseudorandom number generator, as
                                                                                                                                                                                                                                                                                                                  +185         * defined by D. H. Lehmer and described by Donald E. Knuth in
                                                                                                                                                                                                                                                                                                                  +186         * <i>The Art of Computer Programming,</i> Volume 3:
                                                                                                                                                                                                                                                                                                                  +187         * <i>Seminumerical Algorithms</i>, section 3.2.1.
                                                                                                                                                                                                                                                                                                                  +188         *
                                                                                                                                                                                                                                                                                                                  +189         * @param bits random bits
                                                                                                                                                                                                                                                                                                                  +190         * @return the next pseudorandom value from this random number
                                                                                                                                                                                                                                                                                                                  +191         * generator's sequence
                                                                                                                                                                                                                                                                                                                  +192         * @since 1.1
                                                                                                                                                                                                                                                                                                                  +193         */
                                                                                                                                                                                                                                                                                                                  +194        @Override
                                                                                                                                                                                                                                                                                                                  +195        protected int next(int bits) {
                                                                                                                                                                                                                                                                                                                  +196            return randomnessSource.next(bits);
                                                                                                                                                                                                                                                                                                                  +197        }
                                                                                                                                                                                                                                                                                                                  +198    }
                                                                                                                                                                                                                                                                                                                  +199
                                                                                                                                                                                                                                                                                                                  +200    /**
                                                                                                                                                                                                                                                                                                                  +201     * @return a Random instance that can be used for legacy compatibility
                                                                                                                                                                                                                                                                                                                  +202     */
                                                                                                                                                                                                                                                                                                                  +203    public Random asRandom() {
                                                                                                                                                                                                                                                                                                                  +204        if (ran == null) {
                                                                                                                                                                                                                                                                                                                  +205            ran = new CustomRandom(random);
                                                                                                                                                                                                                                                                                                                  +206        }
                                                                                                                                                                                                                                                                                                                  +207        return ran;
                                                                                                                                                                                                                                                                                                                  +208    }
                                                                                                                                                                                                                                                                                                                  +209
                                                                                                                                                                                                                                                                                                                  +210    /**
                                                                                                                                                                                                                                                                                                                  +211     * Returns a value from an even distribution from min (inclusive) to max
                                                                                                                                                                                                                                                                                                                  +212     * (exclusive).
                                                                                                                                                                                                                                                                                                                  +213     *
                                                                                                                                                                                                                                                                                                                  +214     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +215     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +216     * @return the found value
                                                                                                                                                                                                                                                                                                                  +217     */
                                                                                                                                                                                                                                                                                                                  +218    public double between(double min, double max) {
                                                                                                                                                                                                                                                                                                                  +219        return min + (max - min) * nextDouble();
                                                                                                                                                                                                                                                                                                                  +220    }
                                                                                                                                                                                                                                                                                                                  +221
                                                                                                                                                                                                                                                                                                                  +222    /**
                                                                                                                                                                                                                                                                                                                  +223     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +224     * <p>
                                                                                                                                                                                                                                                                                                                  +225     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +226     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +227     *
                                                                                                                                                                                                                                                                                                                  +228     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +229     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +230     * @return the found value
                                                                                                                                                                                                                                                                                                                  +231     */
                                                                                                                                                                                                                                                                                                                  +232    public int between(int min, int max) {
                                                                                                                                                                                                                                                                                                                  +233        return nextInt(max - min) + min;
                                                                                                                                                                                                                                                                                                                  +234    }
                                                                                                                                                                                                                                                                                                                  +235
                                                                                                                                                                                                                                                                                                                  +236    /**
                                                                                                                                                                                                                                                                                                                  +237     * Returns a value between min (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +238     * <p>
                                                                                                                                                                                                                                                                                                                  +239     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +240     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +241     *
                                                                                                                                                                                                                                                                                                                  +242     * @param min the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +243     * @param max the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +244     * @return the found value
                                                                                                                                                                                                                                                                                                                  +245     */
                                                                                                                                                                                                                                                                                                                  +246    public long between(long min, long max) {
                                                                                                                                                                                                                                                                                                                  +247        return nextLong(max - min) + min;
                                                                                                                                                                                                                                                                                                                  +248    }
                                                                                                                                                                                                                                                                                                                  +249
                                                                                                                                                                                                                                                                                                                  +250    /**
                                                                                                                                                                                                                                                                                                                  +251     * Returns the average of a number of randomly selected numbers from the
                                                                                                                                                                                                                                                                                                                  +252     * provided range, with min being inclusive and max being exclusive. It will
                                                                                                                                                                                                                                                                                                                  +253     * sample the number of times passed in as the third parameter.
                                                                                                                                                                                                                                                                                                                  +254     * <p>
                                                                                                                                                                                                                                                                                                                  +255     * The inclusive and exclusive behavior is to match the behavior of the
                                                                                                                                                                                                                                                                                                                  +256     * similar method that deals with floating point values.
                                                                                                                                                                                                                                                                                                                  +257     * <p>
                                                                                                                                                                                                                                                                                                                  +258     * This can be used to weight RNG calls to the average between min and max.
                                                                                                                                                                                                                                                                                                                  +259     *
                                                                                                                                                                                                                                                                                                                  +260     * @param min     the minimum bound on the return value (inclusive)
                                                                                                                                                                                                                                                                                                                  +261     * @param max     the maximum bound on the return value (exclusive)
                                                                                                                                                                                                                                                                                                                  +262     * @param samples the number of samples to take
                                                                                                                                                                                                                                                                                                                  +263     * @return the found value
                                                                                                                                                                                                                                                                                                                  +264     */
                                                                                                                                                                                                                                                                                                                  +265    public int betweenWeighted(int min, int max, int samples) {
                                                                                                                                                                                                                                                                                                                  +266        int sum = 0;
                                                                                                                                                                                                                                                                                                                  +267        for (int i = 0; i < samples; i++) {
                                                                                                                                                                                                                                                                                                                  +268            sum += between(min, max);
                                                                                                                                                                                                                                                                                                                  +269        }
                                                                                                                                                                                                                                                                                                                  +270
                                                                                                                                                                                                                                                                                                                  +271        return Math.round((float) sum / samples);
                                                                                                                                                                                                                                                                                                                  +272    }
                                                                                                                                                                                                                                                                                                                  +273
                                                                                                                                                                                                                                                                                                                  +274    /**
                                                                                                                                                                                                                                                                                                                  +275     * Returns a random element from the provided array and maintains object
                                                                                                                                                                                                                                                                                                                  +276     * type.
                                                                                                                                                                                                                                                                                                                  +277     *
                                                                                                                                                                                                                                                                                                                  +278     * @param <T>   the type of the returned object
                                                                                                                                                                                                                                                                                                                  +279     * @param array the array to get an element from
                                                                                                                                                                                                                                                                                                                  +280     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +281     */
                                                                                                                                                                                                                                                                                                                  +282    public <T> T getRandomElement(T[] array) {
                                                                                                                                                                                                                                                                                                                  +283        if (array.length < 1) {
                                                                                                                                                                                                                                                                                                                  +284            return null;
                                                                                                                                                                                                                                                                                                                  +285        }
                                                                                                                                                                                                                                                                                                                  +286        return array[nextInt(array.length)];
                                                                                                                                                                                                                                                                                                                  +287    }
                                                                                                                                                                                                                                                                                                                  +288
                                                                                                                                                                                                                                                                                                                  +289    /**
                                                                                                                                                                                                                                                                                                                  +290     * Returns a random element from the provided list. If the list is empty
                                                                                                                                                                                                                                                                                                                  +291     * then null is returned.
                                                                                                                                                                                                                                                                                                                  +292     *
                                                                                                                                                                                                                                                                                                                  +293     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  +294     * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  +295     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +296     */
                                                                                                                                                                                                                                                                                                                  +297    public <T> T getRandomElement(List<T> list) {
                                                                                                                                                                                                                                                                                                                  +298        if (list.isEmpty()) {
                                                                                                                                                                                                                                                                                                                  +299            return null;
                                                                                                                                                                                                                                                                                                                  +300        }
                                                                                                                                                                                                                                                                                                                  +301        return list.get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  +302    }
                                                                                                                                                                                                                                                                                                                  +303
                                                                                                                                                                                                                                                                                                                  +304    /**
                                                                                                                                                                                                                                                                                                                  +305     * Returns a random element from the provided ShortSet. If the set is empty
                                                                                                                                                                                                                                                                                                                  +306     * then an exception is thrown.
                                                                                                                                                                                                                                                                                                                   307     * <p>
                                                                                                                                                                                                                                                                                                                  -308     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  -309     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  -310     * </p>
                                                                                                                                                                                                                                                                                                                  -311     *
                                                                                                                                                                                                                                                                                                                  -312     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  -313     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -314     */
                                                                                                                                                                                                                                                                                                                  -315    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  -316        if (set.size <= 0) {
                                                                                                                                                                                                                                                                                                                  -317            throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element");
                                                                                                                                                                                                                                                                                                                  -318        }
                                                                                                                                                                                                                                                                                                                  -319        int n = nextInt(set.size);
                                                                                                                                                                                                                                                                                                                  -320        short s = 0;
                                                                                                                                                                                                                                                                                                                  -321        ShortSet.ShortSetIterator ssi = set.iterator();
                                                                                                                                                                                                                                                                                                                  -322        while (n-- >= 0 && ssi.hasNext)
                                                                                                                                                                                                                                                                                                                  -323            s = ssi.next();
                                                                                                                                                                                                                                                                                                                  -324        ssi.reset();
                                                                                                                                                                                                                                                                                                                  -325        return s;
                                                                                                                                                                                                                                                                                                                  -326    }
                                                                                                                                                                                                                                                                                                                  -327
                                                                                                                                                                                                                                                                                                                  -328    /**
                                                                                                                                                                                                                                                                                                                  -329     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  -330     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  -331     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  -332     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  -333     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  -334     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                  -335     * <p>
                                                                                                                                                                                                                                                                                                                  +308     * <p>
                                                                                                                                                                                                                                                                                                                  +309     * Requires iterating through a random amount of the elements in set, so performance depends on the size of set but
                                                                                                                                                                                                                                                                                                                  +310     * is likely to be decent. This is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  +311     * </p>
                                                                                                                                                                                                                                                                                                                  +312     *
                                                                                                                                                                                                                                                                                                                  +313     * @param set the ShortSet to get an element from
                                                                                                                                                                                                                                                                                                                  +314     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +315     */
                                                                                                                                                                                                                                                                                                                  +316    public short getRandomElement(ShortSet set) {
                                                                                                                                                                                                                                                                                                                  +317        if (set.size <= 0) {
                                                                                                                                                                                                                                                                                                                  +318            throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element");
                                                                                                                                                                                                                                                                                                                  +319        }
                                                                                                                                                                                                                                                                                                                  +320        int n = nextInt(set.size);
                                                                                                                                                                                                                                                                                                                  +321        short s = 0;
                                                                                                                                                                                                                                                                                                                  +322        ShortSet.ShortSetIterator ssi = set.iterator();
                                                                                                                                                                                                                                                                                                                  +323        while (n-- >= 0 && ssi.hasNext)
                                                                                                                                                                                                                                                                                                                  +324            s = ssi.next();
                                                                                                                                                                                                                                                                                                                  +325        ssi.reset();
                                                                                                                                                                                                                                                                                                                  +326        return s;
                                                                                                                                                                                                                                                                                                                  +327    }
                                                                                                                                                                                                                                                                                                                  +328
                                                                                                                                                                                                                                                                                                                  +329    /**
                                                                                                                                                                                                                                                                                                                  +330     * Returns a random element from the provided Collection, which should have predictable iteration order if you want
                                                                                                                                                                                                                                                                                                                  +331     * predictable behavior for identical RNG seeds, though it will get a random element just fine for any Collection
                                                                                                                                                                                                                                                                                                                  +332     * (just not predictably in all cases). If you give this a Set, it should be a LinkedHashSet or some form of sorted
                                                                                                                                                                                                                                                                                                                  +333     * Set like TreeSet if you want predictable results. Any List or Queue should be fine. Map does not implement
                                                                                                                                                                                                                                                                                                                  +334     * Collection, thank you very much Java library designers, so you can't actually pass a Map to this, though you can
                                                                                                                                                                                                                                                                                                                  +335     * pass the keys or values. If coll is empty, returns null.
                                                                                                                                                                                                                                                                                                                   336     * <p>
                                                                                                                                                                                                                                                                                                                  -337     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  -338     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  -339     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  -340     * </p>
                                                                                                                                                                                                                                                                                                                  -341     *
                                                                                                                                                                                                                                                                                                                  -342     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  -343     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  -344     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -345     */
                                                                                                                                                                                                                                                                                                                  -346    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  -347        if (coll.size() <= 0) {
                                                                                                                                                                                                                                                                                                                  -348            return null;
                                                                                                                                                                                                                                                                                                                  -349        }
                                                                                                                                                                                                                                                                                                                  -350        int n = nextInt(coll.size());
                                                                                                                                                                                                                                                                                                                  -351        T t = null;
                                                                                                                                                                                                                                                                                                                  -352        Iterator<T> it = coll.iterator();
                                                                                                                                                                                                                                                                                                                  -353        while (n-- >= 0 && it.hasNext())
                                                                                                                                                                                                                                                                                                                  -354            t = it.next();
                                                                                                                                                                                                                                                                                                                  -355        return t;
                                                                                                                                                                                                                                                                                                                  -356    }
                                                                                                                                                                                                                                                                                                                  -357
                                                                                                                                                                                                                                                                                                                  -358        /*
                                                                                                                                                                                                                                                                                                                  -359     * Returns a random elements from the provided queue. If the queue is empty
                                                                                                                                                                                                                                                                                                                  -360         * then null is returned.
                                                                                                                                                                                                                                                                                                                  -361         *
                                                                                                                                                                                                                                                                                                                  -362         * <p>
                                                                                                                                                                                                                                                                                                                  -363         * Requires iterating through a random amount of the elements in set, so
                                                                                                                                                                                                                                                                                                                  -364         * performance depends on the size of set but is likely to be decent. This
                                                                                                                                                                                                                                                                                                                  -365         * is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  -366         * </p>
                                                                                                                                                                                                                                                                                                                  -367         *
                                                                                                                                                                                                                                                                                                                  -368         * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  -369         * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  -370         * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  -371         */
                                                                                                                                                                                                                                                                                                                  -372        /*
                                                                                                                                                                                                                                                                                                                  -373        public <T> T getRandomElement(Queue<T> list) {
                                                                                                                                                                                                                                                                                                                  -374                if (list.isEmpty()) {
                                                                                                                                                                                                                                                                                                                  -375                        return null;
                                                                                                                                                                                                                                                                                                                  -376                }
                                                                                                                                                                                                                                                                                                                  -377                return new ArrayList<>(list).get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  -378        }*/
                                                                                                                                                                                                                                                                                                                  -379
                                                                                                                                                                                                                                                                                                                  -380    /**
                                                                                                                                                                                                                                                                                                                  -381     * Given a {@link List} l, this selects a random element of l to be the first value in the returned list l2. It
                                                                                                                                                                                                                                                                                                                  -382     * retains the order of elements in l after that random element and makes them follow the first element in l2, and
                                                                                                                                                                                                                                                                                                                  -383     * loops around to use elements from the start of l after it has placed the last element of l into l2.
                                                                                                                                                                                                                                                                                                                  -384     * <br>
                                                                                                                                                                                                                                                                                                                  -385     * Essentially, it does what it says on the tin. It randomly rotates the List l.
                                                                                                                                                                                                                                                                                                                  +337     * <p>
                                                                                                                                                                                                                                                                                                                  +338     * Requires iterating through a random amount of coll's elements, so performance depends on the size of coll but is
                                                                                                                                                                                                                                                                                                                  +339     * likely to be decent, as long as iteration isn't unusually slow. This replaces {@code getRandomElement(Queue)},
                                                                                                                                                                                                                                                                                                                  +340     * since Queue implements Collection and the older Queue-using implementation was probably less efficient.
                                                                                                                                                                                                                                                                                                                  +341     * </p>
                                                                                                                                                                                                                                                                                                                  +342     *
                                                                                                                                                                                                                                                                                                                  +343     * @param <T>  the type of the returned object
                                                                                                                                                                                                                                                                                                                  +344     * @param coll the Collection to get an element from; remember, Map does not implement Collection
                                                                                                                                                                                                                                                                                                                  +345     * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +346     */
                                                                                                                                                                                                                                                                                                                  +347    public <T> T getRandomElement(Collection<T> coll) {
                                                                                                                                                                                                                                                                                                                  +348        int n;
                                                                                                                                                                                                                                                                                                                  +349        if ((n = coll.size()) <= 0) {
                                                                                                                                                                                                                                                                                                                  +350            return null;
                                                                                                                                                                                                                                                                                                                  +351        }
                                                                                                                                                                                                                                                                                                                  +352        n = nextInt(n);
                                                                                                                                                                                                                                                                                                                  +353        T t = null;
                                                                                                                                                                                                                                                                                                                  +354        Iterator<T> it = coll.iterator();
                                                                                                                                                                                                                                                                                                                  +355        while (n-- >= 0 && it.hasNext())
                                                                                                                                                                                                                                                                                                                  +356            t = it.next();
                                                                                                                                                                                                                                                                                                                  +357        return t;
                                                                                                                                                                                                                                                                                                                  +358    }
                                                                                                                                                                                                                                                                                                                  +359
                                                                                                                                                                                                                                                                                                                  +360        /*
                                                                                                                                                                                                                                                                                                                  +361     * Returns a random elements from the provided queue. If the queue is empty
                                                                                                                                                                                                                                                                                                                  +362         * then null is returned.
                                                                                                                                                                                                                                                                                                                  +363         *
                                                                                                                                                                                                                                                                                                                  +364         * <p>
                                                                                                                                                                                                                                                                                                                  +365         * Requires iterating through a random amount of the elements in set, so
                                                                                                                                                                                                                                                                                                                  +366         * performance depends on the size of set but is likely to be decent. This
                                                                                                                                                                                                                                                                                                                  +367         * is mostly meant for internal use, the same as ShortSet.
                                                                                                                                                                                                                                                                                                                  +368         * </p>
                                                                                                                                                                                                                                                                                                                  +369         *
                                                                                                                                                                                                                                                                                                                  +370         * @param <T> the type of the returned object
                                                                                                                                                                                                                                                                                                                  +371         * @param list the list to get an element from
                                                                                                                                                                                                                                                                                                                  +372         * @return the randomly selected element
                                                                                                                                                                                                                                                                                                                  +373         */
                                                                                                                                                                                                                                                                                                                  +374        /*
                                                                                                                                                                                                                                                                                                                  +375        public <T> T getRandomElement(Queue<T> list) {
                                                                                                                                                                                                                                                                                                                  +376                if (list.isEmpty()) {
                                                                                                                                                                                                                                                                                                                  +377                        return null;
                                                                                                                                                                                                                                                                                                                  +378                }
                                                                                                                                                                                                                                                                                                                  +379                return new ArrayList<>(list).get(nextInt(list.size()));
                                                                                                                                                                                                                                                                                                                  +380        }*/
                                                                                                                                                                                                                                                                                                                  +381
                                                                                                                                                                                                                                                                                                                  +382    /**
                                                                                                                                                                                                                                                                                                                  +383     * Given a {@link List} l, this selects a random element of l to be the first value in the returned list l2. It
                                                                                                                                                                                                                                                                                                                  +384     * retains the order of elements in l after that random element and makes them follow the first element in l2, and
                                                                                                                                                                                                                                                                                                                  +385     * loops around to use elements from the start of l after it has placed the last element of l into l2.
                                                                                                                                                                                                                                                                                                                   386     * <br>
                                                                                                                                                                                                                                                                                                                  -387     * If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable()
                                                                                                                                                                                                                                                                                                                  -388     * should have better performance.
                                                                                                                                                                                                                                                                                                                  -389     *
                                                                                                                                                                                                                                                                                                                  -390     * @param l   A {@link List} that will not be modified by this method. All elements of this parameter will be
                                                                                                                                                                                                                                                                                                                  -391     *            shared with the returned List.
                                                                                                                                                                                                                                                                                                                  -392     * @param <T> No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                                                                                                                                                                                                                                                  -393     * @return A shallow copy of {@code l} that has been rotated so its first element has been randomly chosen
                                                                                                                                                                                                                                                                                                                  -394     * from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last
                                                                                                                                                                                                                                                                                                                  -395     * element of l, then element 1, etc.
                                                                                                                                                                                                                                                                                                                  -396     */
                                                                                                                                                                                                                                                                                                                  -397    @GwtIncompatible /* Because of Collections.rotate */
                                                                                                                                                                                                                                                                                                                  -398    public <T> List<T> randomRotation(final List<T> l) {
                                                                                                                                                                                                                                                                                                                  -399        final int sz = l.size();
                                                                                                                                                                                                                                                                                                                  -400        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  -401            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  -402
                                                                                                                                                                                                                                                                                                                  -403                /*
                                                                                                                                                                                                                                                                                                                  -404                 * Collections.rotate should prefer the best-performing way to rotate l,
                                                                                                                                                                                                                                                                                                                  -405                 * which would be an in-place modification for ArrayLists and an append
                                                                                                                                                                                                                                                                                                                  -406                 * to a sublist for Lists that don't support efficient random access.
                                                                                                                                                                                                                                                                                                                  -407                 */
                                                                                                                                                                                                                                                                                                                  -408        List<T> l2 = new ArrayList<>(l);
                                                                                                                                                                                                                                                                                                                  -409        Collections.rotate(l2, nextInt(sz));
                                                                                                                                                                                                                                                                                                                  -410        return l2;
                                                                                                                                                                                                                                                                                                                  -411    }
                                                                                                                                                                                                                                                                                                                  -412
                                                                                                                                                                                                                                                                                                                  -413    /**
                                                                                                                                                                                                                                                                                                                  -414     * Get an Iterable that starts at a random location in list and continues on through list in its current order.
                                                                                                                                                                                                                                                                                                                  -415     * Loops around to the beginning after it gets to the end, stops when it returns to the starting location.
                                                                                                                                                                                                                                                                                                                  -416     * <br>
                                                                                                                                                                                                                                                                                                                  -417     * You should not modify {@code list} while you use the returned reference. And there'll be no
                                                                                                                                                                                                                                                                                                                  -418     * ConcurrentModificationException to detect such erroneous uses.
                                                                                                                                                                                                                                                                                                                  -419     *
                                                                                                                                                                                                                                                                                                                  -420     * @param list A list <b>with a constant-time {@link List#get(int)} method</b> (otherwise performance degrades).
                                                                                                                                                                                                                                                                                                                  -421     * @return An {@link Iterable} that iterates over {@code list} but start at
                                                                                                                                                                                                                                                                                                                  -422     * a random index. If the chosen index is {@code i}, the iterator
                                                                                                                                                                                                                                                                                                                  -423     * will return:
                                                                                                                                                                                                                                                                                                                  -424     * {@code list[i]; list[i+1]; ...; list[list.length() - 1]; list[0]; list[i-1]}
                                                                                                                                                                                                                                                                                                                  -425     */
                                                                                                                                                                                                                                                                                                                  -426    public <T> Iterable<T> getRandomStartIterable(final List<T> list) {
                                                                                                                                                                                                                                                                                                                  -427        final int sz = list.size();
                                                                                                                                                                                                                                                                                                                  -428        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  -429            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  -430
                                                                                                                                                                                                                                                                                                                  -431                /*
                                                                                                                                                                                                                                                                                                                  -432                 * Here's a tricky bit: Defining 'start' here means that every Iterator
                                                                                                                                                                                                                                                                                                                  -433                 * returned by the returned Iterable will have the same iteration order.
                                                                                                                                                                                                                                                                                                                  -434                 * In other words, if you use more than once the returned Iterable,
                                                                                                                                                                                                                                                                                                                  -435                 * you'll will see elements in the same order every time, which is
                                                                                                                                                                                                                                                                                                                  -436                 * desirable.
                                                                                                                                                                                                                                                                                                                  -437                 */
                                                                                                                                                                                                                                                                                                                  -438        final int start = nextInt(sz);
                                                                                                                                                                                                                                                                                                                  -439
                                                                                                                                                                                                                                                                                                                  -440        return new Iterable<T>() {
                                                                                                                                                                                                                                                                                                                  -441            @Override
                                                                                                                                                                                                                                                                                                                  -442            public Iterator<T> iterator() {
                                                                                                                                                                                                                                                                                                                  -443                return new Iterator<T>() {
                                                                                                                                                                                                                                                                                                                  -444
                                                                                                                                                                                                                                                                                                                  -445                    int next = -1;
                                                                                                                                                                                                                                                                                                                  +387     * Essentially, it does what it says on the tin. It randomly rotates the List l.
                                                                                                                                                                                                                                                                                                                  +388     * <br>
                                                                                                                                                                                                                                                                                                                  +389     * If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable()
                                                                                                                                                                                                                                                                                                                  +390     * should have better performance. This was GWT incompatible before GWT 2.8.0 became the version SquidLib uses; now
                                                                                                                                                                                                                                                                                                                  +391     * this method works fine with GWT.
                                                                                                                                                                                                                                                                                                                  +392     *
                                                                                                                                                                                                                                                                                                                  +393     * @param l   A {@link List} that will not be modified by this method. All elements of this parameter will be
                                                                                                                                                                                                                                                                                                                  +394     *            shared with the returned List.
                                                                                                                                                                                                                                                                                                                  +395     * @param <T> No restrictions on type. Changes to elements of the returned List will be reflected in the parameter.
                                                                                                                                                                                                                                                                                                                  +396     * @return A shallow copy of {@code l} that has been rotated so its first element has been randomly chosen
                                                                                                                                                                                                                                                                                                                  +397     * from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last
                                                                                                                                                                                                                                                                                                                  +398     * element of l, then element 1, etc.
                                                                                                                                                                                                                                                                                                                  +399     */
                                                                                                                                                                                                                                                                                                                  +400    public <T> List<T> randomRotation(final List<T> l) {
                                                                                                                                                                                                                                                                                                                  +401        final int sz = l.size();
                                                                                                                                                                                                                                                                                                                  +402        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  +403            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  +404
                                                                                                                                                                                                                                                                                                                  +405                /*
                                                                                                                                                                                                                                                                                                                  +406                 * Collections.rotate should prefer the best-performing way to rotate l,
                                                                                                                                                                                                                                                                                                                  +407                 * which would be an in-place modification for ArrayLists and an append
                                                                                                                                                                                                                                                                                                                  +408                 * to a sublist for Lists that don't support efficient random access.
                                                                                                                                                                                                                                                                                                                  +409                 */
                                                                                                                                                                                                                                                                                                                  +410        List<T> l2 = new ArrayList<>(l);
                                                                                                                                                                                                                                                                                                                  +411        Collections.rotate(l2, nextInt(sz));
                                                                                                                                                                                                                                                                                                                  +412        return l2;
                                                                                                                                                                                                                                                                                                                  +413    }
                                                                                                                                                                                                                                                                                                                  +414
                                                                                                                                                                                                                                                                                                                  +415    /**
                                                                                                                                                                                                                                                                                                                  +416     * Get an Iterable that starts at a random location in list and continues on through list in its current order.
                                                                                                                                                                                                                                                                                                                  +417     * Loops around to the beginning after it gets to the end, stops when it returns to the starting location.
                                                                                                                                                                                                                                                                                                                  +418     * <br>
                                                                                                                                                                                                                                                                                                                  +419     * You should not modify {@code list} while you use the returned reference. And there'll be no
                                                                                                                                                                                                                                                                                                                  +420     * ConcurrentModificationException to detect such erroneous uses.
                                                                                                                                                                                                                                                                                                                  +421     *
                                                                                                                                                                                                                                                                                                                  +422     * @param list A list <b>with a constant-time {@link List#get(int)} method</b> (otherwise performance degrades).
                                                                                                                                                                                                                                                                                                                  +423     * @return An {@link Iterable} that iterates over {@code list} but start at
                                                                                                                                                                                                                                                                                                                  +424     * a random index. If the chosen index is {@code i}, the iterator
                                                                                                                                                                                                                                                                                                                  +425     * will return:
                                                                                                                                                                                                                                                                                                                  +426     * {@code list[i]; list[i+1]; ...; list[list.length() - 1]; list[0]; list[i-1]}
                                                                                                                                                                                                                                                                                                                  +427     */
                                                                                                                                                                                                                                                                                                                  +428    public <T> Iterable<T> getRandomStartIterable(final List<T> list) {
                                                                                                                                                                                                                                                                                                                  +429        final int sz = list.size();
                                                                                                                                                                                                                                                                                                                  +430        if (sz == 0)
                                                                                                                                                                                                                                                                                                                  +431            return Collections.<T>emptyList();
                                                                                                                                                                                                                                                                                                                  +432
                                                                                                                                                                                                                                                                                                                  +433                /*
                                                                                                                                                                                                                                                                                                                  +434                 * Here's a tricky bit: Defining 'start' here means that every Iterator
                                                                                                                                                                                                                                                                                                                  +435                 * returned by the returned Iterable will have the same iteration order.
                                                                                                                                                                                                                                                                                                                  +436                 * In other words, if you use more than once the returned Iterable,
                                                                                                                                                                                                                                                                                                                  +437                 * you'll will see elements in the same order every time, which is
                                                                                                                                                                                                                                                                                                                  +438                 * desirable.
                                                                                                                                                                                                                                                                                                                  +439                 */
                                                                                                                                                                                                                                                                                                                  +440        final int start = nextInt(sz);
                                                                                                                                                                                                                                                                                                                  +441
                                                                                                                                                                                                                                                                                                                  +442        return new Iterable<T>() {
                                                                                                                                                                                                                                                                                                                  +443            @Override
                                                                                                                                                                                                                                                                                                                  +444            public Iterator<T> iterator() {
                                                                                                                                                                                                                                                                                                                  +445                return new Iterator<T>() {
                                                                                                                                                                                                                                                                                                                   446
                                                                                                                                                                                                                                                                                                                  -447                    @Override
                                                                                                                                                                                                                                                                                                                  -448                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  -449                        return next != start;
                                                                                                                                                                                                                                                                                                                  -450                    }
                                                                                                                                                                                                                                                                                                                  -451
                                                                                                                                                                                                                                                                                                                  -452                    @Override
                                                                                                                                                                                                                                                                                                                  -453                    public T next() {
                                                                                                                                                                                                                                                                                                                  -454                        if (next == start)
                                                                                                                                                                                                                                                                                                                  -455                            throw new NoSuchElementException("Iteration terminated; check hasNext() before next()");
                                                                                                                                                                                                                                                                                                                  -456                        if (next == -1)
                                                                                                                                                                                                                                                                                                                  -457                                        /* First call */
                                                                                                                                                                                                                                                                                                                  -458                            next = start;
                                                                                                                                                                                                                                                                                                                  -459                        final T result = list.get(next);
                                                                                                                                                                                                                                                                                                                  -460                        if (next == sz - 1)
                                                                                                                                                                                                                                                                                                                  -461                                        /*
                                                                                                                                                                                                                                                                                                                  -462                                         * Reached the list's end, let's continue from the list's
                                                                                                                                                                                                                                                                                                                  -463                                         * left.
                                                                                                                                                                                                                                                                                                                  -464                                         */
                                                                                                                                                                                                                                                                                                                  -465                            next = 0;
                                                                                                                                                                                                                                                                                                                  -466                        else
                                                                                                                                                                                                                                                                                                                  -467                            next++;
                                                                                                                                                                                                                                                                                                                  -468                        return result;
                                                                                                                                                                                                                                                                                                                  -469                    }
                                                                                                                                                                                                                                                                                                                  -470
                                                                                                                                                                                                                                                                                                                  -471                    @Override
                                                                                                                                                                                                                                                                                                                  -472                    public void remove() {
                                                                                                                                                                                                                                                                                                                  -473                        throw new UnsupportedOperationException("Remove is not supported from a randomStartIterable");
                                                                                                                                                                                                                                                                                                                  -474                    }
                                                                                                                                                                                                                                                                                                                  -475
                                                                                                                                                                                                                                                                                                                  -476                    @Override
                                                                                                                                                                                                                                                                                                                  -477                    public String toString() {
                                                                                                                                                                                                                                                                                                                  -478                        return "RandomStartIterator at index " + next;
                                                                                                                                                                                                                                                                                                                  -479                    }
                                                                                                                                                                                                                                                                                                                  -480                };
                                                                                                                                                                                                                                                                                                                  -481            }
                                                                                                                                                                                                                                                                                                                  -482        };
                                                                                                                                                                                                                                                                                                                  -483    }
                                                                                                                                                                                                                                                                                                                  -484
                                                                                                                                                                                                                                                                                                                  -485    /**
                                                                                                                                                                                                                                                                                                                  -486     * Use that to get random cells in a rectangular map.
                                                                                                                                                                                                                                                                                                                  -487     *
                                                                                                                                                                                                                                                                                                                  -488     * @param width  The map's width (bounds the x-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  -489     * @param height The map's height (bounds the y-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  -490     * @param size   The number of elements in the returned iterable or anything
                                                                                                                                                                                                                                                                                                                  -491     *               negative for no bound (in which case the iterator is infinite, it's
                                                                                                                                                                                                                                                                                                                  -492     *               up to you to bound your iteration).
                                                                                                                                                                                                                                                                                                                  -493     * @return An iterable that returns random cells in the rectangle (0,0)
                                                                                                                                                                                                                                                                                                                  -494     * (inclusive) .. (width, height) (exclusive).
                                                                                                                                                                                                                                                                                                                  -495     */
                                                                                                                                                                                                                                                                                                                  -496    public Iterable<Coord> getRandomCellsIterable(final int width, final int height, final int size) {
                                                                                                                                                                                                                                                                                                                  -497        return new Iterable<Coord>() {
                                                                                                                                                                                                                                                                                                                  -498            @Override
                                                                                                                                                                                                                                                                                                                  -499            public Iterator<Coord> iterator() {
                                                                                                                                                                                                                                                                                                                  -500                return new Iterator<Coord>() {
                                                                                                                                                                                                                                                                                                                  -501
                                                                                                                                                                                                                                                                                                                  -502                    /**
                                                                                                                                                                                                                                                                                                                  -503                     * The number of elements returned so far
                                                                                                                                                                                                                                                                                                                  -504                     */
                                                                                                                                                                                                                                                                                                                  -505                    int returned = 0;
                                                                                                                                                                                                                                                                                                                  -506
                                                                                                                                                                                                                                                                                                                  -507                    @Override
                                                                                                                                                                                                                                                                                                                  -508                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  -509                        return size < 0 || returned < size;
                                                                                                                                                                                                                                                                                                                  -510                    }
                                                                                                                                                                                                                                                                                                                  -511
                                                                                                                                                                                                                                                                                                                  -512                    @Override
                                                                                                                                                                                                                                                                                                                  -513                    public Coord next() {
                                                                                                                                                                                                                                                                                                                  -514                        if (!hasNext())
                                                                                                                                                                                                                                                                                                                  -515                            throw new NoSuchElementException();
                                                                                                                                                                                                                                                                                                                  -516                        returned++;
                                                                                                                                                                                                                                                                                                                  -517                        return nextCoord(width, height);
                                                                                                                                                                                                                                                                                                                  -518                    }
                                                                                                                                                                                                                                                                                                                  -519
                                                                                                                                                                                                                                                                                                                  -520                    @Override
                                                                                                                                                                                                                                                                                                                  -521                    public void remove() {
                                                                                                                                                                                                                                                                                                                  -522                        throw new UnsupportedOperationException();
                                                                                                                                                                                                                                                                                                                  -523                    }
                                                                                                                                                                                                                                                                                                                  -524                };
                                                                                                                                                                                                                                                                                                                  -525            }
                                                                                                                                                                                                                                                                                                                  -526        };
                                                                                                                                                                                                                                                                                                                  -527    }
                                                                                                                                                                                                                                                                                                                  -528
                                                                                                                                                                                                                                                                                                                  -529    /**
                                                                                                                                                                                                                                                                                                                  -530     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  -531     * random order, with the array containing {@code width * height} items.
                                                                                                                                                                                                                                                                                                                  -532     *
                                                                                                                                                                                                                                                                                                                  -533     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  -534     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  -535     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  -536     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  -537     * @return an array containing {@code width * height} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  -538     */
                                                                                                                                                                                                                                                                                                                  -539    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height) {
                                                                                                                                                                                                                                                                                                                  -540        if (width <= 0 || height <= 0)
                                                                                                                                                                                                                                                                                                                  -541            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  -542        return getRandomUniqueCells(startX, startY, width, height, new Coord[width * height]);
                                                                                                                                                                                                                                                                                                                  -543    }
                                                                                                                                                                                                                                                                                                                  -544
                                                                                                                                                                                                                                                                                                                  -545    /**
                                                                                                                                                                                                                                                                                                                  -546     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  -547     * random order, with the array containing {@code Math.min(width * height, size)} items. If size is less than width
                                                                                                                                                                                                                                                                                                                  -548     * times height, then not all Coords in the space will be used.
                                                                                                                                                                                                                                                                                                                  -549     *
                                                                                                                                                                                                                                                                                                                  -550     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  -551     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  -552     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  -553     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  -554     * @param size   the size of the array to return; only matters if it is smaller than {@code width * height}
                                                                                                                                                                                                                                                                                                                  -555     * @return an array containing {@code Math.min(width * height, size)} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  -556     */
                                                                                                                                                                                                                                                                                                                  -557    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  -558                                        final int size) {
                                                                                                                                                                                                                                                                                                                  -559        if (width <= 0 || height <= 0 || size <= 0)
                                                                                                                                                                                                                                                                                                                  -560            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  -561        return getRandomUniqueCells(startX, startY, width, height, new Coord[Math.min(width * height, size)]);
                                                                                                                                                                                                                                                                                                                  -562    }
                                                                                                                                                                                                                                                                                                                  -563
                                                                                                                                                                                                                                                                                                                  -564    /**
                                                                                                                                                                                                                                                                                                                  -565     * Assigns to dest an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height)
                                                                                                                                                                                                                                                                                                                  -566     * exclusive, in a random order, with dest after this is called containing the lesser of {@code width * height} or
                                                                                                                                                                                                                                                                                                                  -567     * {@code dest.length} items. This will not allocate a new array for dest, but will create a temporary int array for
                                                                                                                                                                                                                                                                                                                  -568     * handling the shuffle.
                                                                                                                                                                                                                                                                                                                  -569     *
                                                                                                                                                                                                                                                                                                                  -570     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  -571     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  -572     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  -573     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  -574     * @param dest   a Coord array that will be modified to contain randomly-ordered Coords, but will not be resized
                                                                                                                                                                                                                                                                                                                  -575     * @return dest, now with up to its first {@code width * height} items assigned to random Coords inside the given bounds
                                                                                                                                                                                                                                                                                                                  -576     */
                                                                                                                                                                                                                                                                                                                  -577    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  -578                                        final Coord[] dest) {
                                                                                                                                                                                                                                                                                                                  -579        if (width <= 0 || height <= 0 || dest == null || dest.length <= 0)
                                                                                                                                                                                                                                                                                                                  -580            return dest;
                                                                                                                                                                                                                                                                                                                  -581        int[] o = randomOrdering(width * height);
                                                                                                                                                                                                                                                                                                                  -582        for (int i = 0; i < o.length && i < dest.length; i++) {
                                                                                                                                                                                                                                                                                                                  -583            dest[i] = Coord.get(startX + o[i] % width, startY + o[i] / width);
                                                                                                                                                                                                                                                                                                                  -584        }
                                                                                                                                                                                                                                                                                                                  -585        return dest;
                                                                                                                                                                                                                                                                                                                  -586    }
                                                                                                                                                                                                                                                                                                                  -587
                                                                                                                                                                                                                                                                                                                  -588    /**
                                                                                                                                                                                                                                                                                                                  -589     * Shuffle an array using the Fisher-Yates algorithm and returns a shuffled copy.
                                                                                                                                                                                                                                                                                                                  -590     * GWT-compatible since GWT 2.8.0, which is the default if you use libGDX 1.9.5 or higher.
                                                                                                                                                                                                                                                                                                                  -591     * <br>
                                                                                                                                                                                                                                                                                                                  -592     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -593     *
                                                                                                                                                                                                                                                                                                                  -594     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -595     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -596     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  -597     */
                                                                                                                                                                                                                                                                                                                  -598    public <T> T[] shuffle(final T[] elements) {
                                                                                                                                                                                                                                                                                                                  -599        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  -600        final T[] array = Arrays.copyOf(elements, n);
                                                                                                                                                                                                                                                                                                                  -601        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -602            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  -603            T t = array[r];
                                                                                                                                                                                                                                                                                                                  -604            if (r != i)
                                                                                                                                                                                                                                                                                                                  -605                array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  -606            array[i] = t;
                                                                                                                                                                                                                                                                                                                  -607        }
                                                                                                                                                                                                                                                                                                                  -608        return array;
                                                                                                                                                                                                                                                                                                                  -609    }
                                                                                                                                                                                                                                                                                                                  -610
                                                                                                                                                                                                                                                                                                                  -611    /**
                                                                                                                                                                                                                                                                                                                  -612     * Shuffles an array in place using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  -613     * If you don't want the array modified, use {@link #shuffle(Object[], Object[])}.
                                                                                                                                                                                                                                                                                                                  -614     * Unlike {@link #shuffle(Object[])}, this is GWT-compatible.
                                                                                                                                                                                                                                                                                                                  -615     * <br>
                                                                                                                                                                                                                                                                                                                  -616     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -617     *
                                                                                                                                                                                                                                                                                                                  -618     * @param elements an array of T; <b>will</b> be modified
                                                                                                                                                                                                                                                                                                                  -619     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -620     * @return elements after shuffling it in-place
                                                                                                                                                                                                                                                                                                                  -621     */
                                                                                                                                                                                                                                                                                                                  -622    public <T> T[] shuffleInPlace(T[] elements) {
                                                                                                                                                                                                                                                                                                                  -623        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  -624        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -625            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  -626            T t = elements[r];
                                                                                                                                                                                                                                                                                                                  -627            if (r != i)
                                                                                                                                                                                                                                                                                                                  -628                elements[r] = elements[i];
                                                                                                                                                                                                                                                                                                                  -629            elements[i] = t;
                                                                                                                                                                                                                                                                                                                  -630        }
                                                                                                                                                                                                                                                                                                                  -631        return elements;
                                                                                                                                                                                                                                                                                                                  -632    }
                                                                                                                                                                                                                                                                                                                  -633
                                                                                                                                                                                                                                                                                                                  -634    /**
                                                                                                                                                                                                                                                                                                                  -635     * Shuffle an array using the Fisher-Yates algorithm. DO NOT give the same array for both elements and
                                                                                                                                                                                                                                                                                                                  -636     * dest, since the prior contents of dest are rearranged before elements is used, and if they refer to the same
                                                                                                                                                                                                                                                                                                                  -637     * array, then you can end up with bizarre bugs where one previously-unique item shows up dozens of times. If
                                                                                                                                                                                                                                                                                                                  -638     * possible, create a new array with the same length as elements and pass it in as dest; the returned value can be
                                                                                                                                                                                                                                                                                                                  -639     * assigned to whatever you want and will have the same items as the newly-formed array.
                                                                                                                                                                                                                                                                                                                  -640     * <br>
                                                                                                                                                                                                                                                                                                                  -641     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  -642     *
                                                                                                                                                                                                                                                                                                                  -643     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -644     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -645     * @param dest     Where to put the shuffle. If it does not have the same length as {@code elements}, this will use the
                                                                                                                                                                                                                                                                                                                  -646     *                 randomPortion method of this class to fill the smaller dest. MUST NOT be the same array as elements!
                                                                                                                                                                                                                                                                                                                  -647     * @return {@code dest} after modifications
                                                                                                                                                                                                                                                                                                                  -648     */
                                                                                                                                                                                                                                                                                                                  -649    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  -650        if (dest.length != elements.length)
                                                                                                                                                                                                                                                                                                                  -651            return randomPortion(elements, dest);
                                                                                                                                                                                                                                                                                                                  -652        System.arraycopy(elements, 0, dest, 0, elements.length);
                                                                                                                                                                                                                                                                                                                  -653        shuffleInPlace(dest);
                                                                                                                                                                                                                                                                                                                  -654        return dest;
                                                                                                                                                                                                                                                                                                                  -655    }
                                                                                                                                                                                                                                                                                                                  -656
                                                                                                                                                                                                                                                                                                                  -657    /**
                                                                                                                                                                                                                                                                                                                  -658     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                                                                                                                                                                                  -659     *
                                                                                                                                                                                                                                                                                                                  -660     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -661     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -662     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  -663     */
                                                                                                                                                                                                                                                                                                                  -664    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  -665        return shuffle(elements, null);
                                                                                                                                                                                                                                                                                                                  -666    }
                                                                                                                                                                                                                                                                                                                  -667
                                                                                                                                                                                                                                                                                                                  -668    /**
                                                                                                                                                                                                                                                                                                                  -669     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm. The result
                                                                                                                                                                                                                                                                                                                  -670     * is allocated if {@code buf} is null or if {@code buf} isn't empty,
                                                                                                                                                                                                                                                                                                                  -671     * otherwise {@code elements} is poured into {@code buf}.
                                                                                                                                                                                                                                                                                                                  -672     *
                                                                                                                                                                                                                                                                                                                  -673     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  -674     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -675     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  -676     */
                                                                                                                                                                                                                                                                                                                  -677    public <T> ArrayList<T> shuffle(Collection<T> elements, /*@Nullable*/ ArrayList<T> buf) {
                                                                                                                                                                                                                                                                                                                  -678        final ArrayList<T> al;
                                                                                                                                                                                                                                                                                                                  -679        if (buf == null || !buf.isEmpty())
                                                                                                                                                                                                                                                                                                                  -680            al = new ArrayList<>(elements);
                                                                                                                                                                                                                                                                                                                  -681        else {
                                                                                                                                                                                                                                                                                                                  -682            al = buf;
                                                                                                                                                                                                                                                                                                                  -683            al.addAll(elements);
                                                                                                                                                                                                                                                                                                                  -684        }
                                                                                                                                                                                                                                                                                                                  -685        int n = al.size();
                                                                                                                                                                                                                                                                                                                  -686        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -687            Collections.swap(al, i + nextInt(n - i), i);
                                                                                                                                                                                                                                                                                                                  -688        }
                                                                                                                                                                                                                                                                                                                  -689        return al;
                                                                                                                                                                                                                                                                                                                  -690    }
                                                                                                                                                                                                                                                                                                                  -691
                                                                                                                                                                                                                                                                                                                  -692    /**
                                                                                                                                                                                                                                                                                                                  -693     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  -694     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  -695     *
                                                                                                                                                                                                                                                                                                                  -696     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  -697     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  -698     */
                                                                                                                                                                                                                                                                                                                  -699    public int[] randomOrdering(int length) {
                                                                                                                                                                                                                                                                                                                  -700        if (length <= 0)
                                                                                                                                                                                                                                                                                                                  -701            return new int[0];
                                                                                                                                                                                                                                                                                                                  -702        return randomOrdering(length, new int[length]);
                                                                                                                                                                                                                                                                                                                  -703    }
                                                                                                                                                                                                                                                                                                                  -704
                                                                                                                                                                                                                                                                                                                  -705    /**
                                                                                                                                                                                                                                                                                                                  -706     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive) and stores it in
                                                                                                                                                                                                                                                                                                                  -707     * the dest parameter, avoiding allocations.
                                                                                                                                                                                                                                                                                                                  -708     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  -709     *
                                                                                                                                                                                                                                                                                                                  -710     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  -711     * @param dest   the destination array; will be modified
                                                                                                                                                                                                                                                                                                                  -712     * @return dest, filled with a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  -713     */
                                                                                                                                                                                                                                                                                                                  -714    public int[] randomOrdering(int length, int[] dest) {
                                                                                                                                                                                                                                                                                                                  -715        if (dest == null) return null;
                                                                                                                                                                                                                                                                                                                  -716
                                                                                                                                                                                                                                                                                                                  -717        final int n = Math.min(length, dest.length);
                                                                                                                                                                                                                                                                                                                  -718        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  -719            dest[i] = i;
                                                                                                                                                                                                                                                                                                                  -720        }
                                                                                                                                                                                                                                                                                                                  -721        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -722            int r = i + nextIntHasty(n - i),
                                                                                                                                                                                                                                                                                                                  -723                    t = dest[r];
                                                                                                                                                                                                                                                                                                                  -724            if (r != i)
                                                                                                                                                                                                                                                                                                                  -725                dest[r] = dest[i];
                                                                                                                                                                                                                                                                                                                  -726            dest[i] = t;
                                                                                                                                                                                                                                                                                                                  -727        }
                                                                                                                                                                                                                                                                                                                  -728        return dest;
                                                                                                                                                                                                                                                                                                                  -729    }
                                                                                                                                                                                                                                                                                                                  -730
                                                                                                                                                                                                                                                                                                                  -731    /**
                                                                                                                                                                                                                                                                                                                  -732     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  -733     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  -734     * generating random indices for data's elements, but only as much as needed, assigning the copied section to output
                                                                                                                                                                                                                                                                                                                  -735     * and not modifying data.
                                                                                                                                                                                                                                                                                                                  -736     * <br>
                                                                                                                                                                                                                                                                                                                  -737     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  -738     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  -739     *
                                                                                                                                                                                                                                                                                                                  -740     * @param data   an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -741     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  -742     * @param <T>    can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  -743     * @return an array of T that has length equal to output's length and may contain unchanged elements (null if output
                                                                                                                                                                                                                                                                                                                  -744     * was empty) if data is shorter than output
                                                                                                                                                                                                                                                                                                                  -745     */
                                                                                                                                                                                                                                                                                                                  -746    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  -747        int length = data.length;
                                                                                                                                                                                                                                                                                                                  -748        int n = Math.min(length, output.length);
                                                                                                                                                                                                                                                                                                                  -749        int[] mapping = ArrayTools.range(n);
                                                                                                                                                                                                                                                                                                                  -750        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  -751            int r = nextIntHasty(length);
                                                                                                                                                                                                                                                                                                                  -752            output[i] = data[mapping[r]];
                                                                                                                                                                                                                                                                                                                  -753            mapping[r] = mapping[--length];
                                                                                                                                                                                                                                                                                                                  -754        }
                                                                                                                                                                                                                                                                                                                  -755
                                                                                                                                                                                                                                                                                                                  -756        return output;
                                                                                                                                                                                                                                                                                                                  -757    }
                                                                                                                                                                                                                                                                                                                  -758
                                                                                                                                                                                                                                                                                                                  -759    /**
                                                                                                                                                                                                                                                                                                                  -760     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  -761     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  -762     *
                                                                                                                                                                                                                                                                                                                  -763     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  -764     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  -765     * @param <T>   can be any non-primitive type
                                                                                                                                                                                                                                                                                                                  -766     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  -767     */
                                                                                                                                                                                                                                                                                                                  -768    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  -769        return shuffle(data).subList(0, Math.min(count, data.size()));
                                                                                                                                                                                                                                                                                                                  -770    }
                                                                                                                                                                                                                                                                                                                  -771
                                                                                                                                                                                                                                                                                                                  -772    /**
                                                                                                                                                                                                                                                                                                                  -773     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  -774     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  -775     *
                                                                                                                                                                                                                                                                                                                  -776     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  -777     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  -778     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  -779     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  -780     */
                                                                                                                                                                                                                                                                                                                  -781    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  -782        if (end <= start || start < 0)
                                                                                                                                                                                                                                                                                                                  -783            return new int[0];
                                                                                                                                                                                                                                                                                                                  -784
                                                                                                                                                                                                                                                                                                                  -785        int n = end - start;
                                                                                                                                                                                                                                                                                                                  -786        int[] data = new int[n];
                                                                                                                                                                                                                                                                                                                  -787
                                                                                                                                                                                                                                                                                                                  -788        for (int e = start, i = 0; e < end; e++) {
                                                                                                                                                                                                                                                                                                                  -789            data[i++] = e;
                                                                                                                                                                                                                                                                                                                  -790        }
                                                                                                                                                                                                                                                                                                                  -791
                                                                                                                                                                                                                                                                                                                  -792        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  -793            int r = i + nextInt(n - i), t = data[r];
                                                                                                                                                                                                                                                                                                                  -794            if (r != i)
                                                                                                                                                                                                                                                                                                                  -795                data[r] = data[i];
                                                                                                                                                                                                                                                                                                                  -796            data[i] = t;
                                                                                                                                                                                                                                                                                                                  -797        }
                                                                                                                                                                                                                                                                                                                  -798        int[] array = new int[Math.min(count, n)];
                                                                                                                                                                                                                                                                                                                  -799        System.arraycopy(data, 0, array, 0, Math.min(count, n));
                                                                                                                                                                                                                                                                                                                  -800        return array;
                                                                                                                                                                                                                                                                                                                  -801    }
                                                                                                                                                                                                                                                                                                                  -802
                                                                                                                                                                                                                                                                                                                  -803    /**
                                                                                                                                                                                                                                                                                                                  -804     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  -805     */
                                                                                                                                                                                                                                                                                                                  -806    public double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  -807        if (haveNextNextGaussian) {
                                                                                                                                                                                                                                                                                                                  -808            haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  -809            return nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  -810        } else {
                                                                                                                                                                                                                                                                                                                  -811            double v1, v2, s;
                                                                                                                                                                                                                                                                                                                  -812            do {
                                                                                                                                                                                                                                                                                                                  -813                v1 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  -814                v2 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  -815                s = v1 * v1 + v2 * v2;
                                                                                                                                                                                                                                                                                                                  -816            } while (s >= 1 || s == 0);
                                                                                                                                                                                                                                                                                                                  -817            double multiplier = Math.sqrt(-2 * Math.log(s) / s);
                                                                                                                                                                                                                                                                                                                  -818            nextNextGaussian = v2 * multiplier;
                                                                                                                                                                                                                                                                                                                  -819            haveNextNextGaussian = true;
                                                                                                                                                                                                                                                                                                                  -820            return v1 * multiplier;
                                                                                                                                                                                                                                                                                                                  -821        }
                                                                                                                                                                                                                                                                                                                  -822    }
                                                                                                                                                                                                                                                                                                                  -823
                                                                                                                                                                                                                                                                                                                  -824    /**
                                                                                                                                                                                                                                                                                                                  -825     * This returns a maximum of 0.9999999999999999 because that is the largest
                                                                                                                                                                                                                                                                                                                  -826     * Double value that is less than 1.0
                                                                                                                                                                                                                                                                                                                  -827     *
                                                                                                                                                                                                                                                                                                                  -828     * @return a value between 0 (inclusive) and 0.9999999999999999 (inclusive)
                                                                                                                                                                                                                                                                                                                  -829     */
                                                                                                                                                                                                                                                                                                                  -830    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  -831        return (random.nextLong() & 0x1fffffffffffffL) * DOUBLE_UNIT;
                                                                                                                                                                                                                                                                                                                  -832        // consider changing to this in a future version; it will break compatibility but should be fast/correct
                                                                                                                                                                                                                                                                                                                  -833        //return Double.longBitsToDouble(0x3FF0000000000000L | random.nextLong() >>> 12) - 1.0;
                                                                                                                                                                                                                                                                                                                  -834    }
                                                                                                                                                                                                                                                                                                                  -835
                                                                                                                                                                                                                                                                                                                  -836    /**
                                                                                                                                                                                                                                                                                                                  -837     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  -838     *
                                                                                                                                                                                                                                                                                                                  -839     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  -840     */
                                                                                                                                                                                                                                                                                                                  -841    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  -842        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  -843    }
                                                                                                                                                                                                                                                                                                                  -844
                                                                                                                                                                                                                                                                                                                  -845    /**
                                                                                                                                                                                                                                                                                                                  -846     * This returns a maximum of 0.99999994 because that is the largest Float
                                                                                                                                                                                                                                                                                                                  -847     * value that is less than 1.0f
                                                                                                                                                                                                                                                                                                                  -848     *
                                                                                                                                                                                                                                                                                                                  -849     * @return a value between 0 (inclusive) and 0.99999994 (inclusive)
                                                                                                                                                                                                                                                                                                                  -850     */
                                                                                                                                                                                                                                                                                                                  -851    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  -852        return next(24) * FLOAT_UNIT;
                                                                                                                                                                                                                                                                                                                  -853    }
                                                                                                                                                                                                                                                                                                                  -854
                                                                                                                                                                                                                                                                                                                  -855    /**
                                                                                                                                                                                                                                                                                                                  -856     * Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                                                                                                                                                                                  -857     *
                                                                                                                                                                                                                                                                                                                  -858     * @return a random boolean.
                                                                                                                                                                                                                                                                                                                  -859     */
                                                                                                                                                                                                                                                                                                                  -860    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  -861        return nextLong() < 0L;
                                                                                                                                                                                                                                                                                                                  -862    }
                                                                                                                                                                                                                                                                                                                  -863
                                                                                                                                                                                                                                                                                                                  -864    /**
                                                                                                                                                                                                                                                                                                                  -865     * Get a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  -866     *
                                                                                                                                                                                                                                                                                                                  -867     * @return a 64-bit random long.
                                                                                                                                                                                                                                                                                                                  -868     */
                                                                                                                                                                                                                                                                                                                  -869    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  -870        return random.nextLong();
                                                                                                                                                                                                                                                                                                                  -871    }
                                                                                                                                                                                                                                                                                                                  -872
                                                                                                                                                                                                                                                                                                                  -873    /**
                                                                                                                                                                                                                                                                                                                  -874     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -875     * negative.
                                                                                                                                                                                                                                                                                                                  -876     *
                                                                                                                                                                                                                                                                                                                  -877     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -878     * @return the found number
                                                                                                                                                                                                                                                                                                                  -879     */
                                                                                                                                                                                                                                                                                                                  -880    public long nextLong(final long bound) {
                                                                                                                                                                                                                                                                                                                  -881        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  -882        long threshold = (0x7fffffffffffffffL - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  -883        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  -884            long bits = random.nextLong() & 0x7fffffffffffffffL;
                                                                                                                                                                                                                                                                                                                  -885            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  -886                return bits % bound;
                                                                                                                                                                                                                                                                                                                  -887        }
                                                                                                                                                                                                                                                                                                                  -888    }
                                                                                                                                                                                                                                                                                                                  -889
                                                                                                                                                                                                                                                                                                                  -890    /**
                                                                                                                                                                                                                                                                                                                  -891     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  -892     * negative.
                                                                                                                                                                                                                                                                                                                  -893     *
                                                                                                                                                                                                                                                                                                                  -894     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  -895     * @return the found number
                                                                                                                                                                                                                                                                                                                  -896     */
                                                                                                                                                                                                                                                                                                                  -897    public int nextInt(final int bound) {
                                                                                                                                                                                                                                                                                                                  -898        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  -899        int threshold = (0x7fffffff - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  -900        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  -901            int bits = random.next(31);
                                                                                                                                                                                                                                                                                                                  -902            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  -903                return bits % bound;
                                                                                                                                                                                                                                                                                                                  -904        }
                                                                                                                                                                                                                                                                                                                  -905    }
                                                                                                                                                                                                                                                                                                                  -906
                                                                                                                                                                                                                                                                                                                  -907    /**
                                                                                                                                                                                                                                                                                                                  -908     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  -909     * Uses an aggressively optimized technique that has some bias, but mostly for values of
                                                                                                                                                                                                                                                                                                                  -910     * bound over 1 billion. This method is considered "hasty" since it should be faster than
                                                                                                                                                                                                                                                                                                                  -911     * nextInt() but gives up some statistical quality to do so. It also has undefined behavior
                                                                                                                                                                                                                                                                                                                  -912     * if bound is negative, though it will probably produce a negative number (just how
                                                                                                                                                                                                                                                                                                                  -913     * negative is an open question).
                                                                                                                                                                                                                                                                                                                  -914     * <br>
                                                                                                                                                                                                                                                                                                                  -915     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  -916     *
                                                                                                                                                                                                                                                                                                                  -917     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  -918     * @return the found number
                                                                                                                                                                                                                                                                                                                  -919     */
                                                                                                                                                                                                                                                                                                                  -920    public int nextIntHasty(final int bound) {
                                                                                                                                                                                                                                                                                                                  -921        return (int) ((bound * (random.nextLong() & 0x7FFFFFFFL)) >> 31);
                                                                                                                                                                                                                                                                                                                  -922    }
                                                                                                                                                                                                                                                                                                                  -923
                                                                                                                                                                                                                                                                                                                  -924    /**
                                                                                                                                                                                                                                                                                                                  -925     * Generates random bytes and places them into the given byte array, modifying it in-place.
                                                                                                                                                                                                                                                                                                                  -926     * The number of random bytes produced is equal to the length of the byte array. Unlike the
                                                                                                                                                                                                                                                                                                                  -927     * method in java.util.Random, this generates 8 bytes at a time, which can be more efficient
                                                                                                                                                                                                                                                                                                                  -928     * with many RandomnessSource types than the JDK's method that generates 4 bytes at a time.
                                                                                                                                                                                                                                                                                                                  -929     * <br>
                                                                                                                                                                                                                                                                                                                  -930     * Adapted from code in the JavaDocs of {@link Random#nextBytes(byte[])}.
                                                                                                                                                                                                                                                                                                                  +447                    int next = -1;
                                                                                                                                                                                                                                                                                                                  +448
                                                                                                                                                                                                                                                                                                                  +449                    @Override
                                                                                                                                                                                                                                                                                                                  +450                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  +451                        return next != start;
                                                                                                                                                                                                                                                                                                                  +452                    }
                                                                                                                                                                                                                                                                                                                  +453
                                                                                                                                                                                                                                                                                                                  +454                    @Override
                                                                                                                                                                                                                                                                                                                  +455                    public T next() {
                                                                                                                                                                                                                                                                                                                  +456                        if (next == start)
                                                                                                                                                                                                                                                                                                                  +457                            throw new NoSuchElementException("Iteration terminated; check hasNext() before next()");
                                                                                                                                                                                                                                                                                                                  +458                        if (next == -1)
                                                                                                                                                                                                                                                                                                                  +459                                        /* First call */
                                                                                                                                                                                                                                                                                                                  +460                            next = start;
                                                                                                                                                                                                                                                                                                                  +461                        final T result = list.get(next);
                                                                                                                                                                                                                                                                                                                  +462                        if (next == sz - 1)
                                                                                                                                                                                                                                                                                                                  +463                                        /*
                                                                                                                                                                                                                                                                                                                  +464                                         * Reached the list's end, let's continue from the list's
                                                                                                                                                                                                                                                                                                                  +465                                         * left.
                                                                                                                                                                                                                                                                                                                  +466                                         */
                                                                                                                                                                                                                                                                                                                  +467                            next = 0;
                                                                                                                                                                                                                                                                                                                  +468                        else
                                                                                                                                                                                                                                                                                                                  +469                            next++;
                                                                                                                                                                                                                                                                                                                  +470                        return result;
                                                                                                                                                                                                                                                                                                                  +471                    }
                                                                                                                                                                                                                                                                                                                  +472
                                                                                                                                                                                                                                                                                                                  +473                    @Override
                                                                                                                                                                                                                                                                                                                  +474                    public void remove() {
                                                                                                                                                                                                                                                                                                                  +475                        throw new UnsupportedOperationException("Remove is not supported from a randomStartIterable");
                                                                                                                                                                                                                                                                                                                  +476                    }
                                                                                                                                                                                                                                                                                                                  +477
                                                                                                                                                                                                                                                                                                                  +478                    @Override
                                                                                                                                                                                                                                                                                                                  +479                    public String toString() {
                                                                                                                                                                                                                                                                                                                  +480                        return "RandomStartIterator at index " + next;
                                                                                                                                                                                                                                                                                                                  +481                    }
                                                                                                                                                                                                                                                                                                                  +482                };
                                                                                                                                                                                                                                                                                                                  +483            }
                                                                                                                                                                                                                                                                                                                  +484        };
                                                                                                                                                                                                                                                                                                                  +485    }
                                                                                                                                                                                                                                                                                                                  +486
                                                                                                                                                                                                                                                                                                                  +487    /**
                                                                                                                                                                                                                                                                                                                  +488     * Use that to get random cells in a rectangular map.
                                                                                                                                                                                                                                                                                                                  +489     *
                                                                                                                                                                                                                                                                                                                  +490     * @param width  The map's width (bounds the x-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  +491     * @param height The map's height (bounds the y-coordinate in returned coords).
                                                                                                                                                                                                                                                                                                                  +492     * @param size   The number of elements in the returned iterable or anything
                                                                                                                                                                                                                                                                                                                  +493     *               negative for no bound (in which case the iterator is infinite, it's
                                                                                                                                                                                                                                                                                                                  +494     *               up to you to bound your iteration).
                                                                                                                                                                                                                                                                                                                  +495     * @return An iterable that returns random cells in the rectangle (0,0)
                                                                                                                                                                                                                                                                                                                  +496     * (inclusive) .. (width, height) (exclusive).
                                                                                                                                                                                                                                                                                                                  +497     */
                                                                                                                                                                                                                                                                                                                  +498    public Iterable<Coord> getRandomCellsIterable(final int width, final int height, final int size) {
                                                                                                                                                                                                                                                                                                                  +499        return new Iterable<Coord>() {
                                                                                                                                                                                                                                                                                                                  +500            @Override
                                                                                                                                                                                                                                                                                                                  +501            public Iterator<Coord> iterator() {
                                                                                                                                                                                                                                                                                                                  +502                return new Iterator<Coord>() {
                                                                                                                                                                                                                                                                                                                  +503
                                                                                                                                                                                                                                                                                                                  +504                    /**
                                                                                                                                                                                                                                                                                                                  +505                     * The number of elements returned so far
                                                                                                                                                                                                                                                                                                                  +506                     */
                                                                                                                                                                                                                                                                                                                  +507                    int returned = 0;
                                                                                                                                                                                                                                                                                                                  +508
                                                                                                                                                                                                                                                                                                                  +509                    @Override
                                                                                                                                                                                                                                                                                                                  +510                    public boolean hasNext() {
                                                                                                                                                                                                                                                                                                                  +511                        return size < 0 || returned < size;
                                                                                                                                                                                                                                                                                                                  +512                    }
                                                                                                                                                                                                                                                                                                                  +513
                                                                                                                                                                                                                                                                                                                  +514                    @Override
                                                                                                                                                                                                                                                                                                                  +515                    public Coord next() {
                                                                                                                                                                                                                                                                                                                  +516                        if (!hasNext())
                                                                                                                                                                                                                                                                                                                  +517                            throw new NoSuchElementException();
                                                                                                                                                                                                                                                                                                                  +518                        returned++;
                                                                                                                                                                                                                                                                                                                  +519                        return nextCoord(width, height);
                                                                                                                                                                                                                                                                                                                  +520                    }
                                                                                                                                                                                                                                                                                                                  +521
                                                                                                                                                                                                                                                                                                                  +522                    @Override
                                                                                                                                                                                                                                                                                                                  +523                    public void remove() {
                                                                                                                                                                                                                                                                                                                  +524                        throw new UnsupportedOperationException();
                                                                                                                                                                                                                                                                                                                  +525                    }
                                                                                                                                                                                                                                                                                                                  +526                };
                                                                                                                                                                                                                                                                                                                  +527            }
                                                                                                                                                                                                                                                                                                                  +528        };
                                                                                                                                                                                                                                                                                                                  +529    }
                                                                                                                                                                                                                                                                                                                  +530
                                                                                                                                                                                                                                                                                                                  +531    /**
                                                                                                                                                                                                                                                                                                                  +532     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  +533     * random order, with the array containing {@code width * height} items.
                                                                                                                                                                                                                                                                                                                  +534     *
                                                                                                                                                                                                                                                                                                                  +535     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  +536     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  +537     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  +538     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  +539     * @return an array containing {@code width * height} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  +540     */
                                                                                                                                                                                                                                                                                                                  +541    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height) {
                                                                                                                                                                                                                                                                                                                  +542        if (width <= 0 || height <= 0)
                                                                                                                                                                                                                                                                                                                  +543            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  +544        return getRandomUniqueCells(startX, startY, width, height, new Coord[width * height]);
                                                                                                                                                                                                                                                                                                                  +545    }
                                                                                                                                                                                                                                                                                                                  +546
                                                                                                                                                                                                                                                                                                                  +547    /**
                                                                                                                                                                                                                                                                                                                  +548     * Gets an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height) exclusive, in a
                                                                                                                                                                                                                                                                                                                  +549     * random order, with the array containing {@code Math.min(width * height, size)} items. If size is less than width
                                                                                                                                                                                                                                                                                                                  +550     * times height, then not all Coords in the space will be used.
                                                                                                                                                                                                                                                                                                                  +551     *
                                                                                                                                                                                                                                                                                                                  +552     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  +553     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  +554     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  +555     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  +556     * @param size   the size of the array to return; only matters if it is smaller than {@code width * height}
                                                                                                                                                                                                                                                                                                                  +557     * @return an array containing {@code Math.min(width * height, size)} Coord items in random order, inside the given bounds
                                                                                                                                                                                                                                                                                                                  +558     */
                                                                                                                                                                                                                                                                                                                  +559    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  +560                                        final int size) {
                                                                                                                                                                                                                                                                                                                  +561        if (width <= 0 || height <= 0 || size <= 0)
                                                                                                                                                                                                                                                                                                                  +562            return new Coord[0];
                                                                                                                                                                                                                                                                                                                  +563        return getRandomUniqueCells(startX, startY, width, height, new Coord[Math.min(width * height, size)]);
                                                                                                                                                                                                                                                                                                                  +564    }
                                                                                                                                                                                                                                                                                                                  +565
                                                                                                                                                                                                                                                                                                                  +566    /**
                                                                                                                                                                                                                                                                                                                  +567     * Assigns to dest an array of unique Coords, from (startX,startY) inclusive to (startX+width,startY+height)
                                                                                                                                                                                                                                                                                                                  +568     * exclusive, in a random order, with dest after this is called containing the lesser of {@code width * height} or
                                                                                                                                                                                                                                                                                                                  +569     * {@code dest.length} items. This will not allocate a new array for dest, but will create a temporary int array for
                                                                                                                                                                                                                                                                                                                  +570     * handling the shuffle.
                                                                                                                                                                                                                                                                                                                  +571     *
                                                                                                                                                                                                                                                                                                                  +572     * @param startX the inclusive starting x position
                                                                                                                                                                                                                                                                                                                  +573     * @param startY the inclusive starting y position
                                                                                                                                                                                                                                                                                                                  +574     * @param width  the width of the space to place Coords in, extending from startX
                                                                                                                                                                                                                                                                                                                  +575     * @param height the height of the space to place Coords in, extending from startY
                                                                                                                                                                                                                                                                                                                  +576     * @param dest   a Coord array that will be modified to contain randomly-ordered Coords, but will not be resized
                                                                                                                                                                                                                                                                                                                  +577     * @return dest, now with up to its first {@code width * height} items assigned to random Coords inside the given bounds
                                                                                                                                                                                                                                                                                                                  +578     */
                                                                                                                                                                                                                                                                                                                  +579    public Coord[] getRandomUniqueCells(final int startX, final int startY, final int width, final int height,
                                                                                                                                                                                                                                                                                                                  +580                                        final Coord[] dest) {
                                                                                                                                                                                                                                                                                                                  +581        if (width <= 0 || height <= 0 || dest == null || dest.length <= 0)
                                                                                                                                                                                                                                                                                                                  +582            return dest;
                                                                                                                                                                                                                                                                                                                  +583        int[] o = randomOrdering(width * height);
                                                                                                                                                                                                                                                                                                                  +584        for (int i = 0; i < o.length && i < dest.length; i++) {
                                                                                                                                                                                                                                                                                                                  +585            dest[i] = Coord.get(startX + o[i] % width, startY + o[i] / width);
                                                                                                                                                                                                                                                                                                                  +586        }
                                                                                                                                                                                                                                                                                                                  +587        return dest;
                                                                                                                                                                                                                                                                                                                  +588    }
                                                                                                                                                                                                                                                                                                                  +589
                                                                                                                                                                                                                                                                                                                  +590    /**
                                                                                                                                                                                                                                                                                                                  +591     * Shuffle an array using the Fisher-Yates algorithm and returns a shuffled copy.
                                                                                                                                                                                                                                                                                                                  +592     * GWT-compatible since GWT 2.8.0, which is the default if you use libGDX 1.9.5 or higher.
                                                                                                                                                                                                                                                                                                                  +593     * <br>
                                                                                                                                                                                                                                                                                                                  +594     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  +595     *
                                                                                                                                                                                                                                                                                                                  +596     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +597     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +598     * @return a shuffled copy of elements
                                                                                                                                                                                                                                                                                                                  +599     */
                                                                                                                                                                                                                                                                                                                  +600    public <T> T[] shuffle(final T[] elements) {
                                                                                                                                                                                                                                                                                                                  +601        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  +602        final T[] array = Arrays.copyOf(elements, n);
                                                                                                                                                                                                                                                                                                                  +603        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +604            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  +605            T t = array[r];
                                                                                                                                                                                                                                                                                                                  +606            if (r != i)
                                                                                                                                                                                                                                                                                                                  +607                array[r] = array[i];
                                                                                                                                                                                                                                                                                                                  +608            array[i] = t;
                                                                                                                                                                                                                                                                                                                  +609        }
                                                                                                                                                                                                                                                                                                                  +610        return array;
                                                                                                                                                                                                                                                                                                                  +611    }
                                                                                                                                                                                                                                                                                                                  +612
                                                                                                                                                                                                                                                                                                                  +613    /**
                                                                                                                                                                                                                                                                                                                  +614     * Shuffles an array in place using the Fisher-Yates algorithm.
                                                                                                                                                                                                                                                                                                                  +615     * If you don't want the array modified, use {@link #shuffle(Object[], Object[])}.
                                                                                                                                                                                                                                                                                                                  +616     * Unlike {@link #shuffle(Object[])}, this is GWT-compatible.
                                                                                                                                                                                                                                                                                                                  +617     * <br>
                                                                                                                                                                                                                                                                                                                  +618     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  +619     *
                                                                                                                                                                                                                                                                                                                  +620     * @param elements an array of T; <b>will</b> be modified
                                                                                                                                                                                                                                                                                                                  +621     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +622     * @return elements after shuffling it in-place
                                                                                                                                                                                                                                                                                                                  +623     */
                                                                                                                                                                                                                                                                                                                  +624    public <T> T[] shuffleInPlace(T[] elements) {
                                                                                                                                                                                                                                                                                                                  +625        final int n = elements.length;
                                                                                                                                                                                                                                                                                                                  +626        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +627            int r = i + nextIntHasty(n - i);
                                                                                                                                                                                                                                                                                                                  +628            T t = elements[r];
                                                                                                                                                                                                                                                                                                                  +629            if (r != i)
                                                                                                                                                                                                                                                                                                                  +630                elements[r] = elements[i];
                                                                                                                                                                                                                                                                                                                  +631            elements[i] = t;
                                                                                                                                                                                                                                                                                                                  +632        }
                                                                                                                                                                                                                                                                                                                  +633        return elements;
                                                                                                                                                                                                                                                                                                                  +634    }
                                                                                                                                                                                                                                                                                                                  +635
                                                                                                                                                                                                                                                                                                                  +636    /**
                                                                                                                                                                                                                                                                                                                  +637     * Shuffle an array using the Fisher-Yates algorithm. DO NOT give the same array for both elements and
                                                                                                                                                                                                                                                                                                                  +638     * dest, since the prior contents of dest are rearranged before elements is used, and if they refer to the same
                                                                                                                                                                                                                                                                                                                  +639     * array, then you can end up with bizarre bugs where one previously-unique item shows up dozens of times. If
                                                                                                                                                                                                                                                                                                                  +640     * possible, create a new array with the same length as elements and pass it in as dest; the returned value can be
                                                                                                                                                                                                                                                                                                                  +641     * assigned to whatever you want and will have the same items as the newly-formed array.
                                                                                                                                                                                                                                                                                                                  +642     * <br>
                                                                                                                                                                                                                                                                                                                  +643     * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
                                                                                                                                                                                                                                                                                                                  +644     *
                                                                                                                                                                                                                                                                                                                  +645     * @param elements an array of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +646     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +647     * @param dest     Where to put the shuffle. If it does not have the same length as {@code elements}, this will use the
                                                                                                                                                                                                                                                                                                                  +648     *                 randomPortion method of this class to fill the smaller dest. MUST NOT be the same array as elements!
                                                                                                                                                                                                                                                                                                                  +649     * @return {@code dest} after modifications
                                                                                                                                                                                                                                                                                                                  +650     */
                                                                                                                                                                                                                                                                                                                  +651    public <T> T[] shuffle(T[] elements, T[] dest) {
                                                                                                                                                                                                                                                                                                                  +652        if (dest.length != elements.length)
                                                                                                                                                                                                                                                                                                                  +653            return randomPortion(elements, dest);
                                                                                                                                                                                                                                                                                                                  +654        System.arraycopy(elements, 0, dest, 0, elements.length);
                                                                                                                                                                                                                                                                                                                  +655        shuffleInPlace(dest);
                                                                                                                                                                                                                                                                                                                  +656        return dest;
                                                                                                                                                                                                                                                                                                                  +657    }
                                                                                                                                                                                                                                                                                                                  +658
                                                                                                                                                                                                                                                                                                                  +659    /**
                                                                                                                                                                                                                                                                                                                  +660     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm and returns an ArrayList of T.
                                                                                                                                                                                                                                                                                                                  +661     *
                                                                                                                                                                                                                                                                                                                  +662     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +663     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +664     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  +665     */
                                                                                                                                                                                                                                                                                                                  +666    public <T> ArrayList<T> shuffle(Collection<T> elements) {
                                                                                                                                                                                                                                                                                                                  +667        return shuffle(elements, null);
                                                                                                                                                                                                                                                                                                                  +668    }
                                                                                                                                                                                                                                                                                                                  +669
                                                                                                                                                                                                                                                                                                                  +670    /**
                                                                                                                                                                                                                                                                                                                  +671     * Shuffles a {@link Collection} of T using the Fisher-Yates algorithm. The result
                                                                                                                                                                                                                                                                                                                  +672     * is allocated if {@code buf} is null or if {@code buf} isn't empty,
                                                                                                                                                                                                                                                                                                                  +673     * otherwise {@code elements} is poured into {@code buf}.
                                                                                                                                                                                                                                                                                                                  +674     *
                                                                                                                                                                                                                                                                                                                  +675     * @param elements a Collection of T; will not be modified
                                                                                                                                                                                                                                                                                                                  +676     * @param <T>      can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +677     * @return a shuffled ArrayList containing the whole of elements in pseudo-random order.
                                                                                                                                                                                                                                                                                                                  +678     */
                                                                                                                                                                                                                                                                                                                  +679    public <T> ArrayList<T> shuffle(Collection<T> elements, /*@Nullable*/ ArrayList<T> buf) {
                                                                                                                                                                                                                                                                                                                  +680        final ArrayList<T> al;
                                                                                                                                                                                                                                                                                                                  +681        if (buf == null || !buf.isEmpty())
                                                                                                                                                                                                                                                                                                                  +682            al = new ArrayList<>(elements);
                                                                                                                                                                                                                                                                                                                  +683        else {
                                                                                                                                                                                                                                                                                                                  +684            al = buf;
                                                                                                                                                                                                                                                                                                                  +685            al.addAll(elements);
                                                                                                                                                                                                                                                                                                                  +686        }
                                                                                                                                                                                                                                                                                                                  +687        int n = al.size();
                                                                                                                                                                                                                                                                                                                  +688        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +689            Collections.swap(al, i + nextInt(n - i), i);
                                                                                                                                                                                                                                                                                                                  +690        }
                                                                                                                                                                                                                                                                                                                  +691        return al;
                                                                                                                                                                                                                                                                                                                  +692    }
                                                                                                                                                                                                                                                                                                                  +693
                                                                                                                                                                                                                                                                                                                  +694    /**
                                                                                                                                                                                                                                                                                                                  +695     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive).
                                                                                                                                                                                                                                                                                                                  +696     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  +697     *
                                                                                                                                                                                                                                                                                                                  +698     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  +699     * @return a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  +700     */
                                                                                                                                                                                                                                                                                                                  +701    public int[] randomOrdering(int length) {
                                                                                                                                                                                                                                                                                                                  +702        if (length <= 0)
                                                                                                                                                                                                                                                                                                                  +703            return new int[0];
                                                                                                                                                                                                                                                                                                                  +704        return randomOrdering(length, new int[length]);
                                                                                                                                                                                                                                                                                                                  +705    }
                                                                                                                                                                                                                                                                                                                  +706
                                                                                                                                                                                                                                                                                                                  +707    /**
                                                                                                                                                                                                                                                                                                                  +708     * Generates a random permutation of the range from 0 (inclusive) to length (exclusive) and stores it in
                                                                                                                                                                                                                                                                                                                  +709     * the dest parameter, avoiding allocations.
                                                                                                                                                                                                                                                                                                                  +710     * Useful for passing to OrderedMap or OrderedSet's reorder() methods.
                                                                                                                                                                                                                                                                                                                  +711     *
                                                                                                                                                                                                                                                                                                                  +712     * @param length the size of the ordering to produce
                                                                                                                                                                                                                                                                                                                  +713     * @param dest   the destination array; will be modified
                                                                                                                                                                                                                                                                                                                  +714     * @return dest, filled with a random ordering containing all ints from 0 to length (exclusive)
                                                                                                                                                                                                                                                                                                                  +715     */
                                                                                                                                                                                                                                                                                                                  +716    public int[] randomOrdering(int length, int[] dest) {
                                                                                                                                                                                                                                                                                                                  +717        if (dest == null) return null;
                                                                                                                                                                                                                                                                                                                  +718
                                                                                                                                                                                                                                                                                                                  +719        final int n = Math.min(length, dest.length);
                                                                                                                                                                                                                                                                                                                  +720        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  +721            dest[i] = i;
                                                                                                                                                                                                                                                                                                                  +722        }
                                                                                                                                                                                                                                                                                                                  +723        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +724            int r = i + nextIntHasty(n - i),
                                                                                                                                                                                                                                                                                                                  +725                    t = dest[r];
                                                                                                                                                                                                                                                                                                                  +726            if (r != i)
                                                                                                                                                                                                                                                                                                                  +727                dest[r] = dest[i];
                                                                                                                                                                                                                                                                                                                  +728            dest[i] = t;
                                                                                                                                                                                                                                                                                                                  +729        }
                                                                                                                                                                                                                                                                                                                  +730        return dest;
                                                                                                                                                                                                                                                                                                                  +731    }
                                                                                                                                                                                                                                                                                                                  +732
                                                                                                                                                                                                                                                                                                                  +733    /**
                                                                                                                                                                                                                                                                                                                  +734     * Gets a random portion of data (an array), assigns that portion to output (an array) so that it fills as much as
                                                                                                                                                                                                                                                                                                                  +735     * it can, and then returns output. Will only use a given position in the given data at most once; does this by
                                                                                                                                                                                                                                                                                                                  +736     * generating random indices for data's elements, but only as much as needed, assigning the copied section to output
                                                                                                                                                                                                                                                                                                                  +737     * and not modifying data.
                                                                                                                                                                                                                                                                                                                  +738     * <br>
                                                                                                                                                                                                                                                                                                                  +739     * Based on http://stackoverflow.com/a/21460179 , credit to Vincent van der Weele; modifications were made to avoid
                                                                                                                                                                                                                                                                                                                  +740     * copying or creating a new generic array (a problem on GWT).
                                                                                                                                                                                                                                                                                                                  +741     *
                                                                                                                                                                                                                                                                                                                  +742     * @param data   an array of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +743     * @param output an array of T that will be overwritten; should always be instantiated with the portion length
                                                                                                                                                                                                                                                                                                                  +744     * @param <T>    can be any non-primitive type.
                                                                                                                                                                                                                                                                                                                  +745     * @return an array of T that has length equal to output's length and may contain unchanged elements (null if output
                                                                                                                                                                                                                                                                                                                  +746     * was empty) if data is shorter than output
                                                                                                                                                                                                                                                                                                                  +747     */
                                                                                                                                                                                                                                                                                                                  +748    public <T> T[] randomPortion(T[] data, T[] output) {
                                                                                                                                                                                                                                                                                                                  +749        int length = data.length;
                                                                                                                                                                                                                                                                                                                  +750        int n = Math.min(length, output.length);
                                                                                                                                                                                                                                                                                                                  +751        int[] mapping = ArrayTools.range(n);
                                                                                                                                                                                                                                                                                                                  +752        for (int i = 0; i < n; i++) {
                                                                                                                                                                                                                                                                                                                  +753            int r = nextIntHasty(length);
                                                                                                                                                                                                                                                                                                                  +754            output[i] = data[mapping[r]];
                                                                                                                                                                                                                                                                                                                  +755            mapping[r] = mapping[--length];
                                                                                                                                                                                                                                                                                                                  +756        }
                                                                                                                                                                                                                                                                                                                  +757
                                                                                                                                                                                                                                                                                                                  +758        return output;
                                                                                                                                                                                                                                                                                                                  +759    }
                                                                                                                                                                                                                                                                                                                  +760
                                                                                                                                                                                                                                                                                                                  +761    /**
                                                                                                                                                                                                                                                                                                                  +762     * Gets a random portion of a List and returns it as a new List. Will only use a given position in the given
                                                                                                                                                                                                                                                                                                                  +763     * List at most once; does this by shuffling a copy of the List and getting a section of it.
                                                                                                                                                                                                                                                                                                                  +764     *
                                                                                                                                                                                                                                                                                                                  +765     * @param data  a List of T; will not be modified.
                                                                                                                                                                                                                                                                                                                  +766     * @param count the non-negative number of elements to randomly take from data
                                                                                                                                                                                                                                                                                                                  +767     * @param <T>   can be any non-primitive type
                                                                                                                                                                                                                                                                                                                  +768     * @return a List of T that has length equal to the smaller of count or data.length
                                                                                                                                                                                                                                                                                                                  +769     */
                                                                                                                                                                                                                                                                                                                  +770    public <T> List<T> randomPortion(List<T> data, int count) {
                                                                                                                                                                                                                                                                                                                  +771        return shuffle(data).subList(0, Math.min(count, data.size()));
                                                                                                                                                                                                                                                                                                                  +772    }
                                                                                                                                                                                                                                                                                                                  +773
                                                                                                                                                                                                                                                                                                                  +774    /**
                                                                                                                                                                                                                                                                                                                  +775     * Gets a random subrange of the non-negative ints from start (inclusive) to end (exclusive), using count elements.
                                                                                                                                                                                                                                                                                                                  +776     * May return an empty array if the parameters are invalid (end is less than/equal to start, or start is negative).
                                                                                                                                                                                                                                                                                                                  +777     *
                                                                                                                                                                                                                                                                                                                  +778     * @param start the start of the range of numbers to potentially use (inclusive)
                                                                                                                                                                                                                                                                                                                  +779     * @param end   the end of the range of numbers to potentially use (exclusive)
                                                                                                                                                                                                                                                                                                                  +780     * @param count the total number of elements to use; will be less if the range is smaller than count
                                                                                                                                                                                                                                                                                                                  +781     * @return an int array that contains at most one of each number in the range
                                                                                                                                                                                                                                                                                                                  +782     */
                                                                                                                                                                                                                                                                                                                  +783    public int[] randomRange(int start, int end, int count) {
                                                                                                                                                                                                                                                                                                                  +784        if (end <= start || start < 0)
                                                                                                                                                                                                                                                                                                                  +785            return new int[0];
                                                                                                                                                                                                                                                                                                                  +786
                                                                                                                                                                                                                                                                                                                  +787        int n = end - start;
                                                                                                                                                                                                                                                                                                                  +788        int[] data = new int[n];
                                                                                                                                                                                                                                                                                                                  +789
                                                                                                                                                                                                                                                                                                                  +790        for (int e = start, i = 0; e < end; e++) {
                                                                                                                                                                                                                                                                                                                  +791            data[i++] = e;
                                                                                                                                                                                                                                                                                                                  +792        }
                                                                                                                                                                                                                                                                                                                  +793
                                                                                                                                                                                                                                                                                                                  +794        for (int i = 0; i < n - 1; i++) {
                                                                                                                                                                                                                                                                                                                  +795            int r = i + nextInt(n - i), t = data[r];
                                                                                                                                                                                                                                                                                                                  +796            if (r != i)
                                                                                                                                                                                                                                                                                                                  +797                data[r] = data[i];
                                                                                                                                                                                                                                                                                                                  +798            data[i] = t;
                                                                                                                                                                                                                                                                                                                  +799        }
                                                                                                                                                                                                                                                                                                                  +800        int[] array = new int[Math.min(count, n)];
                                                                                                                                                                                                                                                                                                                  +801        System.arraycopy(data, 0, array, 0, Math.min(count, n));
                                                                                                                                                                                                                                                                                                                  +802        return array;
                                                                                                                                                                                                                                                                                                                  +803    }
                                                                                                                                                                                                                                                                                                                  +804
                                                                                                                                                                                                                                                                                                                  +805    /**
                                                                                                                                                                                                                                                                                                                  +806     * @return a value from the gaussian distribution
                                                                                                                                                                                                                                                                                                                  +807     */
                                                                                                                                                                                                                                                                                                                  +808    public double nextGaussian() {
                                                                                                                                                                                                                                                                                                                  +809        if (haveNextNextGaussian) {
                                                                                                                                                                                                                                                                                                                  +810            haveNextNextGaussian = false;
                                                                                                                                                                                                                                                                                                                  +811            return nextNextGaussian;
                                                                                                                                                                                                                                                                                                                  +812        } else {
                                                                                                                                                                                                                                                                                                                  +813            double v1, v2, s;
                                                                                                                                                                                                                                                                                                                  +814            do {
                                                                                                                                                                                                                                                                                                                  +815                v1 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  +816                v2 = 2 * nextDouble() - 1; // between -1 and 1
                                                                                                                                                                                                                                                                                                                  +817                s = v1 * v1 + v2 * v2;
                                                                                                                                                                                                                                                                                                                  +818            } while (s >= 1 || s == 0);
                                                                                                                                                                                                                                                                                                                  +819            double multiplier = Math.sqrt(-2 * Math.log(s) / s);
                                                                                                                                                                                                                                                                                                                  +820            nextNextGaussian = v2 * multiplier;
                                                                                                                                                                                                                                                                                                                  +821            haveNextNextGaussian = true;
                                                                                                                                                                                                                                                                                                                  +822            return v1 * multiplier;
                                                                                                                                                                                                                                                                                                                  +823        }
                                                                                                                                                                                                                                                                                                                  +824    }
                                                                                                                                                                                                                                                                                                                  +825
                                                                                                                                                                                                                                                                                                                  +826    /**
                                                                                                                                                                                                                                                                                                                  +827     * This returns a maximum of 0.9999999999999999 because that is the largest
                                                                                                                                                                                                                                                                                                                  +828     * Double value that is less than 1.0
                                                                                                                                                                                                                                                                                                                  +829     *
                                                                                                                                                                                                                                                                                                                  +830     * @return a value between 0 (inclusive) and 0.9999999999999999 (inclusive)
                                                                                                                                                                                                                                                                                                                  +831     */
                                                                                                                                                                                                                                                                                                                  +832    public double nextDouble() {
                                                                                                                                                                                                                                                                                                                  +833        return (random.nextLong() & 0x1fffffffffffffL) * DOUBLE_UNIT;
                                                                                                                                                                                                                                                                                                                  +834        // consider changing to this in a future version; it will break compatibility but should be fast/correct
                                                                                                                                                                                                                                                                                                                  +835        //return Double.longBitsToDouble(0x3FF0000000000000L | random.nextLong() >>> 12) - 1.0;
                                                                                                                                                                                                                                                                                                                  +836    }
                                                                                                                                                                                                                                                                                                                  +837
                                                                                                                                                                                                                                                                                                                  +838    /**
                                                                                                                                                                                                                                                                                                                  +839     * This returns a random double between 0.0 (inclusive) and max (exclusive).
                                                                                                                                                                                                                                                                                                                  +840     *
                                                                                                                                                                                                                                                                                                                  +841     * @return a value between 0 (inclusive) and max (exclusive)
                                                                                                                                                                                                                                                                                                                  +842     */
                                                                                                                                                                                                                                                                                                                  +843    public double nextDouble(double max) {
                                                                                                                                                                                                                                                                                                                  +844        return nextDouble() * max;
                                                                                                                                                                                                                                                                                                                  +845    }
                                                                                                                                                                                                                                                                                                                  +846
                                                                                                                                                                                                                                                                                                                  +847    /**
                                                                                                                                                                                                                                                                                                                  +848     * This returns a maximum of 0.99999994 because that is the largest Float
                                                                                                                                                                                                                                                                                                                  +849     * value that is less than 1.0f
                                                                                                                                                                                                                                                                                                                  +850     *
                                                                                                                                                                                                                                                                                                                  +851     * @return a value between 0 (inclusive) and 0.99999994 (inclusive)
                                                                                                                                                                                                                                                                                                                  +852     */
                                                                                                                                                                                                                                                                                                                  +853    public float nextFloat() {
                                                                                                                                                                                                                                                                                                                  +854        return next(24) * FLOAT_UNIT;
                                                                                                                                                                                                                                                                                                                  +855    }
                                                                                                                                                                                                                                                                                                                  +856
                                                                                                                                                                                                                                                                                                                  +857    /**
                                                                                                                                                                                                                                                                                                                  +858     * Get a random bit of state, interpreted as true or false with approximately equal likelihood.
                                                                                                                                                                                                                                                                                                                  +859     *
                                                                                                                                                                                                                                                                                                                  +860     * @return a random boolean.
                                                                                                                                                                                                                                                                                                                  +861     */
                                                                                                                                                                                                                                                                                                                  +862    public boolean nextBoolean() {
                                                                                                                                                                                                                                                                                                                  +863        return nextLong() < 0L;
                                                                                                                                                                                                                                                                                                                  +864    }
                                                                                                                                                                                                                                                                                                                  +865
                                                                                                                                                                                                                                                                                                                  +866    /**
                                                                                                                                                                                                                                                                                                                  +867     * Get a random long between Long.MIN_VALUE to Long.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  +868     *
                                                                                                                                                                                                                                                                                                                  +869     * @return a 64-bit random long.
                                                                                                                                                                                                                                                                                                                  +870     */
                                                                                                                                                                                                                                                                                                                  +871    public long nextLong() {
                                                                                                                                                                                                                                                                                                                  +872        return random.nextLong();
                                                                                                                                                                                                                                                                                                                  +873    }
                                                                                                                                                                                                                                                                                                                  +874
                                                                                                                                                                                                                                                                                                                  +875    /**
                                                                                                                                                                                                                                                                                                                  +876     * Returns a random long below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +877     * negative.
                                                                                                                                                                                                                                                                                                                  +878     *
                                                                                                                                                                                                                                                                                                                  +879     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +880     * @return the found number
                                                                                                                                                                                                                                                                                                                  +881     */
                                                                                                                                                                                                                                                                                                                  +882    public long nextLong(final long bound) {
                                                                                                                                                                                                                                                                                                                  +883        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  +884        long threshold = (0x7fffffffffffffffL - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  +885        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  +886            long bits = random.nextLong() & 0x7fffffffffffffffL;
                                                                                                                                                                                                                                                                                                                  +887            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  +888                return bits % bound;
                                                                                                                                                                                                                                                                                                                  +889        }
                                                                                                                                                                                                                                                                                                                  +890    }
                                                                                                                                                                                                                                                                                                                  +891
                                                                                                                                                                                                                                                                                                                  +892    /**
                                                                                                                                                                                                                                                                                                                  +893     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0 or
                                                                                                                                                                                                                                                                                                                  +894     * negative.
                                                                                                                                                                                                                                                                                                                  +895     *
                                                                                                                                                                                                                                                                                                                  +896     * @param bound the upper bound (exclusive)
                                                                                                                                                                                                                                                                                                                  +897     * @return the found number
                                                                                                                                                                                                                                                                                                                  +898     */
                                                                                                                                                                                                                                                                                                                  +899    public int nextInt(final int bound) {
                                                                                                                                                                                                                                                                                                                  +900        if (bound <= 0) return 0;
                                                                                                                                                                                                                                                                                                                  +901        int threshold = (0x7fffffff - bound + 1) % bound;
                                                                                                                                                                                                                                                                                                                  +902        for (; ; ) {
                                                                                                                                                                                                                                                                                                                  +903            int bits = random.next(31);
                                                                                                                                                                                                                                                                                                                  +904            if (bits >= threshold)
                                                                                                                                                                                                                                                                                                                  +905                return bits % bound;
                                                                                                                                                                                                                                                                                                                  +906        }
                                                                                                                                                                                                                                                                                                                  +907    }
                                                                                                                                                                                                                                                                                                                  +908
                                                                                                                                                                                                                                                                                                                  +909    /**
                                                                                                                                                                                                                                                                                                                  +910     * Returns a random non-negative integer below the given bound, or 0 if the bound is 0.
                                                                                                                                                                                                                                                                                                                  +911     * Uses an aggressively optimized technique that has some bias, but mostly for values of
                                                                                                                                                                                                                                                                                                                  +912     * bound over 1 billion. This method is considered "hasty" since it should be faster than
                                                                                                                                                                                                                                                                                                                  +913     * nextInt() but gives up some statistical quality to do so. It also has undefined behavior
                                                                                                                                                                                                                                                                                                                  +914     * if bound is negative, though it will probably produce a negative number (just how
                                                                                                                                                                                                                                                                                                                  +915     * negative is an open question).
                                                                                                                                                                                                                                                                                                                  +916     * <br>
                                                                                                                                                                                                                                                                                                                  +917     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  +918     *
                                                                                                                                                                                                                                                                                                                  +919     * @param bound the upper bound (exclusive); behavior is undefined if bound is negative
                                                                                                                                                                                                                                                                                                                  +920     * @return the found number
                                                                                                                                                                                                                                                                                                                  +921     */
                                                                                                                                                                                                                                                                                                                  +922    public int nextIntHasty(final int bound) {
                                                                                                                                                                                                                                                                                                                  +923        return (int) ((bound * (random.nextLong() & 0x7FFFFFFFL)) >> 31);
                                                                                                                                                                                                                                                                                                                  +924    }
                                                                                                                                                                                                                                                                                                                  +925
                                                                                                                                                                                                                                                                                                                  +926    /**
                                                                                                                                                                                                                                                                                                                  +927     * Generates random bytes and places them into the given byte array, modifying it in-place.
                                                                                                                                                                                                                                                                                                                  +928     * The number of random bytes produced is equal to the length of the byte array. Unlike the
                                                                                                                                                                                                                                                                                                                  +929     * method in java.util.Random, this generates 8 bytes at a time, which can be more efficient
                                                                                                                                                                                                                                                                                                                  +930     * with many RandomnessSource types than the JDK's method that generates 4 bytes at a time.
                                                                                                                                                                                                                                                                                                                   931     * <br>
                                                                                                                                                                                                                                                                                                                  -932     * @param  bytes the byte array to fill with random bytes; cannot be null, will be modified
                                                                                                                                                                                                                                                                                                                  -933     * @throws NullPointerException if the byte array is null
                                                                                                                                                                                                                                                                                                                  -934     */
                                                                                                                                                                                                                                                                                                                  -935    public void nextBytes(final byte[] bytes) {
                                                                                                                                                                                                                                                                                                                  -936        for (int i = 0; i < bytes.length; )
                                                                                                                                                                                                                                                                                                                  -937            for (long r = random.nextLong(), n = Math.min(bytes.length - i, 8); n-- > 0; r >>>= 8)
                                                                                                                                                                                                                                                                                                                  -938                bytes[i++] = (byte) r;
                                                                                                                                                                                                                                                                                                                  -939    }
                                                                                                                                                                                                                                                                                                                  -940    /**
                                                                                                                                                                                                                                                                                                                  -941     * Gets a random Coord that has x between 0 (inclusive) and width (exclusive) and y between 0 (inclusive)
                                                                                                                                                                                                                                                                                                                  -942     * and height (exclusive). This makes one call to randomLong to generate (more than) 31 random bits for
                                                                                                                                                                                                                                                                                                                  -943     * each axis, and should be very fast. Remember that Coord values are cached in a pool that starts able to
                                                                                                                                                                                                                                                                                                                  -944     * hold up to 255 x and 255 y for positive values, and the pool should be grown with the static method
                                                                                                                                                                                                                                                                                                                  -945     * Coord.expandPool() in order to efficiently use larger Coord values. If width and height are very large,
                                                                                                                                                                                                                                                                                                                  -946     * greater than 100,000 for either, this particular method may show bias toward certain positions due to
                                                                                                                                                                                                                                                                                                                  -947     * the "hasty" technique used to reduce the random numbers to the given size, but because most maps in
                                                                                                                                                                                                                                                                                                                  -948     * tile-based games are relatively small, this technique should be fine.
                                                                                                                                                                                                                                                                                                                  -949     * <br>
                                                                                                                                                                                                                                                                                                                  -950     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  -951     *
                                                                                                                                                                                                                                                                                                                  -952     * @param width  the upper bound (exclusive) for x coordinates
                                                                                                                                                                                                                                                                                                                  -953     * @param height the upper bound (exclusive) for y coordinates
                                                                                                                                                                                                                                                                                                                  -954     * @return a random Coord between (0,0) inclusive and (width,height) exclusive
                                                                                                                                                                                                                                                                                                                  -955     */
                                                                                                                                                                                                                                                                                                                  -956    public Coord nextCoord(int width, int height) {
                                                                                                                                                                                                                                                                                                                  -957        final long n = random.nextLong();
                                                                                                                                                                                                                                                                                                                  -958        return Coord.get((int) ((width * (n >>> 33)) >> 31), (int) ((height * (n & 0x7FFFFFFFL)) >> 31));
                                                                                                                                                                                                                                                                                                                  -959    }
                                                                                                                                                                                                                                                                                                                  -960
                                                                                                                                                                                                                                                                                                                  -961    /**
                                                                                                                                                                                                                                                                                                                  -962     * Get a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  -963     *
                                                                                                                                                                                                                                                                                                                  -964     * @return a 32-bit random int.
                                                                                                                                                                                                                                                                                                                  -965     */
                                                                                                                                                                                                                                                                                                                  -966    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  -967        return next(32);
                                                                                                                                                                                                                                                                                                                  -968    }
                                                                                                                                                                                                                                                                                                                  -969
                                                                                                                                                                                                                                                                                                                  -970    /**
                                                                                                                                                                                                                                                                                                                  -971     * Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                                                                                                                                                                                  -972     *
                                                                                                                                                                                                                                                                                                                  -973     * @param bits 1 to 32
                                                                                                                                                                                                                                                                                                                  -974     * @return a random number that fits in the specified number of bits.
                                                                                                                                                                                                                                                                                                                  -975     */
                                                                                                                                                                                                                                                                                                                  -976    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  -977        return random.next(bits);
                                                                                                                                                                                                                                                                                                                  -978    }
                                                                                                                                                                                                                                                                                                                  -979
                                                                                                                                                                                                                                                                                                                  -980    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  -981        return random;
                                                                                                                                                                                                                                                                                                                  -982    }
                                                                                                                                                                                                                                                                                                                  -983
                                                                                                                                                                                                                                                                                                                  -984    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  -985        this.random = random;
                                                                                                                                                                                                                                                                                                                  -986    }
                                                                                                                                                                                                                                                                                                                  -987
                                                                                                                                                                                                                                                                                                                  -988    /**
                                                                                                                                                                                                                                                                                                                  -989     * Creates a copy of this RNG; it will generate the same random numbers, given the same calls in order, as this RNG
                                                                                                                                                                                                                                                                                                                  -990     * at the point copy() is called. The copy will not share references with this RNG.
                                                                                                                                                                                                                                                                                                                  -991     *
                                                                                                                                                                                                                                                                                                                  -992     * @return a copy of this RNG
                                                                                                                                                                                                                                                                                                                  -993     */
                                                                                                                                                                                                                                                                                                                  -994    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  -995        return new RNG(random.copy());
                                                                                                                                                                                                                                                                                                                  -996    }
                                                                                                                                                                                                                                                                                                                  -997
                                                                                                                                                                                                                                                                                                                  -998    /**
                                                                                                                                                                                                                                                                                                                  -999     * Generates a random 64-bit long with a number of '1' bits (Hamming weight) approximately equal to bitCount.
                                                                                                                                                                                                                                                                                                                  -1000     * For example, calling this with a parameter of 32 will be equivalent to calling nextLong() on this object's
                                                                                                                                                                                                                                                                                                                  -1001     * RandomnessSource (it doesn't consider overridden nextLong() methods, where present, on subclasses of RNG).
                                                                                                                                                                                                                                                                                                                  -1002     * Calling this with a parameter of 16 will have on average 16 of the 64 bits in the returned long set to '1',
                                                                                                                                                                                                                                                                                                                  -1003     * distributed pseudo-randomly, while a parameter of 47 will have on average 47 bits set. This can be useful for
                                                                                                                                                                                                                                                                                                                  -1004     * certain code that uses bits to represent data but needs a different ratio of set bits to unset bits than 1:1.
                                                                                                                                                                                                                                                                                                                  -1005     * <br>
                                                                                                                                                                                                                                                                                                                  -1006     * Implementors should limit any overriding method to calling and returning super(), potentially storing any extra
                                                                                                                                                                                                                                                                                                                  -1007     * information they need to internally, but should not change the result. This works based on a delicate balance of
                                                                                                                                                                                                                                                                                                                  -1008     * the RandomnessSource producing bits with an even 50% chance of being set, regardless of position, and RNG
                                                                                                                                                                                                                                                                                                                  -1009     * subclasses that alter the odds won't work as expected here, particularly if those subclasses use doubles
                                                                                                                                                                                                                                                                                                                  -1010     * internally (which almost always produce less than 64 random bits). You should definitely avoid using certain
                                                                                                                                                                                                                                                                                                                  -1011     * RandomnessSources that aren't properly pseudo-random, such as any QRNG class (SobolQRNG and VanDerCorputQRNG,
                                                                                                                                                                                                                                                                                                                  -1012     * pretty much), since these won't fill all 64 bits with equal likelihood.
                                                                                                                                                                                                                                                                                                                  -1013     *
                                                                                                                                                                                                                                                                                                                  -1014     * @param bitCount an int, only considered if between 0 and 64, that is the average number of bits to set
                                                                                                                                                                                                                                                                                                                  -1015     * @return a 64-bit long that, on average, should have bitCount bits set to 1, potentially anywhere in the long
                                                                                                                                                                                                                                                                                                                  -1016     */
                                                                                                                                                                                                                                                                                                                  -1017    public long approximateBits(int bitCount) {
                                                                                                                                                                                                                                                                                                                  -1018        if (bitCount <= 0)
                                                                                                                                                                                                                                                                                                                  -1019            return 0L;
                                                                                                                                                                                                                                                                                                                  -1020        if (bitCount >= 64)
                                                                                                                                                                                                                                                                                                                  -1021            return -1L;
                                                                                                                                                                                                                                                                                                                  -1022        if (bitCount == 32)
                                                                                                                                                                                                                                                                                                                  -1023            return random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1024        boolean high = bitCount > 32;
                                                                                                                                                                                                                                                                                                                  -1025        int altered = (high ? 64 - bitCount : bitCount), lsb = Integer.lowestOneBit(altered);
                                                                                                                                                                                                                                                                                                                  -1026        long data = random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1027        for (int i = lsb << 1; i <= 16; i <<= 1) {
                                                                                                                                                                                                                                                                                                                  -1028            if ((altered & i) == 0)
                                                                                                                                                                                                                                                                                                                  -1029                data &= random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1030            else
                                                                                                                                                                                                                                                                                                                  -1031                data |= random.nextLong();
                                                                                                                                                                                                                                                                                                                  -1032        }
                                                                                                                                                                                                                                                                                                                  -1033        return high ? ~(random.nextLong() & data) : (random.nextLong() & data);
                                                                                                                                                                                                                                                                                                                  -1034    }
                                                                                                                                                                                                                                                                                                                  -1035
                                                                                                                                                                                                                                                                                                                  -1036    /**
                                                                                                                                                                                                                                                                                                                  -1037     * Gets a somewhat-random long with exactly 32 bits set; in each pair of bits starting at bit 0 and bit 1, then bit
                                                                                                                                                                                                                                                                                                                  -1038     * 2 and bit 3, up to bit 62 and bit 3, one bit will be 1 and one bit will be 0 in each pair.
                                                                                                                                                                                                                                                                                                                  -1039     *
                                                                                                                                                                                                                                                                                                                  -1040     * @return a random long with 32 "1" bits, distributed so exactly one bit is "1" for each pair of bits
                                                                                                                                                                                                                                                                                                                  -1041     */
                                                                                                                                                                                                                                                                                                                  -1042    public long randomInterleave() {
                                                                                                                                                                                                                                                                                                                  -1043        long bits = nextLong() & 0xFFFFFFFFL, ib = ~bits & 0xFFFFFFFFL;
                                                                                                                                                                                                                                                                                                                  -1044        bits |= (bits << 16);
                                                                                                                                                                                                                                                                                                                  -1045        ib |= (ib << 16);
                                                                                                                                                                                                                                                                                                                  -1046        bits &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  -1047        ib &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  -1048        bits |= (bits << 8);
                                                                                                                                                                                                                                                                                                                  -1049        ib |= (ib << 8);
                                                                                                                                                                                                                                                                                                                  -1050        bits &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  -1051        ib &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  -1052        bits |= (bits << 4);
                                                                                                                                                                                                                                                                                                                  -1053        ib |= (ib << 4);
                                                                                                                                                                                                                                                                                                                  -1054        bits &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  -1055        ib &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  -1056        bits |= (bits << 2);
                                                                                                                                                                                                                                                                                                                  -1057        ib |= (ib << 2);
                                                                                                                                                                                                                                                                                                                  -1058        bits &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  -1059        ib &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  -1060        bits |= (bits << 1);
                                                                                                                                                                                                                                                                                                                  -1061        ib |= (ib << 1);
                                                                                                                                                                                                                                                                                                                  -1062        bits &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  -1063        ib &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  -1064        return (bits | (ib << 1));
                                                                                                                                                                                                                                                                                                                  -1065    }
                                                                                                                                                                                                                                                                                                                  -1066
                                                                                                                                                                                                                                                                                                                  -1067    @Override
                                                                                                                                                                                                                                                                                                                  -1068    public String toString() {
                                                                                                                                                                                                                                                                                                                  -1069        return "RNG with Randomness Source " + random;
                                                                                                                                                                                                                                                                                                                  -1070    }
                                                                                                                                                                                                                                                                                                                  -1071
                                                                                                                                                                                                                                                                                                                  -1072    @Override
                                                                                                                                                                                                                                                                                                                  -1073    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  -1074        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  -1075        if (!(o instanceof RNG)) return false;
                                                                                                                                                                                                                                                                                                                  -1076
                                                                                                                                                                                                                                                                                                                  -1077        RNG rng = (RNG) o;
                                                                                                                                                                                                                                                                                                                  +932     * Adapted from code in the JavaDocs of {@link Random#nextBytes(byte[])}.
                                                                                                                                                                                                                                                                                                                  +933     * <br>
                                                                                                                                                                                                                                                                                                                  +934     * @param  bytes the byte array to fill with random bytes; cannot be null, will be modified
                                                                                                                                                                                                                                                                                                                  +935     * @throws NullPointerException if the byte array is null
                                                                                                                                                                                                                                                                                                                  +936     */
                                                                                                                                                                                                                                                                                                                  +937    public void nextBytes(final byte[] bytes) {
                                                                                                                                                                                                                                                                                                                  +938        for (int i = 0; i < bytes.length; )
                                                                                                                                                                                                                                                                                                                  +939            for (long r = random.nextLong(), n = Math.min(bytes.length - i, 8); n-- > 0; r >>>= 8)
                                                                                                                                                                                                                                                                                                                  +940                bytes[i++] = (byte) r;
                                                                                                                                                                                                                                                                                                                  +941    }
                                                                                                                                                                                                                                                                                                                  +942    /**
                                                                                                                                                                                                                                                                                                                  +943     * Gets a random Coord that has x between 0 (inclusive) and width (exclusive) and y between 0 (inclusive)
                                                                                                                                                                                                                                                                                                                  +944     * and height (exclusive). This makes one call to randomLong to generate (more than) 31 random bits for
                                                                                                                                                                                                                                                                                                                  +945     * each axis, and should be very fast. Remember that Coord values are cached in a pool that starts able to
                                                                                                                                                                                                                                                                                                                  +946     * hold up to 255 x and 255 y for positive values, and the pool should be grown with the static method
                                                                                                                                                                                                                                                                                                                  +947     * Coord.expandPool() in order to efficiently use larger Coord values. If width and height are very large,
                                                                                                                                                                                                                                                                                                                  +948     * greater than 100,000 for either, this particular method may show bias toward certain positions due to
                                                                                                                                                                                                                                                                                                                  +949     * the "hasty" technique used to reduce the random numbers to the given size, but because most maps in
                                                                                                                                                                                                                                                                                                                  +950     * tile-based games are relatively small, this technique should be fine.
                                                                                                                                                                                                                                                                                                                  +951     * <br>
                                                                                                                                                                                                                                                                                                                  +952     * Credit goes to Daniel Lemire, http://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction/
                                                                                                                                                                                                                                                                                                                  +953     *
                                                                                                                                                                                                                                                                                                                  +954     * @param width  the upper bound (exclusive) for x coordinates
                                                                                                                                                                                                                                                                                                                  +955     * @param height the upper bound (exclusive) for y coordinates
                                                                                                                                                                                                                                                                                                                  +956     * @return a random Coord between (0,0) inclusive and (width,height) exclusive
                                                                                                                                                                                                                                                                                                                  +957     */
                                                                                                                                                                                                                                                                                                                  +958    public Coord nextCoord(int width, int height) {
                                                                                                                                                                                                                                                                                                                  +959        final long n = random.nextLong();
                                                                                                                                                                                                                                                                                                                  +960        return Coord.get((int) ((width * (n >>> 33)) >> 31), (int) ((height * (n & 0x7FFFFFFFL)) >> 31));
                                                                                                                                                                                                                                                                                                                  +961    }
                                                                                                                                                                                                                                                                                                                  +962
                                                                                                                                                                                                                                                                                                                  +963    /**
                                                                                                                                                                                                                                                                                                                  +964     * Get a random integer between Integer.MIN_VALUE to Integer.MAX_VALUE (both inclusive).
                                                                                                                                                                                                                                                                                                                  +965     *
                                                                                                                                                                                                                                                                                                                  +966     * @return a 32-bit random int.
                                                                                                                                                                                                                                                                                                                  +967     */
                                                                                                                                                                                                                                                                                                                  +968    public int nextInt() {
                                                                                                                                                                                                                                                                                                                  +969        return next(32);
                                                                                                                                                                                                                                                                                                                  +970    }
                                                                                                                                                                                                                                                                                                                  +971
                                                                                                                                                                                                                                                                                                                  +972    /**
                                                                                                                                                                                                                                                                                                                  +973     * Get up to 32 bits (inclusive) of random state from the RandomnessSource.
                                                                                                                                                                                                                                                                                                                  +974     *
                                                                                                                                                                                                                                                                                                                  +975     * @param bits 1 to 32
                                                                                                                                                                                                                                                                                                                  +976     * @return a random number that fits in the specified number of bits.
                                                                                                                                                                                                                                                                                                                  +977     */
                                                                                                                                                                                                                                                                                                                  +978    public int next(int bits) {
                                                                                                                                                                                                                                                                                                                  +979        return random.next(bits);
                                                                                                                                                                                                                                                                                                                  +980    }
                                                                                                                                                                                                                                                                                                                  +981
                                                                                                                                                                                                                                                                                                                  +982    public RandomnessSource getRandomness() {
                                                                                                                                                                                                                                                                                                                  +983        return random;
                                                                                                                                                                                                                                                                                                                  +984    }
                                                                                                                                                                                                                                                                                                                  +985
                                                                                                                                                                                                                                                                                                                  +986    public void setRandomness(RandomnessSource random) {
                                                                                                                                                                                                                                                                                                                  +987        this.random = random;
                                                                                                                                                                                                                                                                                                                  +988    }
                                                                                                                                                                                                                                                                                                                  +989
                                                                                                                                                                                                                                                                                                                  +990    /**
                                                                                                                                                                                                                                                                                                                  +991     * Creates a copy of this RNG; it will generate the same random numbers, given the same calls in order, as this RNG
                                                                                                                                                                                                                                                                                                                  +992     * at the point copy() is called. The copy will not share references with this RNG.
                                                                                                                                                                                                                                                                                                                  +993     *
                                                                                                                                                                                                                                                                                                                  +994     * @return a copy of this RNG
                                                                                                                                                                                                                                                                                                                  +995     */
                                                                                                                                                                                                                                                                                                                  +996    public RNG copy() {
                                                                                                                                                                                                                                                                                                                  +997        return new RNG(random.copy());
                                                                                                                                                                                                                                                                                                                  +998    }
                                                                                                                                                                                                                                                                                                                  +999
                                                                                                                                                                                                                                                                                                                  +1000    /**
                                                                                                                                                                                                                                                                                                                  +1001     * Generates a random 64-bit long with a number of '1' bits (Hamming weight) approximately equal to bitCount.
                                                                                                                                                                                                                                                                                                                  +1002     * For example, calling this with a parameter of 32 will be equivalent to calling nextLong() on this object's
                                                                                                                                                                                                                                                                                                                  +1003     * RandomnessSource (it doesn't consider overridden nextLong() methods, where present, on subclasses of RNG).
                                                                                                                                                                                                                                                                                                                  +1004     * Calling this with a parameter of 16 will have on average 16 of the 64 bits in the returned long set to '1',
                                                                                                                                                                                                                                                                                                                  +1005     * distributed pseudo-randomly, while a parameter of 47 will have on average 47 bits set. This can be useful for
                                                                                                                                                                                                                                                                                                                  +1006     * certain code that uses bits to represent data but needs a different ratio of set bits to unset bits than 1:1.
                                                                                                                                                                                                                                                                                                                  +1007     * <br>
                                                                                                                                                                                                                                                                                                                  +1008     * Implementors should limit any overriding method to calling and returning super(), potentially storing any extra
                                                                                                                                                                                                                                                                                                                  +1009     * information they need to internally, but should not change the result. This works based on a delicate balance of
                                                                                                                                                                                                                                                                                                                  +1010     * the RandomnessSource producing bits with an even 50% chance of being set, regardless of position, and RNG
                                                                                                                                                                                                                                                                                                                  +1011     * subclasses that alter the odds won't work as expected here, particularly if those subclasses use doubles
                                                                                                                                                                                                                                                                                                                  +1012     * internally (which almost always produce less than 64 random bits). You should definitely avoid using certain
                                                                                                                                                                                                                                                                                                                  +1013     * RandomnessSources that aren't properly pseudo-random, such as any QRNG class (SobolQRNG and VanDerCorputQRNG,
                                                                                                                                                                                                                                                                                                                  +1014     * pretty much), since these won't fill all 64 bits with equal likelihood.
                                                                                                                                                                                                                                                                                                                  +1015     *
                                                                                                                                                                                                                                                                                                                  +1016     * @param bitCount an int, only considered if between 0 and 64, that is the average number of bits to set
                                                                                                                                                                                                                                                                                                                  +1017     * @return a 64-bit long that, on average, should have bitCount bits set to 1, potentially anywhere in the long
                                                                                                                                                                                                                                                                                                                  +1018     */
                                                                                                                                                                                                                                                                                                                  +1019    public long approximateBits(int bitCount) {
                                                                                                                                                                                                                                                                                                                  +1020        if (bitCount <= 0)
                                                                                                                                                                                                                                                                                                                  +1021            return 0L;
                                                                                                                                                                                                                                                                                                                  +1022        if (bitCount >= 64)
                                                                                                                                                                                                                                                                                                                  +1023            return -1L;
                                                                                                                                                                                                                                                                                                                  +1024        if (bitCount == 32)
                                                                                                                                                                                                                                                                                                                  +1025            return random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1026        boolean high = bitCount > 32;
                                                                                                                                                                                                                                                                                                                  +1027        int altered = (high ? 64 - bitCount : bitCount), lsb = Integer.lowestOneBit(altered);
                                                                                                                                                                                                                                                                                                                  +1028        long data = random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1029        for (int i = lsb << 1; i <= 16; i <<= 1) {
                                                                                                                                                                                                                                                                                                                  +1030            if ((altered & i) == 0)
                                                                                                                                                                                                                                                                                                                  +1031                data &= random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1032            else
                                                                                                                                                                                                                                                                                                                  +1033                data |= random.nextLong();
                                                                                                                                                                                                                                                                                                                  +1034        }
                                                                                                                                                                                                                                                                                                                  +1035        return high ? ~(random.nextLong() & data) : (random.nextLong() & data);
                                                                                                                                                                                                                                                                                                                  +1036    }
                                                                                                                                                                                                                                                                                                                  +1037
                                                                                                                                                                                                                                                                                                                  +1038    /**
                                                                                                                                                                                                                                                                                                                  +1039     * Gets a somewhat-random long with exactly 32 bits set; in each pair of bits starting at bit 0 and bit 1, then bit
                                                                                                                                                                                                                                                                                                                  +1040     * 2 and bit 3, up to bit 62 and bit 3, one bit will be 1 and one bit will be 0 in each pair.
                                                                                                                                                                                                                                                                                                                  +1041     *
                                                                                                                                                                                                                                                                                                                  +1042     * @return a random long with 32 "1" bits, distributed so exactly one bit is "1" for each pair of bits
                                                                                                                                                                                                                                                                                                                  +1043     */
                                                                                                                                                                                                                                                                                                                  +1044    public long randomInterleave() {
                                                                                                                                                                                                                                                                                                                  +1045        long bits = nextLong() & 0xFFFFFFFFL, ib = ~bits & 0xFFFFFFFFL;
                                                                                                                                                                                                                                                                                                                  +1046        bits |= (bits << 16);
                                                                                                                                                                                                                                                                                                                  +1047        ib |= (ib << 16);
                                                                                                                                                                                                                                                                                                                  +1048        bits &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  +1049        ib &= 0x0000FFFF0000FFFFL;
                                                                                                                                                                                                                                                                                                                  +1050        bits |= (bits << 8);
                                                                                                                                                                                                                                                                                                                  +1051        ib |= (ib << 8);
                                                                                                                                                                                                                                                                                                                  +1052        bits &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  +1053        ib &= 0x00FF00FF00FF00FFL;
                                                                                                                                                                                                                                                                                                                  +1054        bits |= (bits << 4);
                                                                                                                                                                                                                                                                                                                  +1055        ib |= (ib << 4);
                                                                                                                                                                                                                                                                                                                  +1056        bits &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  +1057        ib &= 0x0F0F0F0F0F0F0F0FL;
                                                                                                                                                                                                                                                                                                                  +1058        bits |= (bits << 2);
                                                                                                                                                                                                                                                                                                                  +1059        ib |= (ib << 2);
                                                                                                                                                                                                                                                                                                                  +1060        bits &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  +1061        ib &= 0x3333333333333333L;
                                                                                                                                                                                                                                                                                                                  +1062        bits |= (bits << 1);
                                                                                                                                                                                                                                                                                                                  +1063        ib |= (ib << 1);
                                                                                                                                                                                                                                                                                                                  +1064        bits &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  +1065        ib &= 0x5555555555555555L;
                                                                                                                                                                                                                                                                                                                  +1066        return (bits | (ib << 1));
                                                                                                                                                                                                                                                                                                                  +1067    }
                                                                                                                                                                                                                                                                                                                  +1068
                                                                                                                                                                                                                                                                                                                  +1069    @Override
                                                                                                                                                                                                                                                                                                                  +1070    public String toString() {
                                                                                                                                                                                                                                                                                                                  +1071        return "RNG with Randomness Source " + random;
                                                                                                                                                                                                                                                                                                                  +1072    }
                                                                                                                                                                                                                                                                                                                  +1073
                                                                                                                                                                                                                                                                                                                  +1074    @Override
                                                                                                                                                                                                                                                                                                                  +1075    public boolean equals(Object o) {
                                                                                                                                                                                                                                                                                                                  +1076        if (this == o) return true;
                                                                                                                                                                                                                                                                                                                  +1077        if (!(o instanceof RNG)) return false;
                                                                                                                                                                                                                                                                                                                   1078
                                                                                                                                                                                                                                                                                                                  -1079        return random.equals(rng.random);
                                                                                                                                                                                                                                                                                                                  -1080    }
                                                                                                                                                                                                                                                                                                                  -1081
                                                                                                                                                                                                                                                                                                                  -1082    @Override
                                                                                                                                                                                                                                                                                                                  -1083    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  -1084        return random.hashCode();
                                                                                                                                                                                                                                                                                                                  -1085    }
                                                                                                                                                                                                                                                                                                                  -1086}
                                                                                                                                                                                                                                                                                                                  +1079        RNG rng = (RNG) o;
                                                                                                                                                                                                                                                                                                                  +1080
                                                                                                                                                                                                                                                                                                                  +1081        return random.equals(rng.random);
                                                                                                                                                                                                                                                                                                                  +1082    }
                                                                                                                                                                                                                                                                                                                  +1083
                                                                                                                                                                                                                                                                                                                  +1084    @Override
                                                                                                                                                                                                                                                                                                                  +1085    public int hashCode() {
                                                                                                                                                                                                                                                                                                                  +1086        return random.hashCode();
                                                                                                                                                                                                                                                                                                                  +1087    }
                                                                                                                                                                                                                                                                                                                  +1088}
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                  diff --git a/docs/squidlib-util/src-html/squidpony/squidmath/StatefulRNG.html b/docs/squidlib-util/src-html/squidpony/squidmath/StatefulRNG.html
                                                                                                                                                                                                                                                                                                                  index 79463a520d..9ace5221d7 100644
                                                                                                                                                                                                                                                                                                                  --- a/docs/squidlib-util/src-html/squidpony/squidmath/StatefulRNG.html
                                                                                                                                                                                                                                                                                                                  +++ b/docs/squidlib-util/src-html/squidpony/squidmath/StatefulRNG.html
                                                                                                                                                                                                                                                                                                                  @@ -43,8 +43,8 @@
                                                                                                                                                                                                                                                                                                                   035     * technique assigns to all 64 bits and has less correlation between similar inputs causing similar starting states.
                                                                                                                                                                                                                                                                                                                   036     * It's also faster, but that shouldn't matter in a constructor.
                                                                                                                                                                                                                                                                                                                   037     */
                                                                                                                                                                                                                                                                                                                  -038    public StatefulRNG(String seedString) {
                                                                                                                                                                                                                                                                                                                  -039        this(new LightRNG(CrossHash.Wisp.hash64(seedString)));
                                                                                                                                                                                                                                                                                                                  +038    public StatefulRNG(CharSequence seedString) {
                                                                                                                                                                                                                                                                                                                  +039        this(new LightRNG(CrossHash.hash64(seedString)));
                                                                                                                                                                                                                                                                                                                   040    }
                                                                                                                                                                                                                                                                                                                   041
                                                                                                                                                                                                                                                                                                                   042    @Override
                                                                                                                                                                                                                                                                                                                  diff --git a/squidlib-util/src/main/java/squidpony/squidmath/CriticalRNG.java b/squidlib-util/src/main/java/squidpony/squidmath/CriticalRNG.java
                                                                                                                                                                                                                                                                                                                  new file mode 100644
                                                                                                                                                                                                                                                                                                                  index 0000000000..2ce0a9df07
                                                                                                                                                                                                                                                                                                                  --- /dev/null
                                                                                                                                                                                                                                                                                                                  +++ b/squidlib-util/src/main/java/squidpony/squidmath/CriticalRNG.java
                                                                                                                                                                                                                                                                                                                  @@ -0,0 +1,196 @@
                                                                                                                                                                                                                                                                                                                  +package squidpony.squidmath;
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +import java.util.*;
                                                                                                                                                                                                                                                                                                                  +
                                                                                                                                                                                                                                                                                                                  +/**
                                                                                                                                                                                                                                                                                                                  + * A type of RNG that can generate values larger or smaller than the normal maximum or minimum, based on a modifier.
                                                                                                                                                                                                                                                                                                                  + * You should not use this as a general-purpose substitute for {@link RNG}; it is meant for cases where there is no hard
                                                                                                                                                                                                                                                                                                                  + * maximum or minimum for a random value, so it is a poor fit for getting random items from collections or shuffling.
                                                                                                                                                                                                                                                                                                                  + * It also uses a curved distribution (almost Gaussian, but slightly more shallow), which makes its results to be most
                                                                                                                                                                                                                                                                                                                  + * often near the center of the range they can fall into. The {@link #luck} field affects the distribution simply, and
                                                                                                                                                                                                                                                                                                                  + * should generally be between -0.5f and 0.5f except in cases where a character or event routinely defies all odds.
                                                                                                                                                                                                                                                                                                                  + * There is no value for luck that will prevent this from sometimes producing values outside the requested range, though
                                                                                                                                                                                                                                                                                                                  + * at luck = 0 it is somewhat rare for the bounds to be significantly exceeded.
                                                                                                                                                                                                                                                                                                                  + * 
                                                                                                                                                                                                                                                                                                                  + * The name comes from "critical hit," the rare but potentially very significant strike in many role-playing games. + *
                                                                                                                                                                                                                                                                                                                  + * Created by Tommy Ettinger on 9/20/2017. + */ +public class CriticalRNG extends RNG { + /** + * Positive for higher results, negative for lower results; usually this is small, between -0.5f and 0.5f . + */ + public float luck = 0f; + + /** + * Makes a CriticalRNG with a luck factor of 0 and a randomly-seeded ThrustRNG for its RandomnessSource. + */ + public CriticalRNG() { + super(new ThrustRNG()); + } + + /** + * Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource. + * @param seed any long + */ + public CriticalRNG(long seed) { + super(new ThrustRNG(seed)); + } + /** + * Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource (this + * will hash seedString using {@link CrossHash#hash64(CharSequence)} and use the result to seed the ThrustRNG). + * @param seedString any String + */ + public CriticalRNG(CharSequence seedString) { + super(new ThrustRNG(CrossHash.hash64(seedString))); + } + + /** + * Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource. + * @param random a RandomnessSource, such as a {@link LongPeriodRNG} or {@link LightRNG} + */ + public CriticalRNG(RandomnessSource random) { + super(random); + } + + /** + * Makes a CriticalRNG with the given luck factor and a randomly-seeded ThrustRNG for its RandomnessSource. + * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns + */ + public CriticalRNG(float luck) { + super(new ThrustRNG()); + this.luck = luck; + } + + /** + * Makes a CriticalRNG with the given luck factor and a ThrustRNG with the given seed for its RandomnessSource. + * @param seed any long + * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns + */ + public CriticalRNG(long seed, float luck) { + super(new ThrustRNG(seed)); + this.luck = luck; + } + + /** + * Makes a CriticalRNG with a luck factor of 0 and a ThrustRNG with the given seed for its RandomnessSource (this + * will hash seedString using {@link CrossHash#hash64(CharSequence)} and use the result to seed the ThrustRNG). + * @param seedString any String + * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns + */ + public CriticalRNG(CharSequence seedString, float luck) { + super(new ThrustRNG(CrossHash.hash64(seedString))); + this.luck = luck; + } + + /** + * Makes a CriticalRNG with a luck factor of 0 and the given RandomnessSource. + * @param random a RandomnessSource, such as a {@link LongPeriodRNG} or {@link LightRNG} + * @param luck typically a small float, often between -0.5f and 0.5f, that will affect the results this returns + */ + public CriticalRNG(RandomnessSource random, float luck) { + super(random); + this.luck = luck; + } + + @Override + public double nextDouble() { + return NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck; + } + + @Override + public double nextDouble(double max) { + return (NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * max; + } + + @Override + public float nextFloat() { + return NumberTools.formCurvedFloat(random.nextLong()) * 0.875f + 0.5f + luck; + } + + @Override + public boolean nextBoolean() { + return NumberTools.formCurvedFloat(random.nextLong()) * 0.875f + 0.5f + luck >= 0f; + } + + private static int intify(final double t) { + return t >= 0.0 ? (int) (t + 0.5) : (int) (t - 0.5); + } + private static long longify(final double t) { + return t >= 0.0 ? (long) (t + 0.5) : (long) (t - 0.5); + } + + @Override + public long nextLong() { + return longify((NumberTools.formCurvedFloat(random.nextLong()) + luck * -2.0) * 0x8000000000000000L); + } + + @Override + public long nextLong(long bound) { + return longify((NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * bound); + } + + @Override + public int nextInt(int bound) { + return intify((NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * bound); + } + + @Override + public int nextIntHasty(int bound) { + return intify((NumberTools.formCurvedFloat(random.nextLong()) * 0.875 + 0.5 + luck) * bound); + } + + @Override + public int nextInt() { + return intify((NumberTools.formCurvedFloat(random.nextLong()) + luck * -2.0) * 0x80000000); + } + + @Override + public T getRandomElement(T[] array) { + if (array.length < 1) { + return null; + } + return array[super.nextIntHasty(array.length)]; + } + + @Override + public T getRandomElement(List list) { + if (list.isEmpty()) { + return null; + } + return list.get(super.nextIntHasty(list.size())); + } + + @Override + public short getRandomElement(ShortSet set) { + if (set.size <= 0) { + throw new UnsupportedOperationException("ShortSet cannot be empty when getting a random element"); + } + int n = super.nextIntHasty(set.size); + short s = 0; + ShortSet.ShortSetIterator ssi = set.iterator(); + while (n-- >= 0 && ssi.hasNext) + s = ssi.next(); + ssi.reset(); + return s; + } + + @Override + public T getRandomElement(Collection coll) { + int n; + if ((n = coll.size()) <= 0) { + return null; + } + n = super.nextIntHasty(n); + T t = null; + Iterator it = coll.iterator(); + while (n-- >= 0 && it.hasNext()) + t = it.next(); + return t; + } + + @Override + public double nextGaussian() { + return NumberTools.formCurvedFloat(random.nextLong()) * 1.75 + luck * 2; + } +} diff --git a/squidlib-util/src/main/java/squidpony/squidmath/DeckRNG.java b/squidlib-util/src/main/java/squidpony/squidmath/DeckRNG.java index c6f482a462..a05b2262da 100644 --- a/squidlib-util/src/main/java/squidpony/squidmath/DeckRNG.java +++ b/squidlib-util/src/main/java/squidpony/squidmath/DeckRNG.java @@ -1,7 +1,6 @@ package squidpony.squidmath; import squidpony.StringKit; -import squidpony.annotation.GwtIncompatible; import java.io.Serializable; import java.util.*; @@ -49,8 +48,8 @@ public DeckRNG(final long seed) { * * @param seedString a String to use as a seed; will be hashed in a uniform way across platforms. */ - public DeckRNG(String seedString) { - this(CrossHash.hash(seedString)); + public DeckRNG(CharSequence seedString) { + this(CrossHash.hash64(seedString)); } /** * Seeds this DeckRNG using the RandomnessSource it is given. Does not assign the RandomnessSource to any fields @@ -271,7 +270,6 @@ public int nextInt(int bound) { * @return a shuffled copy of elements */ @Override - @GwtIncompatible public T[] shuffle(T[] elements) { int n = elements.length; @@ -382,18 +380,6 @@ public Random asRandom() { return ran; } - @Override - @GwtIncompatible - public List randomRotation(List l) { - return super.randomRotation(l); - } - - @Override - public Iterable getRandomStartIterable(List list) { - return super.getRandomStartIterable(list); - } - - /** * Returns a value between min (inclusive) and max (exclusive). *

                                                                                                                                                                                                                                                                                                                  @@ -409,18 +395,6 @@ public long between(long min, long max) { return nextLong(max - min) + min; } - /* - * Shuffle an array using the Fisher-Yates algorithm. - * - * @param elements an array of T; will not be modified - * @return a shuffled copy of elements - * / - @Override - @GwtIncompatible - public T[] shuffle(T[] elements) { - return super.shuffle(elements); - } -*/ /** * Shuffle an array using the Fisher-Yates algorithm. * diff --git a/squidlib-util/src/main/java/squidpony/squidmath/DharmaRNG.java b/squidlib-util/src/main/java/squidpony/squidmath/DharmaRNG.java index e67130a2a8..8854d6ba0b 100644 --- a/squidlib-util/src/main/java/squidpony/squidmath/DharmaRNG.java +++ b/squidlib-util/src/main/java/squidpony/squidmath/DharmaRNG.java @@ -1,9 +1,8 @@ package squidpony.squidmath; -import squidpony.annotation.GwtIncompatible; - import java.io.Serializable; -import java.util.*; +import java.util.Collection; +import java.util.List; /** * An alteration to a RandomnessSource that attempts to produce values that are perceived as fair to an imperfect user. @@ -83,7 +82,7 @@ public DharmaRNG(final long seed, final double fairness) { * * @param seedString a String as a seed */ - public DharmaRNG(String seedString) { + public DharmaRNG(CharSequence seedString) { super(seedString); } @@ -381,38 +380,6 @@ public int next(int bits) { } - @Override - public Random asRandom() { - return super.asRandom(); - } - - @Override - @GwtIncompatible - public List randomRotation(List l) { - return super.randomRotation(l); - } - - @Override - public Iterable getRandomStartIterable(List list) { - return super.getRandomStartIterable(list); - } -/* - @Override - @GwtIncompatible - public T[] shuffle(T[] elements) { - return super.shuffle(elements); - } -*/ - @Override - public T[] shuffle(T[] elements, T[] dest) { - return super.shuffle(elements, dest); - } - - @Override - public ArrayList shuffle(Collection elements) { - return super.shuffle(elements); - } - /** * Returns a value between min (inclusive) and max (exclusive). *

                                                                                                                                                                                                                                                                                                                  @@ -428,33 +395,6 @@ public long between(long min, long max) { return min + nextLong(max - min); } - /** - * Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays. - *
                                                                                                                                                                                                                                                                                                                  - * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle - * - * @param elements an array of T; will not be modified - * @return a shuffled copy of elements - */ - @GwtIncompatible - @Override - public T[] shuffle(T[] elements) { - return super.shuffle(elements); - } - - /** - * Generates a random permutation of the range from 0 (inclusive) to length (exclusive). - * Useful for passing to OrderedMap or OrderedSet's reorder() methods. - * - * @param length the size of the ordering to produce - * @return a random ordering containing all ints from 0 to length (exclusive) - */ - @Override - public int[] randomOrdering(int length) { - return super.randomOrdering(length); - } - - /** * Returns a random non-negative integer below the given bound, or 0 if the bound is 0. * Uses a slightly optimized technique. This method is considered "hasty" since diff --git a/squidlib-util/src/main/java/squidpony/squidmath/EditRNG.java b/squidlib-util/src/main/java/squidpony/squidmath/EditRNG.java index 9a0d568138..170a95c307 100644 --- a/squidlib-util/src/main/java/squidpony/squidmath/EditRNG.java +++ b/squidlib-util/src/main/java/squidpony/squidmath/EditRNG.java @@ -1,12 +1,8 @@ package squidpony.squidmath; -import squidpony.annotation.GwtIncompatible; - import java.io.Serializable; -import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Random; /** * A subclass of StatefulRNG (and thus RNG) that allows customizing many parts of the random number generation. @@ -99,7 +95,7 @@ public EditRNG(final long seed) { * * @param seed used to seed the default RandomnessSource. */ - public EditRNG(final String seed) { + public EditRNG(final CharSequence seed) { super(seed); } @@ -458,32 +454,6 @@ public int next(int bits) { } - @Override - public Random asRandom() { - return super.asRandom(); - } - - @Override - @GwtIncompatible - public List randomRotation(List l) { - return super.randomRotation(l); - } - - @Override - public Iterable getRandomStartIterable(List list) { - return super.getRandomStartIterable(list); - } - - @Override - public T[] shuffle(T[] elements, T[] dest) { - return super.shuffle(elements, dest); - } - - @Override - public ArrayList shuffle(Collection elements) { - return super.shuffle(elements); - } - @Override public float nextFloat() { return (float)nextDouble(); @@ -617,40 +587,11 @@ public boolean equals(Object o) { @Override public int hashCode() { int result = super.hashCode() * 31; - long temp; - temp = NumberTools.doubleToLongBits(expected); - result += (int) (temp ^ (temp >>> 32)); - temp = NumberTools.doubleToLongBits(centrality); - result = 31 * result + (int) (temp ^ (temp >>> 32)); + result += NumberTools.doubleToMixedIntBits(expected); + result = 31 * result + NumberTools.doubleToMixedIntBits(centrality); return result; } - /** - * Shuffle an array using the Fisher-Yates algorithm. Not GWT-compatible; use the overload that takes two arrays. - *
                                                                                                                                                                                                                                                                                                                  - * https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle - * - * @param elements an array of T; will not be modified - * @return a shuffled copy of elements - */ - @GwtIncompatible - @Override - public T[] shuffle(T[] elements) { - return super.shuffle(elements); - } - - /** - * Generates a random permutation of the range from 0 (inclusive) to length (exclusive). - * Useful for passing to OrderedMap or OrderedSet's reorder() methods. - * - * @param length the size of the ordering to produce - * @return a random ordering containing all ints from 0 to length (exclusive) - */ - @Override - public int[] randomOrdering(int length) { - return super.randomOrdering(length); - } - /** * Returns a random non-negative integer below the given bound, or 0 if the bound is 0. * Uses a slightly optimized technique. This method is considered "hasty" since diff --git a/squidlib-util/src/main/java/squidpony/squidmath/RNG.java b/squidlib-util/src/main/java/squidpony/squidmath/RNG.java index ef76d6a380..18ff468f2c 100644 --- a/squidlib-util/src/main/java/squidpony/squidmath/RNG.java +++ b/squidlib-util/src/main/java/squidpony/squidmath/RNG.java @@ -1,7 +1,6 @@ package squidpony.squidmath; import squidpony.ArrayTools; -import squidpony.annotation.GwtIncompatible; import java.io.Serializable; import java.util.*; @@ -104,7 +103,9 @@ public class RNG implements Serializable { * applications anyway. The addition of LongPeriodRNG on March 21, 2016 should help to take the part of a fast, * large-period RNG, which MersenneTwister is unable to act as on GWT. The default may change again some time after * May 1, 2016, now that we have XoRoRNG, which is approximately as fast as LightRNG and has a substantially better - * period (pow(2, 128) - 1). + * period (pow(2, 128) - 1). It may change instead to the newer ThrustRNG, which is extremely similar to LightRNG + * except that it has slightly better statistical quality (both excellent) and is a fair amount faster (its period + * remains at pow(2, 64)). */ public RNG() { this(new LightRNG()); @@ -123,18 +124,18 @@ public RNG(long seed) { * seed for LightRNG, which is of high quality, but low period (which rarely matters for games), and has good speed, * tiny state size, and excellent 64-bit number generation. */ - public RNG(String seedString) { + public RNG(CharSequence seedString) { this(new LightRNG(CrossHash.hash(seedString))); } /** * Uses the provided source of randomness for all calculations. This * constructor should be used if an alternate RandomnessSource other than LightRNG is desirable. - * + * If the parameter is null, this is equivalent to using {@link #RNG()} as the constructor. * @param random the source of pseudo-randomness, such as a MersenneTwister or SobolQRNG object */ public RNG(RandomnessSource random) { - this.random = random; + this.random = (random == null) ? new LightRNG() : random; } /** @@ -294,7 +295,7 @@ public T getRandomElement(T[] array) { * @return the randomly selected element */ public T getRandomElement(List list) { - if (list.size() <= 0) { + if (list.isEmpty()) { return null; } return list.get(nextInt(list.size())); @@ -344,10 +345,11 @@ public short getRandomElement(ShortSet set) { * @return the randomly selected element */ public T getRandomElement(Collection coll) { - if (coll.size() <= 0) { + int n; + if ((n = coll.size()) <= 0) { return null; } - int n = nextInt(coll.size()); + n = nextInt(n); T t = null; Iterator it = coll.iterator(); while (n-- >= 0 && it.hasNext()) @@ -385,7 +387,8 @@ public T getRandomElement(Queue list) { * Essentially, it does what it says on the tin. It randomly rotates the List l. *
                                                                                                                                                                                                                                                                                                                  * If you only need to iterate through a collection starting at a random point, the method getRandomStartIterable() - * should have better performance. + * should have better performance. This was GWT incompatible before GWT 2.8.0 became the version SquidLib uses; now + * this method works fine with GWT. * * @param l A {@link List} that will not be modified by this method. All elements of this parameter will be * shared with the returned List. @@ -394,7 +397,6 @@ public T getRandomElement(Queue list) { * from all possible elements but order is retained. Will "loop around" to contain element 0 of l after the last * element of l, then element 1, etc. */ - @GwtIncompatible /* Because of Collections.rotate */ public List randomRotation(final List l) { final int sz = l.size(); if (sz == 0) diff --git a/squidlib-util/src/main/java/squidpony/squidmath/StatefulRNG.java b/squidlib-util/src/main/java/squidpony/squidmath/StatefulRNG.java index 0d6a7991ae..e939916f45 100644 --- a/squidlib-util/src/main/java/squidpony/squidmath/StatefulRNG.java +++ b/squidlib-util/src/main/java/squidpony/squidmath/StatefulRNG.java @@ -35,8 +35,8 @@ public StatefulRNG(long seed) { * technique assigns to all 64 bits and has less correlation between similar inputs causing similar starting states. * It's also faster, but that shouldn't matter in a constructor. */ - public StatefulRNG(String seedString) { - this(new LightRNG(CrossHash.Wisp.hash64(seedString))); + public StatefulRNG(CharSequence seedString) { + this(new LightRNG(CrossHash.hash64(seedString))); } @Override diff --git a/squidlib-util/src/test/java/squidpony/examples/RNGFeatureTest.java b/squidlib-util/src/test/java/squidpony/examples/RNGFeatureTest.java index f0a6b18e3f..4bee094ad1 100644 --- a/squidlib-util/src/test/java/squidpony/examples/RNGFeatureTest.java +++ b/squidlib-util/src/test/java/squidpony/examples/RNGFeatureTest.java @@ -1,10 +1,7 @@ package squidpony.examples; import org.junit.Test; -import squidpony.squidmath.BeardRNG; -import squidpony.squidmath.Coord; -import squidpony.squidmath.OrderedSet; -import squidpony.squidmath.RNG; +import squidpony.squidmath.*; import static org.junit.Assert.assertTrue; @@ -14,6 +11,7 @@ public class RNGFeatureTest { public static BeardRNG beard = new BeardRNG("Testing all the while..."); public static RNG rng = new RNG(beard); + public static CriticalRNG crng = new CriticalRNG(0x123456789ABCDEF0L); public static final boolean PRINTING = false; @Test public void testUniqueCells(){ @@ -34,4 +32,22 @@ public void testUniqueCells(){ // using a Set to test for uniqueness assertTrue(set.size() == width * height / 4); } + @Test + public void testCriticalHits() + { + double total; + int c; + for(float lc : new float[]{0f, 0.25f, -0.25f, 0.5f, -0.5f, 0.8f, -0.8f, 1f, -1f, 1.5f, -1.5f}) + { + total = 0.0; + crng.luck = lc; + if(PRINTING) System.out.println("Luck is " + lc); + for (int j = 0; j < 32; j++) { + c = crng.nextInt(20); + if(PRINTING) System.out.print(c + " "); + total += c * 0x1p-5; + } + if(PRINTING) System.out.println("\n" + total + "\n"); + } + } }