Comparing version 1.8.6 to 1.9.0
@@ -43,2 +43,3 @@ #!/usr/bin/env node | ||
console.log(' rdist <n> [mean] [stdev] : Generate `n` normally-distributed random floats'); | ||
console.log(' rseq <min> <max> : Randomize a sequence of integers from `min` to `max`'); | ||
process.exit(1); | ||
@@ -135,2 +136,6 @@ } | ||
} | ||
case ('rseq'): { | ||
console.log(_1.SMath.rseq(nums[0], nums[1])); | ||
break; | ||
} | ||
case (''): { | ||
@@ -137,0 +142,0 @@ console.error('Missing argument. Use with "help" for a list of commands.'); |
@@ -399,2 +399,23 @@ "use strict"; | ||
/** | ||
* Randomize a sequence of integers from `min` to `max`. | ||
* @param min The minimum integer in the randomized sequence | ||
* @param max The maximum integer in the randomized sequence | ||
* @returns A randomized sequence of integers from `min` to `max` | ||
* @example | ||
* ```js | ||
* const sequence = SMath.rseq(-2, 2); // [ 2, 0, 1, -2, -1 ] | ||
* ``` | ||
*/ | ||
function rseq(min, max) { | ||
min |= 0; | ||
max |= 0; | ||
max++; | ||
var rawData = []; | ||
for (var i = min; i < max; i++) { | ||
rawData.push({ index: runif(-1, 1), value: i }); | ||
} | ||
return rawData.sort(function (a, b) { return a.index - b.index; }).map(function (a) { return a.value; }); | ||
} | ||
SMath.rseq = rseq; | ||
/** | ||
* Take the limit of a function. A return value of `NaN` indicates | ||
@@ -401,0 +422,0 @@ * that no limit exists either due to a discontinuity or imaginary value. |
{ | ||
"name": "smath", | ||
"version": "1.8.6", | ||
"version": "1.9.0", | ||
"description": "Small math function library", | ||
@@ -58,5 +58,5 @@ "homepage": "https://npm.nicfv.com/", | ||
"devDependencies": { | ||
"@types/node": "20.12.7", | ||
"@types/node": "22.10.1", | ||
"t6": "1.1.4" | ||
} | ||
} |
@@ -265,2 +265,13 @@ /** | ||
/** | ||
* Randomize a sequence of integers from `min` to `max`. | ||
* @param min The minimum integer in the randomized sequence | ||
* @param max The maximum integer in the randomized sequence | ||
* @returns A randomized sequence of integers from `min` to `max` | ||
* @example | ||
* ```js | ||
* const sequence = SMath.rseq(-2, 2); // [ 2, 0, 1, -2, -1 ] | ||
* ``` | ||
*/ | ||
function rseq(min: number, max: number): Array<number>; | ||
/** | ||
* Take the limit of a function. A return value of `NaN` indicates | ||
@@ -267,0 +278,0 @@ * that no limit exists either due to a discontinuity or imaginary value. |
34896
990