I'm trying to make a program that will select a random element from an array, and want it to be that different elements have a different probability to be chosen. What is the best way to do this?
var char = ["a","b","c"];
var weights = ["0.2","0.3","0.5";
function randomSelection(){
var randomchoice = ??;
return randomchoice
}
Thanks!
Aucun commentaire:
Enregistrer un commentaire