TypeScript
HTML
<div id="app"></div>
CSS
body {
background: #20262E;
padding: 20px;
font-family: Helvetica;
}
#app {
background: #fff;
border-radius: 4px;
padding: 20px;
transition: all 0.2s;
text-align: center;
}
TypeScript
const x = [0,1,2,3,4,5,6,7,8,9];
const p = [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
const l = 100;
const y = [];
for (const i = 0; i < x.length; i++) {
y = y.concat(new Array(l*p[i]).fill(x[i]));
}
function getRandomInt(max) {
return Math.floor(Math.random() * max);
}
// result
console.log(y);
console.log(y[getRandomInt(y.length - 1)])