From ed2d76b66c997b2253bb7f665c4195fcf88d3271 Mon Sep 17 00:00:00 2001 From: Fen Dweller Date: Wed, 28 Feb 2018 20:10:15 -0500 Subject: [PATCH] Spent way way way too long fixing the distribution function for larger numbers of items --- recursive-macro.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/recursive-macro.js b/recursive-macro.js index 2222d38..ed95682 100644 --- a/recursive-macro.js +++ b/recursive-macro.js @@ -244,12 +244,13 @@ function distribution(min, max, samples) { var limit = Math.min(100,samples); if (limit < samples) { - + let dist = 0; for (let i = 0; i < limit; i++) { - result += (i/10 + 1) * Math.floor(Math.random() * (max - min + 1) + min); + dist += Math.random(); } + dist /= 100; - result = Math.round((result / 595) * samples * (max - min) + min); + return Math.floor(dist * samples * (max - min + 1) + samples * min); } else { for (let i = 0; i < limit; i++) { result += Math.floor(Math.random() * (max - min + 1) + min);