15 Zeilen
278 B
TypeScript
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
|
|
}
|
|
}
|
|
}
|