diff --git a/src/random/random.js b/src/random/random.js index 4f66236..c9e359d 100644 --- a/src/random/random.js +++ b/src/random/random.js @@ -1,13 +1,10 @@ /** * Generate random number between interval * - * @param {Object} arg1 Props - * @param {number} arg1.min The minimum - * @param {number} arg1.max The maximum + * @param {Number} min Minimum value + * @param {Number} max Maximum value * - * @return {integer} + * @return {Integer} */ -const random = ({ min, max }) => - Math.floor(Math.random() * (max - min + 1) + min) - -export { random } +export const random = (min, max) => + Math.floor(min+ Math.random() * (max - min + 1)) diff --git a/src/random/random.test.js b/src/random/random.test.js index 1f33c18..ce37b82 100644 --- a/src/random/random.test.js +++ b/src/random/random.test.js @@ -1,25 +1,27 @@ import test from "tape" import chiSquaredTest from "chi-squared-test" -import { random, repeat, get, lt, hist } from ".." +import { random, repeat, get, lt, hist, pipe } from ".." test("random", t => { const [min, max, observationCount] = [5, 10, 600] - const observationsHist = - observationCount - |> repeat(() => random({ min, max })) - |> hist - |> Object.values + const observationsHist = pipe( + repeat(() => random(min, max)), + hist, + Object.values + )(observationCount) - const expectedHist = + const expectedHist = repeat(() => observationCount / observationsHist.length)( observationsHist.length - |> repeat(() => observationCount / observationsHist.length) + ) t.equals( - chiSquaredTest(observationsHist, expectedHist, 1) - |> get("chiSquared") - |> lt(11.07), + pipe(chiSquaredTest, get("chiSquared"), lt(11.07))( + observationsHist, + expectedHist, + 1 + ), true, `Generate ${observationCount} integers between ${min} and ${max}}` )