function generateRandomString() { let specialChars = "`~!@#$%^&*-+=_|{}[]:;'<>,.?/"; let lowercaseLetters = 'abcdefghijklmnopqrstuvwxyz'; let uppercaseLetters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'; let numbers = '0123456789'; let randomString = specialChars.charAt(Math.floor(Math.random() * specialChars.length)) + lowercaseLetters.charAt(Math.floor(Math.random() * lowercaseLetters.length)) + uppercaseLetters.charAt(Math.floor(Math.random() * uppercaseLetters.length)) + numbers.charAt(Math.floor(Math.random() * numbers.length)); let remainingChars = specialChars + lowercaseLetters + uppercaseLetters + numbers; for (let i = 4; i < 30; i++) { randomString += remainingChars.charAt(Math.floor(Math.random() * remainingChars.length)); } return randomString.split('').sort(() => 0.5 - Math.random()).join(''); } let res = generateRandomString(); console.log(res);标签:02,30,20,charAt,floor,random,length,let,Math From: https://www.cnblogs.com/iuniko/p/18022933