# Universal Unique Identifier (UUID)

## Overview

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

## General

<div align="left"><img src="/files/QJuMWI21M60ZKzo0mFAN" 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="/files/QJuMWI21M60ZKzo0mFAN" 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://0xn3va.gitbook.io/application-security-handbook/web-application/cryptography/universal-unique-identifier-uuid.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
