Files
Picsur/shared/src/util/random.ts
2022-03-27 22:48:10 +02:00

14 lines
402 B
TypeScript

import crypto from 'crypto';
const randomCharacters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
export function generateRandomString(length: number): string {
let out = '';
for (let i = 0; i < length; i++) {
// Yes this is done synchronously, but it's not a big deal
out += randomCharacters[crypto.randomInt(0, randomCharacters.length - 1)];
}
return out;
}