Fork Copy let users = [ { name: "A", w: 1 }, { name: "B", w: 2 }, { name: "C", w: 1 }, { name: "D", w: 5}, { name: "E", w: 1 }, { name: "F", w: 2 } ]; function randomByWeight(list, take, getWeight) { if (!getWeight) { getWeight = v => v } let totalWeight = list.reduce((res, cur) => res + getWeight(cur), 0); let picked = {}; for (let i = 1; i <= take; i++) { let randomWeight = Math.random() * totalWeight; for (let j = 0; j < list.length; j++) { let item = list[j]; if (picked[j]) { continue; } let itemWeight = getWeight(item); if (itemWeight > randomWeight) { picked[j] = item; totalWeight -= itemWeight; break; } randomWeight -= itemWeight; } } return Object.values(picked); } console.log(randomByWeight([1, 2, 3, 4], 2));