filmov
tv
Javascript Mistakes: UUID generation with Math.random()?

Показать описание
Using a pseudo-random number generator (PRNG) for generating UUID v4 is a bad idea because PRNGs have a limited period of randomness, which means that over time, the same sequence of values will be generated. This can lead to collisions and undermine the uniqueness of the UUIDs. Additionally, PRNGs may be predictable or susceptible to cryptographic attacks, which can compromise the security of the UUIDs. To ensure the uniqueness and security of UUIDs, a true random number generator should be used instead of a PRNG.
The standard Crypto API has methods to generate random UUIDs and cryptographically strong random values:
Be aware that libraries published on NPM can have this kind of mistakes too:
#shorts #javascript #typescript #coding #programming #codingtips