function pickFromArray(a) {
    let x = Math.random() * vtotal(a),
        i = -1;
    while(x > 0) {
      x -= a[++i];
    }
    return i;
  }
// Picks random index from weighted probability array
Picks random index from weighted probability array
Picks random index from weighted probability array
function pickFromArray(a) {
    let x = Math.random() * vtotal(a),
        i = -1;
    while(x > 0) {
      x -= a[++i];
    }
    return i;
  }
function pickFromArray ( a ) { let x = Math . random ( ) * vtotal ( a ) , i = - 1 ; while ( x > 0 ) { x -= a [ ++ i ] ; } return i ; }
Picks random index from weighted probability array
Picks random index from weighted probability array