JSFiddle - React, Tailwind, and code Playground
HTML
<div id="out">
foo
</div>
JavaScript
var choices = [1, 2, 3, 4];
function chose(samples) {
var sampled = [];
for(var i = 0; i < samples; i++) {
var index = Math.floor(Math.random() * choices.length);
sampled[index] = (sampled[index] || 0) + 1;
}
return sampled;
}
window.out.innerHTML = chose(1000).join(", ");