function percentageRandom (list, roundup=false) {
  var r = Math.random() * 100;  // random between 0 and 100
  var factor = 1;

  // calculate factor to 100%
  if (roundup) {
    factor = 0;
    for (let i=0; i < list.length; i++) 
      factor += list[i];
    factor = 100 / factor;
  }
  // find random index
  for (let i=0; i < list.length; i++) 
    if ((r -=  (list[i] * factor)) < 0)  
      return i;
  // rounding diff will result first item
  return 0;  
}
// return value is a random array index, weight by percentage items 
return value is a random array index, weight by percentage items
return value is a random array index weight by percentage items
function percentageRandom (list, roundup=false) {
  var r = Math.random() * 100;  
  var factor = 1;
  if (roundup) {
    factor = 0;
    for (let i=0; i < list.length; i++) 
      factor += list[i];
    factor = 100 / factor;
  }
  for (let i=0; i < list.length; i++) 
    if ((r -=  (list[i] * factor)) < 0)  
      return i;
  return 0;  
}
function percentageRandom ( list , roundup = false ) { var r = Math . random ( ) * 100 ; var factor = 1 ; if ( roundup ) { factor = 0 ; for ( let i = 0 ; i < list . length ; i ++ ) factor += list [ i ] ; factor = 100 / factor ; } for ( let i = 0 ; i < list . length ; i ++ ) if ( ( r -= ( list [ i ] * factor ) ) < 0 ) return i ; return 0 ; }
return value is a random array index, weight by percentage items
return value is a random array index weight by percentage items
// random between 0 and 100 // calculate factor to 100% // find random index // rounding diff will result first item