randomIdGenerator.ts14 lines · main
| 1 | // export default function () { |
| 2 | // const randomNumber = Math.floor(Math.random() * 26) + Date.now() |
| 3 | // return randomNumber.toString() |
| 4 | // } |
| 5 | |
| 6 | export function generateUID() { |
| 7 | // I generate the UID from two parts here |
| 8 | // to ensure the random number provide enough bits. |
| 9 | var firstPart = (Math.random() * 46656) | 0 |
| 10 | var secondPart = (Math.random() * 46656) | 0 |
| 11 | const newFirstPart = ('00000' + firstPart.toString(36)).slice(-3) |
| 12 | const newSecondPart = ('00000' + secondPart.toString(36)).slice(-3) |
| 13 | return newFirstPart + newSecondPart |
| 14 | } |