Inside of the Hashable
we can see:
/// Hash values are not guaranteed to be equal across different executions of
/// your program. Do not save h
Hash randomization was enforced in Swift 4.2, with the implementation of SE 0206 Hashable Enhancements. From the proposal:
However, Hasher may generate entirely different hash values in other executions, even if it is fed the exact same byte sequence. This randomization is a critical feature, as it makes it much harder for potential attackers to predict hash values. Hashable has always been documented to explicitly allow such nondeterminism.
In addition, it allows the actual implementation to be changed (e.g. improved) in the Swift standard library, without breaking compatibility.
For debugging purposes the hash randomization can be disabled by defining the SWIFT_DETERMINISTIC_HASHING environment variable with a value of 1.
The implementation of the Swift standard hasher can be found in the open source repository:
It is based on SipHash.