This repository has been archived on 2025-03-19. You can view files and clone it, but cannot push or open issues or pull requests.
feishin/src/renderer/utils/random-string.ts
2022-12-19 17:44:40 -08:00

9 lines
351 B
TypeScript

export const randomString = (length?: number) => {
const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
let string = '';
for (let i = 0; i < (length || 12); i += 1) {
const randomPoz = Math.floor(Math.random() * charSet.length);
string += charSet.substring(randomPoz, randomPoz + 1);
}
return string;
};