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)]);
}

Coin Marketplace

STEEM 0.05
TRX 0.29
JST 0.043
BTC 68343.45
ETH 1978.45
USDT 1.00
SBD 0.38