**
**
from os import linesep
from random import Random
def generaterandomrecord(firstnamelength, lastnamelength, gender):
rnd = Random()
generatedline = ""
generatedline += chr(rnd.randint(65, 90))
for index in range(0, firstnamelength):
randomasciinumber = rnd.randint(97, 122)
generatedline += chr(randomasciinumber)
generatedline += " "
generatedline += chr(rnd.randint(65, 90))
for index in range(0, lastnamelength):
randomasciinumber = rnd.randint(97, 122)
generatedline += chr(randomasciinumber)
generatedline += ","
for index in range(0, 10):
generatedline += str(rnd.randint(0, 10) )
generatedline += ","
for index in range(0, gender):
generatedline += chr(rnd.randint(106, 115))
return generatedline
filepath = r"t:\test.txt"
filestream = open(filepath, "w")
rnd = Random()
for index in range(0, 300):
firstnamelength = rnd.randint(3, 5)
lastnamelength = rnd.randint(5,7 )
gender = rnd.randint(106, 115)
filestream.write(generaterandomrecord(firstnamelength, lastnamelength, gender) + linesep)
filestream.flush()
filestream.close()
print("Done processing")
谢谢
答案 0 :(得分:5)
import random
print random.choice("MF")