Produce predictable hash values for a given seed and n using MD5. The value can be arbitrary as long as it is deterministic and has a uniform distribution. The MD5 hash is used to produce a 16 character hexadecimal string which is then converted to a 64-bit integer.
(n: int, seed: int)
| 83 | |
| 84 | |
| 85 | def generate_hash(n: int, seed: int): |
| 86 | """Produce predictable hash values for a given seed and n using MD5. |
| 87 | |
| 88 | The value can be arbitrary as long as it is deterministic and has a uniform |
| 89 | distribution. The MD5 hash is used to produce a 16 character hexadecimal |
| 90 | string which is then converted to a 64-bit integer. |
| 91 | """ |
| 92 | value = bytes([seed] * 64 + [n] * 64) |
| 93 | hasher = hashlib.md5(value) |
| 94 | return hasher.hexdigest()[:16] |
| 95 | |
| 96 | |
| 97 | def generate_hashtable(seed: int, length=256): |
no test coverage detected