Created
August 19, 2012 06:37
-
-
Save aeter/3392763 to your computer and use it in GitHub Desktop.
db random data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import string | |
ALPHABET = string.ascii_lowercase | |
DIGITS = string.digits | |
def make_random_string(_len, seq): | |
return ''.join([random.choice(seq) for _ in range(_len)]) | |
def make_first_name(_len): | |
return make_random_string(_len, ALPHABET) | |
def make_last_name(_len): | |
return make_random_string(_len, ALPHABET) | |
def make_phone_number(_len): | |
return make_random_string(_len, DIGITS) | |
def make_year(): | |
return make_random_string(4, DIGITS) | |
def make_month(): | |
return make_random_string(2, DIGITS) | |
def make_day(): | |
return make_random_string(2, DIGITS) | |
def make_date_of_birth(): | |
return "%s-%s-%s" % (make_year(), make_month(), make_day()) | |
def make_employee_id(num): | |
return str(num) | |
def main(): | |
with open("data.csv", "a") as f: | |
for num in range(1, 1000): | |
data = [ | |
make_employee_id(num), | |
make_first_name(10), | |
make_last_name(15), | |
make_date_of_birth(), | |
make_phone_number(9), | |
] | |
f.write(",".join(data)) | |
f.write('\n') | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment