Skip to content

Instantly share code, notes, and snippets.

@zlepper
Created April 11, 2016 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zlepper/0167416896e22f0fbea9141b35e17113 to your computer and use it in GitHub Desktop.
Save zlepper/0167416896e22f0fbea9141b35e17113 to your computer and use it in GitHub Desktop.
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