I'm trying to make a random NPC generator in Python--the last time I tried this, it was in PHP, and that went. . . strangely. What I'd like to be able to do with this is to call the defined variables within the string multiple times. I can do that by running a for i in range(n)
loop, but that gets me the same random choice every time.
I've been looking, and I'm not totally sure that I've found how to call that function multiple times and get different results each time.
import random
gend = [ 'male', 'female' ]
race = [ 'Human', 'Elf', 'Orc', 'Halfling', 'Gnome', 'Half-Elf', 'Half-Orc', 'Outsider' ]
pers = [ 'leader-like, optimistic', 'bad-tempered, irritable', 'relaxed, peaceful', 'quiet, analytical' ]
hook = [ 'a chore that needs doing', "some concerns for another's well-being", 'an item that needs retrieving/delivering',
'a grudge', 'a person/organization in their way', 'a target on his or her back', 'an indiscretion that needs covering up',
'a debt that needs paying' ]
randgend = random.choice(gend)
randrace = random.choice(race)
randpers = random.choice(pers)
randhook = random.choice(hook)
print("A {} {}, with a {} disposition and {}.".format(randgend, randrace, randpers, randhook))
Aucun commentaire:
Enregistrer un commentaire