const weights = [
{ number: 1, probability: 0.015, label: '7%', value: 3 },
{ number: 2, probability: 0.16, label: '5%', value: 2 },
{ number: 3, probability: 0.05, label: '10%', value: 1 },
... // добавьте нужное количество секторов
];
function getRandomWeightedNumber() {
let cumulative = 0;
const distribution = weights.map(item => {
cumulative += item.probability;
return { number: item.number, cumulative: cumulative };
});
const random = Math.random();
for (const item of distribution) {
if (random <= item.cumulative) return item.number;
}
}
const currentPoint = getRandomWeightedNumber();
const deg = (currentPoint * (360 / points)) + (360 * numSwing) + degShift;
ConveadClient.Helpers.animate_prop({
el: elW,
prop: 'transform',
cssFunction: 'rotate',
dimension: 'deg',
start: 0,
end: deg,
duration: time,
delta: 'easeOutQuart',
complete: function() {
let result = weights.find(item => item.number === currentPoint);
const emailVariant = 'roulette_win_' + result.value;
ConveadClient.WidgetTracker.submit_value = emailVariant;
elBtnSubmit.click();
}
});