I am looking for a way to generate unique random numbers in JavaScript or Typescript.
Currently, I am using the following code:
var id = -((new Date()).getTime() & 0xffff);
This code produces numbers such as -13915
or -28806
...
While this method works most of the time, it encounters issues when executed in promises, potentially leading to duplicate IDs being generated.
Is there a reliable solution for generating unique random numbers under all circumstances?