PYTHONHASHSEED

The environment variable that controls the seed Python uses to randomise str, bytes and datetime hashes.

A fixed or disabled seed in production brings back the hash-flooding weakness.

In more detail

If it is unset or set to "random", each process picks a random seed. Setting it to an integer fixes the seed so hash values and set iteration order repeat between runs, and 0 turns randomisation off entirely. Fixed seeds are for reproducible tests and debugging only.

Example

PYTHONHASHSEED=0 python3 -c "print(hash('apple'))"

Related terms

Taught in

References