A deterministic hash for arbitray objects
Python's default hash
will give different results each process invocation, in order to thwart
denial-of-service attacks based on intentionally triggering hash collisions (see -R
in Python's
CLI options). Even setting PYTHONHASHSEED
is not enough, because the hash can still use
non-deterministic data such as pointer-addresses. By default, this package uses the xxhash
algorithm, which is the fastest non-cryptographic hash I know of.
If you don't have pip
installed, see the pip install
guide.
$ pip install charmonium.determ_hash
>>> from charmonium.determ_hash import determ_hash
>>> determ_hash(b"hello world")
141361478936837800319111455324245712876