# DistributedUIDGenerator

> The default key generator. It produces a distributed unique id, Snowflake-style, that combines a timestamp, a machine id, and a per-millisecond sequence.

## Definition

* **Type:** Class
* **Namespace:** [Unity.Localization](/engine/7000.0/script-reference/unity/localization.md)
* **Assembly:** UnityEngine.LocalizationRuntimeModule
* **Implements:** [IKeyGenerator](/engine/7000.0/script-reference/unity/localization/ikeygenerator.md), [ISerializationCallbackReceiver](/engine/7000.0/script-reference/unityengine/iserializationcallbackreceiver.md)

```csharp
public class DistributedUIDGenerator : IKeyGenerator, ISerializationCallbackReceiver
```

## Remarks

The generated ids are non-sequential, so several users can add keys to the same table without id collisions. The id packs a per-millisecond sequence (12 bits), a machine id (10 bits), and a timestamp measured from [DistributedUIDGenerator.CustomEpoch](/engine/7000.0/script-reference/unity/localization/distributeduidgenerator/customepoch.md) (41 bits). Timestamps count from a fixed default epoch of 2020-01-01T00:00:00Z, and every generator in the process draws from one sequence counter, so two default generators created at the same moment still hand out different ids. The machine id is derived from [SystemInfo.deviceUniqueIdentifier](/engine/7000.0/script-reference/unityengine/systeminfo/deviceuniqueidentifier.md) so it is stable per machine. Assign an instance to [SharedTableData.KeyGenerator](/engine/7000.0/script-reference/unity/localization/sharedtabledata/keygenerator.md) to control how a collection assigns key ids, or implement [IKeyGenerator](/engine/7000.0/script-reference/unity/localization/ikeygenerator.md) for a different scheme.

Additional Resources: [IKeyGenerator](/engine/7000.0/script-reference/unity/localization/ikeygenerator.md), [SharedTableData](/engine/7000.0/script-reference/unity/localization/sharedtabledata.md)

Generate two ids and confirm they differ.

## Examples

```csharp
using Unity.Localization;
using UnityEngine;

namespace Unity.Localization.Samples
{
    public class DistributedUIDGeneratorOverviewExample
    {
        public void Run()
        {
            var generator = new DistributedUIDGenerator();

            var first = generator.GetNextKey();
            var second = generator.GetNextKey();

            Debug.Log(first != second);   // True: ids are unique
        }
    }
}
```

## Constructors

| Constructor                                                                                                                                                 | Description                                                          |
| ----------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------- |
| [DistributedUIDGenerator()](/engine/7000.0/script-reference/unity/localization/distributeduidgenerator/ctor.md#distributeduidgenerator\(\))                 | Creates a generator that measures timestamps from the default epoch. |
| [DistributedUIDGenerator(System.Int64)](/engine/7000.0/script-reference/unity/localization/distributeduidgenerator/ctor.md#distributeduidgenerator\(long\)) | Creates a generator that measures timestamps from a specific epoch.  |

## Properties

| Property                                                                                                 | Description                                                         |
| -------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------- |
| [CustomEpoch](/engine/7000.0/script-reference/unity/localization/distributeduidgenerator/customepoch.md) | The epoch, in Unix milliseconds, that timestamps are measured from. |
| [MachineId](/engine/7000.0/script-reference/unity/localization/distributeduidgenerator/machineid.md)     | The machine id folded into each id.                                 |

## Methods

| Method                                                                                                 | Description                             |
| ------------------------------------------------------------------------------------------------------ | --------------------------------------- |
| [GetNextKey](/engine/7000.0/script-reference/unity/localization/distributeduidgenerator/getnextkey.md) | Returns the next distributed unique id. |
