如何在打字稿中创建由字母[a-z0-9]组成的随机字符串?它应该始终由32位数字组成。并且也不应有多余的字符串。
答案 0 :(得分:1)
尝试一下:
makeString(): string {
let outString: string = '';
let inOptions: string = 'abcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 32; i++) {
outString += inOptions.charAt(Math.floor(Math.random() * inOptions.length));
}
return outString;
}
result: string = this.makeString();