In certain controlled environments, such as while running certain CI tests, it may be helpful to selectively disable hash seed randomization, so that hash values and Set/Dictionary orderings remain consistent across executions.
In recent trunk development builds, you can disable hash seed randomization by defining the environment variable SWIFT_DETERMINISTIC_HASHING
with the value of 1
. The Swift runtime looks at this variable during process startup and, if it is defined, replaces the random seed with a constant value.
If you need more control over the seed, please let us know by describing your use case below.
Note that hash randomization has no effect on the performance of Swift programs; however, it is an important factor in the reliability of Set
and Dictionary
, so generally it should not be disabled.
Additionally, setting SWIFT_DETERMINISTIC_HASHING
does not guarantee that hash values remain stable across different versions of the compiler/stdlib -- please do not rely on specific hash values and do not save them across executions.