Issue
I'm using hashing of strings for seeding random states in the following way:
context = "string"
seed = hash(context) % 4294967295 # This is necessary to keep the hash within allowed seed values
np.random.seed(seed)
This is unfortunately (for my usage) non-deterministic between runs in Python 3.3 and up. I do know that I could set the PYTHONHASHSEED
environment variable to an integer value to regain the determinism, but I would probably prefer something that feels a bit less hacky, and won't entirely disregard the extra security added by random hashing. Suggestions?
Solution
Use a purpose-built hash function. zlib.adler32()
is an excellent choice; alternatively, check out the hashlib
module for more options.
Answered By - user149341
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.