Skip to content

Instantly share code, notes, and snippets.

@ayushgoel
Created October 1, 2012 11:39
Show Gist options
  • Save ayushgoel/3811112 to your computer and use it in GitHub Desktop.
Save ayushgoel/3811112 to your computer and use it in GitHub Desktop.
Create random contacts CSV
import random
# Change this number to get more contacts
number_of_contacts = 100
# Give FileName here
filename = 'contacts.csv'
all_chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
def create_number():
return ''.join([str(random.randint(0,9)) for i in range(10)])
def get_name(length):
return ''.join([all_chars[random.randint(0,len(all_chars)-1)] for i in range(length)])
if __name__ == '__main__':
with open(filename, 'w') as f:
f.write('First Name,Second Name,Phone\n')
for i in range(number_of_contacts):
f.write(get_name(5) + ',' + get_name(5) + ',' + create_number() + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment