question: why isn't a byte of a hash more uniform? how could I improve my code to cure that?

Paul Rubin http
Sat Aug 8 07:09:23 CEST 2009

László Sándor <SandorL at> writes:
> OK, I understand. Could anyone suggest a better way to do this, then?
> (Recap: random-looking, close-to uniform assignment of one number out
> of four possibilities to strings.)

Use a cryptographic hash function like md5 (deprecated for security
purposes but should be ok for this application).  The built-in Python
hash function is made for hashing symbols and is designed to avoid
collisions when you have a bunch of sequential identifiers (a,b,c...).
That is, it deliberately does NOT resemble a random function, which
would have a certain number of collisions by chance.

More information about the Python-list mailing list