Generating a large random string
Andreas Lobinger
andreas.lobinger at netsurf.de
Thu Feb 19 10:23:50 EST 2004
Aloha,
i wanted to ask another problem, but as i started to build an example...
How to generate (memory and time)-efficient a string containing
random characters? I have never worked with generators, so my solution
at the moment is:
import string
import random
random.seed(14)
d = [random.choice(string.letters) for x in xrange(3000)]
s = "".join(d)
print s
which is feasible for the 3000, but i need lengths in the range
10.000 to 1.000.000.
Hoping for an answer and wishing a happy day
LOBI
More information about the Python-list
mailing list