Memo password

by Paul Panov

HTML

<div id="a">:: </div>

CSS

html, body {
    background: #1C1C1C;
    margin:0;
}
#a {
    font-family: Ubuntu Momo, Monaco, Consolas, monospace;
    color: white;
}

JavaScript

const rand = (min, max) => 
    min + Math.floor(Math.random() * ((max-min) + 1));
const sum = (arr) => arr.reduce((a,b)=>a+b,0);
const one = () => 1;
const mappings = [
	["qwrtpsdfghjklzxcvnm", 10, one],
	["eyuioa", 10, (...prev) => sum(prev.map((x,i) => "eyuioa".includes(x) * 1/(prev.length - i)))],
	["0123456789", 0, one]
];

for (let i = 0; i < 500; ++i) {
	let word = '', length = rand(4, 7);
	for (let j = 0; j < length; ++j) {
		const currentMappings = mappings.map(([charset, apr, fx]) => {
		console.log(fx(word.split('')));
			return [charset, apr * fx(word.split(''))];
		});
		const currentSum = sum(currentMappings.map(([charset,prb]) => prb));
		const sample = rand(0, currentSum);
		let min = 0;
		for (let k = 0; k < currentMappings.length; ++k) {
			min += currentMappings[k][1];
			if (min > sample) {
				const charset = currentMappings[k][0];
				word += charset[rand(0, charset.length - 1)];
				break;
			}
		}
	}

	document.getElementById('a').innerText = a.innerText + ' ' + word;
};