const items = [ { name: 'Apple', dropChance: 0.7 }, { name: 'Knife', dropChance: 0.25 }, { name: 'Spoon', dropChance: 0.25 }, { name: 'Ice Cream', dropChance: 0.1 } ]; const lerp = (min, max, value) => ((1 - value) * min + value * max); const drop = items => { const total = items.reduce((accumulator, item) => (accumulator += item.dropChance), 0); const chance = lerp(0, total, Math.random()); let current = 0; for (const item of items) { if (current <= chance && chance < current + item.dropChance) { return item; } current += item.dropChance; } };