Mrs. Tini moves the cooperative’s member book onto a computer: make thousands of member numbers with Math.random, Date.now, getRandomValues or…
Unique ids are everywhere: React keys, primary keys, upload file names, idempotency keys. A number cut short collides much sooner than you would guess, Date.now() collides within one millisecond, and Math.random is not safe randomness for tokens.
Unique is about space: 122 random bits from crypto.randomUUID
Math.random() collide Cut short, its space is small and duplicates come much sooner than you think; Math.random can also be predicted. Use crypto.randomUUID().crypto.randomUUID is missing in the browser It only exists in a secure context: https or localhost. Over plain http, build one from crypto.getRandomValues(new Uint8Array(16)) (always there) or move to https.randomUUID Pick randomUUID, then Print one card twice. Find the 4 and the variant letter that never change.Date.now() A thousand cards in a millisecond or two: almost all of them duplicates.randomUUID for 100,000 cards Zero duplicates. 122 random bits: far more room than any pile of cards.