JavaScript 生成随机用户名函数
function getRandomUserName() {
const adjectiveList = ['happy', 'silly', 'funny', 'clever', 'smart', 'kind', 'brave', 'curious', 'shy', 'creative'];
const nounList = ['panda', 'unicorn', 'robot', 'dinosaur', 'octopus', 'dragon', 'banana', 'apple', 'flower', 'star'];
const randomNumber1 = Math.floor(Math.random() * adjectiveList.length);
const randomNumber2 = Math.floor(Math.random() * nounList.length);
const username = ${adjectiveList[randomNumber1]}_${nounList[randomNumber2]}_${Math.floor(Math.random() * 100)};
return username;
}
// 示例用法: const username = getRandomUserName(); console.log(username); // 输出: 'curious_octopus_42'
原文地址: https://www.cveoy.top/t/topic/lRic 著作权归作者所有。请勿转载和采集!