Website/src/util/util.ts
2023-09-24 16:33:14 +02:00

15 Zeilen
278 B
TypeScript

import { randomBytes } from 'crypto'
const usedIds = new Set<string>()
export const getRandomId = () => {
while (true) {
const id = randomBytes(4).toString('hex')
if (!usedIds.has(id)) {
usedIds.add(id)
return id
}
}
}