string random generator (Sorry if too stupid, but i am a beginner)
BPettersen at NAREX.com
Fri Jul 20 13:09:55 EDT 2001
> From: Gustavo Vieira Goncalves Coelho Rios
> Hi folks!
> I am in need for a function that return a string of len x
> random generated, like
> I have the following code: The problem is that i don't known
> how to map a int to a char.
> import random
> def strrnd(n = 24) :
> result = 
> while n :
> n = n - 1
> return result
> How may i get what i want. (Sorry if too basic, but i am a
> python beginner).
> Another problem: This functins will be called thousands of
> time a minute, so performance is a definitive requirement.
Something along these lines should work:
import random, string
res = ''
for i in range(length):
res += random.choice(string.letters)
More information about the Python-list