• SatyrSack@feddit.org
    link
    fedilink
    English
    arrow-up
    1
    ·
    3 hours ago

    For fun, I just ported it to Python

    source
    from random import random
    import math
    
    startStrings = [
      "B",
      "Br",
      "J",
      "F",
      "S",
      "M",
      "C",
      "Ch",
      "L",
      "P",
      "K",
      "W",
      "G",
      "Z",
      "Tr",
      "T",
      "Gr",
      "Fr",
      "Pr",
      "N",
      "Sn",
      "R",
      "Sh",
      "St"
    ]
    connectiveStrings = [
      "ll",
      "tch",
      "l",
      "m",
      "n",
      "p",
      "r",
      "s",
      "t",
      "c",
      "rt",
      "ts"
    ]
    
    vowelStrings = [
      "a",
      "e",
      "i",
      "o",
      "u"
    ]
    
    endStrings = [
      "ie",
      "o",
      "a",
      "ers",
      "ley"
    ]
    vowelDictionary1 = {
      "a": [
        "nie",
        "bell",
        "bo",
        "boo",
        "bella",
        "s"
      ],
      "e": [
        "ll",
        "llo",
        "",
        "o"
      ],
      "i": [
        "ck",
        "e",
        "bo",
        "ba",
        "lo",
        "la",
        "to",
        "ta",
        "no",
        "na",
        "ni",
        "a",
        "o",
        "zor",
        "que",
        "ca",
        "co",
        "mi"
      ],
      "o": [
        "nie",
        "ze",
        "dy",
        "da",
        "o",
        "ver",
        "la",
        "lo",
        "s",
        "ny",
        "mo",
        "ra"
      ],
      "u": [
        "rt",
        "mo",
        "",
        "s"
      ]
    }
    
    vowelDictionary2 = {
      "a": [
        "nny",
        "sper",
        "trina",
        "bo",
        "-bell",
        "boo",
        "lbert",
        "sko",
        "sh",
        "ck",
        "ishe",
        "rk"
      ],
      "e": [
        "lla",
        "llo",
        "rnard",
        "cardo",
        "ffe",
        "ppo",
        "ppa",
        "tch",
        "x"
      ],
      "i": [
        "llard",
        "lly",
        "lbo",
        "cky",
        "card",
        "ne",
        "nnie",
        "lbert",
        "nono",
        "nano",
        "nana",
        "ana",
        "nsy",
        "msy",
        "skers",
        "rdo",
        "rda",
        "sh"
      ],
      "o": [
        "nie",
        "zzy",
        "do",
        "na",
        "la",
        "la",
        "ver",
        "ng",
        "ngus",
        "ny",
        "-mo",
        "llo",
        "ze",
        "ra",
        "ma",
        "cco",
        "z"
      ],
      "u": [
        "ssie",
        "bbie",
        "ffy",
        "bba",
        "rt",
        "s",
        "mby",
        "mbo",
        "mbus",
        "ngus",
        "cky"
      ]
    }
    
    def randomNumberBetween(bottom, top):
      diff = top - bottom
      rando = math.floor(random() * (diff))
      return rando + bottom
    
    def randomNumberNext(num):
      return randomNumberBetween(0, num)
    
    def randoNext(num1, num2 = None):
      if (num2 == None):
        return randomNumberNext(num1)
      else:
        return randomNumberBetween(num1, num2)
    
    def namer():
      source = ""
      str1 = ""
      num = randoNext(3, 6)
    
      # Get start of string
      source = str1 + startStrings[randoNext(len(startStrings) - 1)]
    
      # Add some chars from array 2 or array 3
      for index in range(1, num - 1):
        source = source + vowelStrings[randoNext(len(vowelStrings))] if index % 2 != 0 else source + connectiveStrings[randoNext(len(connectiveStrings))]
    
        # Stop if greater than the number
        if (len(source) >= num):
          break
    
      char = ''
      currentLastLetter = source[len(source) - 1]
    
      # if last letter is not a vowel and 50% chance, add some letters
      if (random() < 0.5 and (currentLastLetter not in vowelStrings)):
        source += endStrings[randoNext(len(endStrings))]
    
      # otherwise if the last letter is a vowel
      elif (currentLastLetter in vowelStrings):
        # if 80 percent chance
        if (random() < 0.8):
          newCurrentLastLetter = source[len(source) - 1]
          char = newCurrentLastLetter
    
          # if its short add something from voweldict2
          if len(source) <= 3:
            maxValue = len(vowelDictionary2[char]) - 1
            index2 = randoNext(maxValue)
            str3 = vowelDictionary2[newCurrentLastLetter][index2]
    
            source = source + str3
          # if its long add something from voweldict1
          else:
            maxValue = len(vowelDictionary1[char]) - 1
            index2 = randoNext(maxValue)
            str3 = vowelDictionary1[newCurrentLastLetter][index2]
    
            source = source + str3
      # otherwise add a vowel
      else:
        source += vowelStrings[randoNext(len(vowelStrings))]
    
      # from end of the source, every character
      for index in range(len(source) - 1, 2):
        # get the character
        char = source[index];
        
        # if its a vowel
        if char in vowelStrings:
          # get the two to last letter
          char = source[index - 2]
          
          # if its also a vowel
          if char in vowelStrings:
            # find the letter in between and add a letter to it
            # so "noco" turns into "nocko" etc
            char = source[index - 1]
            match char:
              case 'c' | 'r':
                source = source[0, index] + 'k' + source[index]
                index -= 1
                continue
              case 'l':
                source = source[0, index] + 'n' + source[index]
                index -= 1
                continue
              case _:
                continue
    
      # small percent chance of doubling the string if its shourt. a la ka-ka
      if len(source) <= 3 and random() < 0.1:
        source = source + source if random() < 0.5 else source + '-' + source
    
      # maybe add an m, p, or b, if there's an e at the end
      if len(source) <= 2 and source[len(source) - 1] == 'e':
        source += 'm' if random() < 0.3 else 'p' if random() < 0.5 else 'b'
    
      # blacklist words
      blacklist = [
        'sex',
        'taboo',
        'fuck',
        'rape',
        'cock',
        'willy',
        'cum',
        'goock',
        'trann',
        'gook',
        'bitch',
        'shit',
        'pusie',
        'kike',
        'nigg',
        'puss'
      ]
      for expletive in blacklist:
        if expletive in source:
          source = 'Bobo' if random() > 0.5 else 'Wumbus'
    
      return source
      
    if __name__ == '__main__':
      print(namer())