<@U07FJ89LFFB> How does deterministic hashing work...
# ask-ai
b
@brash-pillow-71627 How does deterministic hashing work?
o
A message from kapa.ai
Deterministic hashing is a method used by GrowthBook to ensure that the same user always gets assigned the same variation in an experiment. This is done by hashing together the
hashAttribute
(the user attribute used to assign a variation, ex: user id) and the experiment
trackingKey
. This produces a decimal between 0 and 1. Each variation is then assigned a range of values (e.g.
0 to 0.5
and
0.5 to 1.0
) and the user is assigned to whichever one their hash falls into. Here's an example of how you can customize this hashing behavior in GrowthBook:
Copy code
javascript gb.run({     key: "my-experiment",     variations: ["A", "B"],     hashVersion: 2,     seed: "abcdef123456",     hashAttribute: "device_id",   });
In this example, the
hashAttribute
is set to
device_id
, meaning the device ID is used as the user attribute for assigning a variation. The
hashVersion
is set to
2
, which is the latest and recommended version of the hashing algorithm. The
seed
is set to a custom value, which is used instead of the experiment key for the hashing process. Please note that if you change the experiment configuration, some users may switch their assigned variation. This is because the hash value will change if the inputs (i.e., the
hashAttribute
or
trackingKey
) change. To avoid this, it's recommended to treat experiments as immutable once they are running. For more information, you can refer to the [GrowthBook documentation on hashing](https://docs.growthbook.io/lib/js#hashing) and the [FAQ section](https://docs.growthbook.io/faq) on deterministic hashing.