code: function(lst, probs) {
      var p = randf(0, 1.0);
      var cumprob = 0.0;
      for(var k=0,n=lst.length;k<n;k++) {
        cumprob += probs[k];
        if(p < cumprob) { return lst[k]; }
      }
    }
docs: sample from list lst according to probabilities in list probs the two lists are of same size, and probs adds up to 1