You are viewing a single comment's thread from:

RE: Seeking help for an easy to extend random function

in #programming8 years ago

a better solution:


var runs = 10000;
var total = array();
for(var i = 0; i < options.length; i++){
  for(var j = 0; j < options[i]['chance']; j++){
    total.push(options[i]['Key']);
  }
}
for(var i = 0; i < runs; i++){
  console.log(total[Math.floor(Math.random()*total.length+1)]);
}