News for hackers. Stuff that matters.
Re:The Wi Flag -Turns out some players in Asheron's Call wer... by ryani on Friday February 10, 2023 @01:02PM (#34743228)
Here's the standard algorithm for this problem

    function weightedRandom(weight, outcomes){
      var total = sum( weight );
      var roll = Math.random()*total; // value in the range [0,total)
      var seen = 0;
      for(let i=0; i<weight.length; i++) {
        seen += weight[i];
        if(roll<seen)
          return outcomes[i];
      }
    }

There are no comments on this comment yet.