Why doesn't Python hash function give the same values when run on Android implementation?

前端 未结 5 725
-上瘾入骨i
-上瘾入骨i 2020-12-09 15:44

I believed that hash() function works the same in all python interpreters. But it differs when I run it on my mobile using python for android. I get same hash v

5条回答
  •  青春惊慌失措
    2020-12-09 16:26

    hash() is randomised by default each time you start a new instance of recent versions (Python3.3+) to prevent dictionary insertion DOS attacks

    Prior to that, hash() was different for 32bit and 64bit builds anyway.

    If you want something that does hash to the same thing every time, use one of the hashes in hashlib

    >>> import hashlib
    >>> hashlib.algorithms
    ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
    

提交回复
热议问题