Home Generating random names in Python
Post
Cancel

Generating random names in Python

This script shows how to produce a pseudo-random list of proper names, state names and colors plus a timestamp. This script has no purpose except to show a few conventions in python.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3

import array as arr
import random
from datetime import datetime

def random_element (list_num: int):
    array_names = ["Fred", "James", "Susan", "Paul", "Donella", "John", "Abel", "Cain", "Joseph", "Mary", "Jane", "Nancy", "Lewis", "George"]
    state_names = ["Alaska", "Alabama", "Arkansas", "American Samoa", "Arizona", "California", "Colorado", "Connecticut", "District of Columbia", "Delaware", 
                    "Florida", "Georgia", "Guam", "Hawaii", "Iowa", "Idaho", "Illinois", "Indiana", "Kansas", "Kentucky", "Louisiana",
                    "Massachusetts", "Maryland", "Maine", "Michigan", "Minnesota", "Missouri", "Mississippi", "Montana", "North Carolina", 
                    "North Dakota", "Nebraska", "New Hampshire", "New Jersey", "New Mexico", "Nevada", "New York", "Ohio", "Oklahoma", "Oregon", 
                    "Pennsylvania", "Puerto Rico", "Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", 
                    "Virginia", "Virgin Islands", "Vermont", "Washington", "Wisconsin", "West Virginia", "Wyoming"]
    color_names = ["Absolute Zero","Acid green","Aero","African violet","Air superiority blue","Alice blue","Alizarin","Alloy orange","Almond",
                    "Amaranth deep purple","Amaranth pink","Amaranth purple","Amazon","Amber","Amethyst","Android green","Antique brass","Antique bronze",
                    "Antique fuchsia","Antique ruby","Antique white","Apricot","Aqua","Aquamarine","Arctic lime","Artichoke green","Arylide yellow","Ash gray",
                    "Atomic tangerine","Aureolin","Azure","Azure (X11/web color)","Baby blue","Baby blue eyes","Baby pink","Baby powder","Baker-Miller pink",
                    "Banana Mania","Barn red","Battleship grey","B'dazzled blue","Beau blue","Beaver","Beige","Big dip o’ruby","Bisque","Bistre","Bistre brown",
                    "Bitter lemon","Black","Black bean","Black coral","Black olive","Black Shadows","Blanched almond","Blast-off bronze","Bleu de France",
                    "Blizzard blue","Blood red","Blue","Blue bell","Blue (Crayola)","Blue-gray (Crayola)","Blue jeans","Blue (Munsell)","Blue (NCS)",
                    "Blue (Pantone)","Blue (pigment)","Blue sapphire","Bluetiful","Blue-violet","Blue yonder","Blush","Bole","Bone","Brick red","Bright lilac",
                    "Bright yellow (Crayola)","Bronze","Brown sugar","Bud green","Buff","Burgundy","Burlywood","Burnished brown","Burnt orange","Burnt sienna",
                    "Burnt umber","Byzantine","Byzantium","Cadet blue","Cadet grey","Cadmium green","Cadmium orange","Café au lait","Café noir",
                    "Cambridge blue","Camel","Cameo pink","Canary","Canary yellow","Candy pink","Cardinal","Caribbean green","Carmine","Carmine (M&P)"]
    
    if (list_num == 1):
        return random.choice(array_names)
    if (list_num == 2):
        return random.choice(state_names)
    if (list_num == 3):
        return random.choice(color_names)

def main():
    count = 0
    while (count < 10):
        count = count + 1
        random_name = random_element(1)
        random_state = random_element(2)
        random_color = random_element(3)
        print(random_name, " -> ", random_state, " --- ", random_color, " ---", datetime.now())


if __name__ == "__main__":
    main()

Output:

1
2
3
4
5
6
7
8
9
10
11
$ ./first.py 
Paul  ->  Idaho  ---  Air superiority blue  --- 2022-12-19 16:29:18.870064
Joseph  ->  Alaska  ---  Brick red  --- 2022-12-19 16:29:18.870142
Mary  ->  New Jersey  ---  Blue (pigment)  --- 2022-12-19 16:29:18.870177
John  ->  Michigan  ---  Arylide yellow  --- 2022-12-19 16:29:18.870209
James  ->  Indiana  ---  Almond  --- 2022-12-19 16:29:18.870231
George  ->  Montana  ---  Carmine (M&P)  --- 2022-12-19 16:29:18.870274
Fred  ->  Alaska  ---  Cadet blue  --- 2022-12-19 16:29:18.870315
Nancy  ->  Minnesota  ---  Antique ruby  --- 2022-12-19 16:29:18.870336
Donella  ->  Oregon  ---  Blue-gray (Crayola)  --- 2022-12-19 16:29:18.870391
George  ->  Kentucky  ---  Black olive  --- 2022-12-19 16:29:18.870408
This post is licensed under CC BY 4.0 by the author.