🍋
Menu
Generator

UUIDv4

UUID Version 4

A randomly generated 128-bit universally unique identifier with a probability of collision near zero.

Chi tiết kỹ thuật

UUIDv4 relies on pseudo-random number generators (PRNGs). JavaScript's Math.random() uses an implementation-specific PRNG (typically xoshiro256**) that is fast but not cryptographically secure. For security-sensitive generation (tokens, passwords, keys), the Web Crypto API's crypto.getRandomValues() draws from the OS entropy pool (/dev/urandom on Linux, CryptGenRandom on Windows). True randomness requires hardware sources (thermal noise, radioactive decay) and is unnecessary for most generation tasks.

Ví dụ

```javascript
// UUIDv4: generation example
function generate(options = {}) {
  const { length = 10, type = 'alphanumeric' } = options;
  const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
  const values = crypto.getRandomValues(new Uint32Array(length));
  return Array.from(values, v => chars[v % chars.length]).join('');
}
```

Công cụ liên quan

Thuật ngữ liên quan