string random generator (Sorry if too stupid, but i am a beginner)

Gustavo Vieira Goncalves Coelho Rios gustavo at ifour.com.br
Fri Jul 20 13:03:30 EDT 2001


Hi folks!

I am in need for a function that return a string of len x random generated, like

strrnd(5)
'Df%d^'

strrnd(2)
'&@'


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
		result.append(random.randrange(1,255,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.


-- 
Whatever became of eternal truth?




More information about the Python-list mailing list