Skip to content

Commit d2fca54

Browse files
committed
chore: change rand to crng
1 parent 9e0580a commit d2fca54

File tree

1 file changed

+4
-1
lines changed
  • infrastructure/w3id/src/utils

1 file changed

+4
-1
lines changed

infrastructure/w3id/src/utils/rand.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ export function generateRandomAlphaNum(length = 16): string {
1010
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
1111
let result = "";
1212
const charsLength = chars.length;
13+
const randomValues = new Uint32Array(length);
14+
15+
crypto.getRandomValues(randomValues);
1316

1417
for (let i = 0; i < length; i++) {
15-
result += chars.charAt(Math.floor(Math.random() * charsLength));
18+
result += chars.charAt(randomValues[i] % charsLength);
1619
}
1720

1821
return result;

0 commit comments

Comments
 (0)