Creating a Variety of Dummy Order Ids in Python
I have a work task to give our sales reps a tool where they can add dummy customer requests into our system. Since we ingest data from a variety of vendors, we have “order ids” that are in a variety of formats. And our sales reps wanted to see the dummy data represent the variety of formats.
For example, some order ids are a short string of letters and digits (e.g., “1YK2P”), other order is are strings of digits (e.g., “6993027”), or even compound strings of digits (e.g., “9098930-6908420”)
I chose to use Python’s random functions in order to get some variety. First, I used if random.randint(1, 1000000) % 4 == 0: to decide the format of an order id. In this case, I wanted the particular order id format to be under-represented. This will get the format chosen about 25% of the time.
Three quarters of the time, we go into the other branch. In this case, we’re using if random.randint(1, 1000) % 2 == 0: to do a 50/50 split between choosing a string with letter and digits versus digits only.
Here is the function and a little test loop that calls the function and prints out some generated order ids.
import random
import string
def get_new_order_id():
new_order_id = ''
if random.randint(1, 1000000) % 4 == 0:
# Occasionally get an order id that has a different style
new_order_id = '{0}-{1}'.format(random.randint(1000000, 10000000), random.randint(1000000, 10000000))
else:
if random.randint(1, 1000) % 2 == 0:
character_pool = '{0}{1}'.format(string.ascii_uppercase, string.digits)
dummy_id_length = 5
else:
character_pool = '{0}'.format(string.digits)
dummy_id_length = 7
for i in range(dummy_id_length):
index = random.randint(0, len(character_pool) - 1)
new_order_id += character_pool[index]
return new_order_id
for i in range(10):
print('New order id: {0}'.format(get_new_order_id()))
And here’s the output from running the program (python3 dummy_customer_ids.py):
New order id: 9861208-2900156 New order id: 6778559 New order id: 7593421 New order id: 3170423-6228037 New order id: 5890167 New order id: HH0KC New order id: 5867390 New order id: X03N4 New order id: 6206263-8881841 New order id: 8191531-7848540
Hopefully you find some interesting uses for those random functions!
