目前我已经设置了一段代码用于基于50/50的A / B测试。但现在我想重建它到50/25/25设置。定义Math.random数字的最佳方法是什么?
// Launch A/B test surveys
if (/GB|CA|MY|EG|US|Global/i.test(_satellite.getVar("dlCountry")) && /EN/i.test(_satellite.getVar("dlLanguage"))) {
if (!_satellite.readCookie("s_UbVar")) {
// Make 50/50 split and set cookie
var UbVariant = RegExp(/true/).test(String(Math.random() < 0.5));
if (UbVariant) {
_satellite.setCookie("s_UbVar", "varA");
} else {
_satellite.setCookie("s_UbVar", "varB");
}
} else {
// Extend session cookie
_satellite.setCookie("s_UbVar", _satellite.readCookie("s_UbVar"));
if (_satellite.readCookie("s_UbVar") === "varA") {
usabilla_live("trigger", "survey-A");
} else if (_satellite.readCookie("s_UbVar") === "varB") {
usabilla_live("trigger", "survey-B");
} else {
// Cookies contains an empty/unknown value
_satellite.removeCookie("s_UbVar");
}
}
} else {
// Remove existing cookies
_satellite.removeCookie("s_UbVar");
}
答案 0 :(得分:0)
只需设置您的积分
即可var variant = Math.random();
if (variant < 0.5) {
// A Code
}
else if (variant > 0.75) {
// B Code
}
else {
// C Code
}
答案 1 :(得分:0)
或者没有if:
const tt = Math.random()
switch (true) {
case (tt<.5):
// do 1
break
case (tt<.75):
// do 2
break
default:
// do 3
}