> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kameleoon.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing a variation's allocation according to a user ID

> Override Kameleoon's default variation assignment to deliver consistent variations to authenticated users across devices using a unique user ID.

Kameleoon randomly allocates a variation to a visitor by default. The [statistical paper](https://storage.googleapis.com/kameleoon-storage-documentation/user-manual/pdf/statistics-at-kameleoon.pdf) explains the assignment algorithm logic in the "Kameleoon's assignation algorithm" section. The default function follows:

```
function (experiment)
{
  var registeredVariationId;
  var deviationRandom = experiment.obtainVariationAssignmentRandomNumber();
  var total = 0.0;
  for (var i = 0, l = experiment.variations.length; i < l; ++i)
  {
      total += experiment.variations[i].deviation;
      if (deviationRandom <= total)
      {
          registeredVariationId = experiment.variations[i].id;
          break;
      }
  }
  return registeredVariationId != null ? registeredVariationId : "none";
}
```

Overwrite the default function to change how Kameleoon selects and displays variations. Secure websites can use this to show consistent variations to connected users across platforms and devices:

```
function(experiment)
{
 var memberId = window.member_id.toString(); //CODE to update with your variable that contains the unique identifier. It has to be available before calling the Kameleoon snippet
 memberId = memberId + experiment.id.toString();
 var hash = 0;
 for (i = 0; i < memberId.length; ++i)
 {
 char = memberId.charCodeAt(i);
 hash = ((hash << 5) - hash) + char;
 hash = hash & hash;
 }
 hash = (Math.abs(hash) * 9301 + 49297) % 233280;
 var deviationRandom = hash / 233280;
 var total = 0.0;
 for (var i = 0, l = experiment.variations.length; i < l; ++i)
 {
 total += experiment.variations[i].deviation;
 if (deviationRandom <= total)
 {
 chosenVariationId = experiment.variations[i].id;
 break;
 }
 }
return registeredVariationId != null ? registeredVariationId : "none";
}
```

Add the custom code to the account's advanced options:

1. Log in to the [Kameleoon account](https://login.kameleoon.com/app).
2. Click **Admin** > **Projects**.
3. Click **Configuration** on the website card.

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/variations-allocation/website-configuration.png)
</Frame>

4. Add the script above in the **Variation selection script** field.

<Frame>
  ![](https://storage.googleapis.com/kameleoon-storage-documentation/developers/images/variations-allocation/variation-selection-script.png)
</Frame>
