# ------------------------------------------------------ # A quick Python module for generating random "names" # (i.e., pairs of short strings of letters, capitalized) # For WU CS 241: Data Structures, Fall 2020; Fritz Ruehr # ------------------------------------------------------ # We use the standard Python random module for choices and # random ranges (randrange) # # See: import random alphabet = 'abcdefghijklmnopqrstuvwxyz' # A name is the join of some random choices of alphabetic # letters, of length k, where k is itself a choice of a # number between parameters min and max, then capitalized. def name(min,max): return ( ''.join ( random.choices( alphabet, k = random.randrange(min,max) )) ).capitalize() # first names tend to be shorter, last names a bit longer def firstname(): return name(3,8) def lastname(): return name(5,10) # A quick test function to print out ten random names def test(): for i in range(10): print(firstname(), lastname()) # ------------------------------------------------------