# 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/6000.7/script-reference/unity/localization.md)
* **Assembly:** UnityEngine.LocalizationRuntimeModule
* **Implements:** [IKeyGenerator](/engine/6000.7/script-reference/unity/localization/ikeygenerator.md)

```csharp
public class DistributedUIDGenerator : IKeyGenerator
```

## 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/6000.7/script-reference/unity/localization/distributeduidgenerator/customepoch.md) (41 bits). The machine id is derived from [\_deviceUniqueIdentifier](/engine/6000.7/script-reference/unityengine/systeminfo/deviceuniqueidentifier.md) so it is stable per machine. Assign an instance to [SharedTableData.KeyGenerator](/engine/6000.7/script-reference/unity/localization/sharedtabledata/keygenerator.md) to control how a collection assigns key ids, or implement [IKeyGenerator](/engine/6000.7/script-reference/unity/localization/ikeygenerator.md) for a different scheme.

Additional Resources: [IKeyGenerator](/engine/6000.7/script-reference/unity/localization/ikeygenerator.md), [SharedTableData](/engine/6000.7/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/6000.7/script-reference/unity/localization/distributeduidgenerator/ctor.md#distributeduidgenerator\(\))                 | Creates a generator that measures timestamps from the current time. |
| [DistributedUIDGenerator(System.Int64)](/engine/6000.7/script-reference/unity/localization/distributeduidgenerator/ctor.md#distributeduidgenerator\(long\)) | Creates a generator that measures timestamps from a specific epoch. |

## Properties

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

## Methods

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