var arr = [2, 3, 5, 5];
console.log(arr);
var sum = 0;
for (let i = 0; i < arr.length; i++) {
sum += arr[i];
}
for (let i = 0; i < arr.length; i++) {
console.log(i + ") " + (arr[i]/sum));
}
console.log(sum);
var r = Math.random();
console.log("random number: " + r);
var totalP = 0;
for (let i = 0; i < arr.length; i++) {
var p = arr[i]/sum;
console.log("p => " + p);
totalP += p;
console.log("\ttotalP => " + totalP);
if(r < totalP) {
console.log("\t\tBINGO!!!! => item " + i + " with mark: " + arr[i]);
break;
}
}