Created
April 11, 2016 18:05
-
-
Save zlepper/0167416896e22f0fbea9141b35e17113 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var fs = require("fs"); | |
var helpers = require("./helpers"); | |
var readline = require("readline"); | |
var path = require("path"); | |
var adjectives = []; | |
var nouns = []; | |
function loadData() { | |
"use strict"; | |
var adjectivesPath = path.join(__dirname, "txt", "adjectives.txt"); | |
var rl = readline.createInterface({ | |
input: fs.createReadStream(adjectivesPath) | |
}); | |
rl.on("line", function(line) { | |
adjectives.push(helpers.capitalizeFirtsLetter(line).trim()); | |
}); | |
var nounPath = path.join(__dirname, "txt", "nouns.txt"); | |
var rl2 = readline.createInterface({ | |
input: fs.createReadStream(nounPath) | |
}); | |
rl2.on("line", function(line) { | |
nouns.push(helpers.capitalizeFirtsLetter(line).trim()); | |
}); | |
} | |
loadData(); | |
function generateKey() { | |
"use strict"; | |
var adjIndex = Math.floor(Math.random() * adjectives.length); | |
var secondAdjIndex = Math.floor(Math.random() * adjectives.length); | |
while (adjIndex === secondAdjIndex) { | |
secondAdjIndex = Math.floor(Math.random() * adjectives.length); | |
} | |
var nounIndex = Math.floor(Math.random() * adjectives.length); | |
return adjectives[adjIndex] + adjectives[secondAdjIndex] + nouns[nounIndex]; | |
} | |
module.exports = generateKey; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment