Skip to content

Instantly share code, notes, and snippets.

@chinying
Created August 31, 2018 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chinying/25a720b68582c328126b03eaa31ee273 to your computer and use it in GitHub Desktop.
Save chinying/25a720b68582c328126b03eaa31ee273 to your computer and use it in GitHub Desktop.
import csv
import random
def randTime(size=500):
timings = [700, 730, 800, 830, 900]
return (random.choices(timings, k=size))
def generate(contents, size=500):
r = [contents[(random.randint(0, len(contents)))]
for i in range(size * 2)]
origins = random.choices()
r = list(map(lambda x: x[0], r)) # postal code is in first column of csv dump
randomTimes = randTime(size)
rows = []
rows.append("Index,Origin,Destination,Time")
for i in range(size):
rows.append("{},{},{},{}".format(i, r[i], r[size+i], randomTimes[i]))
return rows
if __name__ == "__main__":
infile = "./postal_code_to_address.csv"
with open(infile) as csvfile:
csvreader = csv.reader(csvfile, delimiter=',', quotechar='"')
next(csvreader)
contents = list(csvreader)
csvfile.close()
with open("cf-file.csv", 'w') as outfile:
outfile.write("\n".join(generate(contents, 500)))
outfile.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment