(length = 16)
| 23 | * @returns Lowercase hex string of the given length |
| 24 | */ |
| 25 | export function generateRandomHex(length = 16): string { |
| 26 | const bytes = generateRandomBytes(Math.ceil(length / 2)) |
| 27 | return Array.from(bytes) |
| 28 | .map((b) => b.toString(16).padStart(2, '0')) |
| 29 | .join('') |
| 30 | .slice(0, length) |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Generates a cryptographically secure random alphanumeric string. |
no test coverage detected