chore: change generateID() implementation

This commit is contained in:
Alexis Métaireau 2024-02-22 16:45:21 +01:00
parent bcd650e844
commit f9175e98b9

View file

@ -1,7 +1,7 @@
/**
* Generate a pseudo-unique identifier (4 chars long)
* Generate a pseudo-unique identifier (5 chars long, mixed-case alphanumeric)
*
* Using uppercase + lowercase + digits, here's the collision risk:
* Here's the collision risk:
* - for 6 chars, 1 in 100 000
* - for 5 chars, 5 in 100 000
* - for 4 chars, 500 in 100 000
@ -9,5 +9,5 @@
* @returns string
*/
export function generateId() {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
return btoa(Math.random().toString()).substring(10, 15)
}