# Universal Unique Identifier (UUID)

## Overview

This page contains recommendations for using Universal Unique Identifier (UUID).

## General

<div align="left"><img src="https://1795604890-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaH8j4W1MtabOUlUc8Trn%2Fuploads%2Fgit-blob-b41291c03c4de901e1f0faa235c5ad68838b2947%2Ftype-base-icon.svg?alt=media" alt=""></div>

* Do **not** use UUID as a random value. UUID is a unique value, not random. There is no a way to guarantee randomness, [especially for versions != 4](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions).
* Do **not** use UUID as a session identifier.
* You can use a UUID as a unique value for objects, such as a bank card ID or upload file name.

## UUID generation

<div align="left"><img src="https://1795604890-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FaH8j4W1MtabOUlUc8Trn%2Fuploads%2Fgit-blob-b41291c03c4de901e1f0faa235c5ad68838b2947%2Ftype-base-icon.svg?alt=media" alt=""></div>

{% tabs %}
{% tab title="Go" %}
You can use the [google/uuid](https://pkg.go.dev/github.com/google/uuid) package to generate UUID values in Go.

```go
import "github.com/google/uuid"

func GenerateNewUUIDValue() string {
    return uuid.New().String()
}
```
{% endtab %}

{% tab title="Java" %}
Use the [java.util.UUID](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/UUID.html) class to generate UUID values.

```java
import java.util.UUID;

public static String generateUUIDv4() {
    return UUID.randomUUID().toString();
}
```
{% endtab %}

{% tab title="Node.js" %}
Use the [uuid](https://www.npmjs.com/package/uuid) package to generate UUID values.

```javascript
import { v4 as uuidv4 } from 'uuid';
uuidv4();
```
{% endtab %}

{% tab title="Python" %}
Use the [uuid](https://docs.python.org/3/library/uuid.html) package to generate UUID values.

```python
import uuid

def generate_uuid_v4() -> str:
    return str(uuid.uuid4())
```
{% endtab %}
{% endtabs %}
