diff --git a/src/interpolation/helpers.js b/src/interpolation/helpers.js index 92c6614..2bf620c 100644 --- a/src/interpolation/helpers.js +++ b/src/interpolation/helpers.js @@ -10,12 +10,19 @@ */ export function takeSampleFrom(sourceList, amount) { let randElements = [], - max = sourceList.length; + max = sourceList.length, + swap = false; if (amount >= max) { return {sample: sourceList, remainder: {}}; } + // If picking more than half of the entire set, random to pick the remainder instead + if (amount > Math.ceil(max/2)){ + amount = max - amount; + swap = true; + } + for (let i = 0; i < amount; ++i) { let rand = sourceList[Math.floor((Math.random() * max))]; // Re-random until suitable value is found. @@ -28,10 +35,18 @@ export function takeSampleFrom(sourceList, amount) { return !randElements.includes(obj); }); - return { - sample: randElements, - remainder: remainder - }; + if(swap) { + return { + sample: remainder, + remainder: randElements + }; + } + else { + return { + sample: randElements, + remainder: remainder + }; + } } /**