Last active
October 10, 2018 00:50
-
-
Save terrierscript/c79c02be84797586774b4ac1a2246523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const readline = require("readline") | |
const seeds = [ | |
// 使いたい漢字を列挙する | |
] | |
const firstName = "" // 名字 | |
const getRandomInt = (len) => { | |
return Math.ceil(Math.random() * len) | |
} | |
const pick = (arr) => { | |
return arr[getRandomInt(arr.length)] | |
} | |
// 2文字:1文字:3文字 = 2:1:1で出したい | |
const randomLength = () => { | |
const num = getRandomInt(4) | |
switch (num) { | |
case 1: | |
return 1 | |
case 3: | |
return 3 | |
default: | |
return 2 | |
} | |
} | |
const generateName = (seeds) => { | |
return Array.from({ length: randomLength() }) | |
.map((_) => { | |
return pick(seeds) | |
}) | |
.join("") | |
} | |
const rl = readline.createInterface(process.stdin, process.stdout) | |
const main = () => { | |
outputRandomName() | |
rl.on("line", function(line) { | |
outputRandomName() | |
}) | |
} | |
const outputRandomName = () => { | |
for (let i = 0; i < 5; i++) { | |
console.log(firstName, generateName(seeds)) | |
} | |
} | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment