Select Page

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.

And here’s the output from running the program (python3

Hopefully you find some interesting uses for those random functions!

Share This