function random(ary){
    return ary[Math.floor(Math.random()*ary.length)];
}

function randomChance(ary,chance){
  var ranint = Math.random() * (100 - 0) + 0;
  if (ranint <= chance){
    return ary[Math.floor(Math.random()*ary.length)];
  } else {
    return '';
  }
}

var tippedArrows = [
'cyclic:stun', 
'minecraft:weakness', 
'atmospheric:worsening',
'immersiveengineering:sticky',
'occultism:third_eye',
'apotheosis:sundering',
'cofh_core:wrenched'
];

var specialArrows = ['minecraft:spectral_arrow', 'archers_paradox:frost_arrow', 'archers_paradox:ender_arrow', 'archers_paradox:phantasmal_arrow', 'archers_paradox:quartz_arrow', 'archers_paradox:shulker_arrow', 'archers_paradox:slime_arrow', 'apotheosis:obsidian_arrow', 'archers_paradox:blaze_arrow'];



onEvent('entity.spawned', event => {

    if(event.entity.type == 'minecraft:skeleton') {
        
        event.server.scheduleInTicks(2, cb => {
        
        var UUID = event.entity.getFullNBT().UUID;
		
	var arrowFormula = [('id:"minecraft:tipped_arrow",tag:{Potion:"'+random(tippedArrows)+'"},Count:1'), ('id:"'+random(specialArrows)+'",Count:1')]
	  
	  event.server.runCommandSilent('data merge entity @e[nbt={UUID:'+UUID+'},limit=1] {HandItems:[{id:"minecraft:bow",Count:1},{'+randomChance(arrowFormula,10.0)+'}]}');
    });
}
})
