I've seen How to run a randomly selected function in JavaScript? which allows for running a JavaScript function randomly selected from at array with an equal chance each time (e.g. if there are two functions in total, there is a 50% chance that each function will be executed each time).
How to write a function to state the percentage chance of executing each function that is randomly available to be chosen from an array of functions? How do I do a weighted randomization??
function randomFrom(array) {
return array[Math.floor(Math.random() * array.length)];
}
var contentWrapper = function (target,type,articleId) {
// list type ads
if (type == 'list') {
function randomListData() {
var func = randomFrom([
function () {
fnNameA10(target, 'list');
},
function () {
fnNameB20(target, 'list', articleId);
}
]);
(func)();
}
randomListData();
// content type ads
} else if (type == 'content') {
function randomContentData() {
var func = randomFrom([
function () {
fnNameA10(target, 'content');
},
function () {
fnNameB20(target, 'content', articleId);
}
]);
(func)();
}
randomContentAd();
}
};
{function:percentage}as input?