distribution

by evgkch

JavaScript

const random = () => Math.round(Math.random());

const word = length => n => {
	const arr = new Uint8Array(length).fill(0);
  
  for (let i = 0; i < n; i++) {
  	arr[i] = 1;
  }
  
  return arr.sort((a, b) => Math.random() > 0.5 ? 1 : -1); 
}

const mult = a => b => a.map((x, i) => (x + b[i]) % 2);

const res = {};
let count = 0;

function main(m) {
	for (let i = 0; i < m; i++) {
  	const n = mult(word(64)(13))(word(64)(30)).reduce((a, b) => a + b);
    if (typeof(res[n]) === 'undefined') {
    	res[n] = 0;
    }
    res[n]++;
    count++;
  }
  for (let key in res) {
  	console.log(key, res[key] / count)
  }
}

main(10000)