Have you tried using UUID module? <div><br></div><div>Its pretty handy and comes with base64 encoding function which gives extremely high quality randon strings </div><div><br></div><div>ref: </div><div><a href="http://stackoverflow.com/questions/621649/python-and-random-keys-of-21-char-max">http://stackoverflow.com/questions/621649/python-and-random-keys-of-21-char-max</a></div>
<div><br></div><div><br></div><div><br><div class="gmail_quote">On Tue, Jun 7, 2011 at 3:48 PM, Robin Becker <span dir="ltr"><<a href="mailto:robin@reportlab.com">robin@reportlab.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
A python web process is producing files that are given randomized names of the form<br>
<br>
hhhhhh-YYYYMMDDhhmmss-rrrrrrrr.pdf<br>
<br>
where rrr.. is a 128bit random number (encoded as base62). The intent of the random part is to prevent recipients of one file from being able to guess the names of others.<br>
<br>
The process was originally a cgi script which meant each random number was produced thusly<br>
<br>
<br>
pid is process id, dur is 4 bytes from /dev/urandom.<br>
<br>
random.seed(long(time.time()*someprimeint)|(pid<<64)|(dur<<32))<br>
rrr = random.getrandbits(128)<br>
<br>
<br>
is this algorithm safe? Is it safe if the process is switched to fastcgi and the initialization is only carried out once and then say 50 rrr values are generated.<br>
-- <br>
Robin Becker<br><font color="#888888">
<br>
-- <br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Nitin Pawar<br><br>
</div>