Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os.path
- import random
- import time
- # Name generator easy proto :)
- # by LarsKort
- # @nType - fileName, better use name of race.
- # @gender - "M" = Male, "F" = Female, "N" = nogender.
- # @seed - generate one cool name everytime by numeric seed.
- def rand(min, max, seed = None):
- # Seeded name
- # Works only if @seed is (int) type and != None.
- # Else use randomizr
- if (seed != None): seed = int(time.time())
- rand = random.seed(seed)
- return random.randint(min, max)
- def generateName(nType = "elf", gender = "", seed = None):
- # FileNames specification
- # nType_X = base names file
- # nType_X.suff.db = suffix file
- dbName = nType + "_" + gender + ".db"
- dbSuff = nType + "_" + gender + ".suff.db"
- if not os.path.exists(dbName):
- print("Name dbfile not found. Stopping")
- exit()
- if not os.path.exists(dbSuff):
- print("Suffix dbfile not found. Stopping")
- exit()
- # Read name-base from file.
- names = open(dbName, 'r', encoding='utf-8')
- allNames = names.read().split('\n')
- names.close()
- # Read end-suffix from suffix file.
- suff = open(dbSuff, 'r', encoding='utf-8')
- allSuff = suff.read().split('\n')
- suff.close()
- index_name = rand(0, len(allNames)) - 1
- index_suff = rand(0, len(allSuff)) - 1
- return allNames[index_name] + allSuff[index_suff]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement