21 lines
455 B
TypeScript
21 lines
455 B
TypeScript
const ALFNUM = "0123456789";
|
|
const SECRET_LENGTH = 8;
|
|
|
|
function randomInt(low: number, high: number) {
|
|
return Math.floor(Math.random() * (high - low + 1) + low);
|
|
}
|
|
|
|
export function randomId() {
|
|
const arr = new Int32Array(1);
|
|
crypto.getRandomValues(arr);
|
|
return Math.abs(arr[0]);
|
|
}
|
|
|
|
export function randomSecret() {
|
|
let out = "";
|
|
for (let i = 0; i < SECRET_LENGTH; i++) {
|
|
out += ALFNUM[randomInt(0, ALFNUM.length - 1)];
|
|
}
|
|
return out;
|
|
}
|