Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- $stems = [
- 'b' => 2,
- 'br' => 2,
- 'c' => 3,
- 'ch' => 4,
- 'cl' => 2,
- 'd' => 2,
- 'dr' => 1,
- 'f' => 2,
- 'g' => 1,
- 'gh' => 3,
- 'h' => 5,
- 'j' => 1,
- 'jh' => 1,
- 'k' => 2,
- 'kl' => 2,
- 'l' => 1,
- 'm' => 2,
- 'mn' => 1,
- 'n' => 2,
- 'ng' => 1,
- 'p' => 1,
- 'q' => 1,
- 'r' => 2,
- 's' => 4,
- 'sc' => 1,
- 'sh' => 3,
- 'sp' => 2,
- 'st' => 3,
- 't' => 4,
- 'th' => 4,
- 'w' => 1,
- 'wr' => 1,
- 'x' => 4,
- 'xh' => 1,
- 'y' => 2,
- 'z' => 5,
- 'zh' => 5,
- ];
- $vowels = [
- 'a' => 3,
- 'ae' => 2,
- 'ai' => 2,
- 'ao' => 1,
- 'au' => 1,
- 'ay' => 1,
- 'e' => 4,
- 'ea' => 1,
- 'ei' => 1,
- 'eo' => 1,
- 'eu' => 2,
- 'ey' => 1,
- 'i' => 3,
- 'ia' => 1,
- 'ie' => 1,
- 'io' => 1,
- 'iu' => 1,
- 'o' => 3,
- 'oa' => 1,
- 'oe' => 1,
- 'oi' => 1,
- 'ou' => 2,
- 'oy' => 2,
- 'u' => 2,
- 'ua' => 1,
- 'ui' => 1,
- 'uo' => 1,
- 'y' => 2,
- 'ya' => 1,
- 'ye' => 1,
- 'yi' => 1,
- 'yo' => 1,
- 'yu' => 1,
- ];
- $altVowelChance = 30;
- $prefixes = [
- '' => 100,
- 'b' => 8,
- 'd' => 10,
- 'g' => 10,
- 'k' => 10,
- 'm' => 6,
- 'n' => 6,
- 's' => 10,
- 't' => 10,
- 'z' => 10,
- ];
- $subjectiveSuffixes = [
- '' => 100,
- 'h' => 10,
- 'n' => 5,
- 'w' => 10,
- 'y' => 20,
- ];
- $objectiveSuffixes = [
- '' => 1,
- 'b' => 1,
- 'j' => 5,
- 'l' => 2,
- 'm' => 10,
- 'n' => 10,
- 'p' => 2,
- 'r' => 10,
- 't' => 2,
- 'v' => 1,
- 'w' => 1,
- 'x' => 1,
- 'z' => 2,
- ];
- $possessiveSuffixes = [
- 'l' => 2,
- 'm' => 3,
- 'mn' => 2,
- 'n' => 3,
- 'r' => 10,
- 'rl' => 4,
- 's' => 10,
- 'sz' => 7,
- 'v' => 3,
- 'w' => 2,
- 'z' => 10,
- ];
- $cull = [
- 'kc',
- 'kd',
- 'uy',
- 'wyi',
- 'yy',
- 'sx',
- 'zx',
- ];
- do {
- $stem = r($stems);
- $mainVowel = r($vowels);
- $vowel = (rand(1, 100) <= $altVowelChance) ? r($vowels) : $mainVowel;
- $subjective = $stem . $vowel;
- $suffix = r($subjectiveSuffixes);
- if ($suffix && !endsWith($subjective, $suffix)) {
- $subjective .= $suffix;
- }
- if (strlen($stem) === 1) {
- $prefix = r($prefixes);
- if ($prefix && $prefix !== $stem) {
- $subjective = $prefix . $subjective;
- }
- }
- $vowel = (rand(1, 100) <= $altVowelChance) ? r($vowels) : $mainVowel;
- $objective = $stem . $vowel;
- $suffix = r($objectiveSuffixes);
- if ($suffix && !endsWith($objective, $suffix)) {
- $objective .= $suffix;
- }
- if (strlen($stem) === 1) {
- $prefix = r($prefixes);
- if ($prefix && $prefix !== $stem) {
- $objective = $prefix . $objective;
- }
- }
- $vowel = (rand(1, 100) <= $altVowelChance) ? r($vowels) : $mainVowel;
- $possessive = $stem . $vowel;
- $suffix = r($possessiveSuffixes);
- if ($suffix && !endsWith($possessive, $suffix)) {
- $possessive .= $suffix;
- }
- if (strlen($stem) === 1) {
- $prefix = r($prefixes);
- if ($prefix && $prefix !== $stem) {
- $possessive = $prefix . $possessive;
- }
- }
- } while(
- $subjective === $objective
- || $subjective === $possessive
- || $objective === $possessive
- || has($subjective, $cull)
- || has($objective, $cull)
- || has($possessive, $cull)
- );
- echo "$subjective / $objective / $possessive\n";
- function r(array $l) {
- $total = 0;
- foreach ($l as $w) {
- $total += $w;
- }
- $s = rand(0, $total);
- $p = 0;
- foreach ($l as $v => $w) {
- $p += $w;
- if ($p >= $s) {
- return $v;
- }
- }
- throw new Exception('should be unreachable');
- }
- function endsWith(string $s, string $e) {
- return substr($s, strlen($s) - strlen($e), strlen($e)) === $e;
- }
- function has(string $s, array $l) {
- foreach ($l as $m) {
- if (strpos($s, $m) !== false) {
- return true;
- }
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement