Random string

Carsten Geckeler carsten.dot.geckeler at gmx.dot.de
Tue Dec 5 17:42:40 EST 2000


On Mon, 4 Dec 2000, Jay O'Connor wrote:

> 	Is there a good algorithm or existing function for creating a random string such
> as "AFYGADFGWETOQW6DSJD", suitable as a 'session id' for a web session

A very straight forward way is:

import whrandom
str = ""
for i in range(20):
	str = str + chr(whrandom.randint(ord("A"), ord("Z")))

Not very fancy, but it works.  But you still have to check if it's unique.

Cheers, Carsten
-- 
Carsten Geckeler:  carsten dot geckeler at gmx dot de
To get proper email-address replace `dot' and `at' by the corresponding symbols.





More information about the Python-list mailing list