SHARE
TWEET

Untitled

a guest Jul 17th, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var bigrams_en = {
  2.   '^': 'AAABBBCCCDDDEEFFFGGGHHHIIJJKKLLLMMMNNNOOOPPPQRRRSSSTTTUUVVVWWZZ',
  3.   'A': 'BBBCCCDDDEFFGGGHHHIJKKKLLLMMMNNNPPPQRRRSSSTTTVVVWXZ',
  4.   'B': 'AAACDDEEEFHIIILLLNNNOOOPRRRSSSTUUVVYZ',
  5.   'C': 'AAACDEEEGHHHHHHHHIIKKKKKKKLLLMMNNOOOPQRRRTTTTUUV',
  6.   'D': 'AAADEEEHIIIOOORRRSSTTUUUVVY',
  7.   'E': 'AAABBBCCCDDDEFFFGGGHIJLLLMMMNNNOPPPQQQRRRSSSTTUUUVWXXXZ',
  8.   'F': 'AAAEEEFIIIKLLLOOORRRTTUUU',
  9.   'G': 'AAABCDEEEFGGHHHHIIILLLNNNOOORRRTUUUVVWY',
  10.   'H': 'AAAEEEIIIKKKLLLMOOORSTYY',
  11.   'I': 'AABBBCCCDDDEFGGGLLLMMMNNNOOPPPQRRRSSSTTTUUUVZ',
  12.   'J': 'AAAEEEHHHIOOOUUU',
  13.   'K': 'AAEEEHHIIILMMNOOORRSTVV',
  14.   'L': 'AAABDDEEEFGHIIIKKKLLMNOOOPSTTTUUUVYY',
  15.   'M': 'AAABEEEIIIKMNNOOOPPPQRRRSSSTUUUYY',
  16.   'N': 'AAACDEEEFGIIJKLMNNOOOPQRRSSTTUUVVY',
  17.   'O': 'ABBCCCDDDEFFFGGGHKLLMMMNNNOPPPRRRSSSTVVWWZZ',
  18.   'P': 'AAADEEEHHHHHHIIILLLOOOPRRRSSTTUVY',
  19.   'Q': 'UUUVVVY',
  20.   'R': 'AAACCCDDDEEEGGGHHHIIIKKKLMMMNNNOOOPQRSSSTTTUVYZ',
  21.   'S': 'AAABBCCDEEEGHHHHHHHHHHHHHHHHHIIIKKKLLLMMNNOOOPPPQQRSSTTTTTTUVWWWY',
  22.   'T': 'AAACEEEHHHHHHHHHHIIIKKLMNOOORRRRTUUU',
  23.   'U': 'AACCDDDEEEGGHIIKLLLMMMNOOPPPQRRSSTT',
  24.   'V': 'AAABCDEEEGHIIIKLLOOORU',
  25.   'W': 'AAEEEHHHHHIIIOOORRRST',
  26.   'X': 'EEEIIPPPQQQTTT',
  27.   'Y': 'AEEEILLLOOORRRSX',
  28.   'Z': 'AIIIMMMOOOZ',
  29. }
  30. var vowels_en = 'AEIOUY';
  31.  
  32. function generateCode_old(locale) {
  33.   var bigrams = locale == bigrams_en;
  34.   var vowels = locale == vowels_en;
  35.  
  36.   var len = 6;
  37.   var code = bigrams['^'][Math.floor(Math.random() * bigrams['^'].length)];
  38.   var prev = code;
  39.   var prevVowel = vowels.indexOf(prev) > -1;
  40.   var run = 1;
  41.   for (var i = 0; i < len; i++) {
  42.     var next, nextVowel, done;
  43.     do {
  44.       next = bigrams[prev][Math.floor(Math.random() * bigrams[prev].length)];
  45.       nextVowel = vowels.indexOf(next) > -1;
  46.       done = true;
  47.       if (prevVowel == nextVowel) {
  48.         // 4 гласных или согласных подряд: запретить совсем
  49.         if (run >= 3) {
  50.           done = false;
  51.         } else
  52.         // 2 одинаковых гласных + гласная, 2 одинаковых согласных + согласная
  53.         if ((run >= 2) && (prev == code[code.length - 2])) {
  54.           done = false;
  55.         } else
  56.         // 3 гласных подряд
  57.         if ((run >= 2) && prevVowel) {
  58.           done = false;
  59.         } else
  60.         // 3 согласных подряд: запретить в 66% случаев
  61.         if ((run >= 2) && (Math.random() > 0.333)) {
  62.           done = false;
  63.         }
  64.       }
  65.     } while (!done);
  66.     code += next;
  67.     prev = next;
  68.     if (prevVowel == nextVowel) {
  69.       run++;
  70.     } else {
  71.       prevVowel = nextVowel;
  72.       run = 1;
  73.     }
  74.   }
  75.  
  76.   return code;
  77. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top