bias-random 1.0.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -21
- package/README.md +14 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +24 -14
- package/dist/index.d.ts +24 -14
- package/dist/index.js +1 -1
- package/package.json +34 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# bias-random
|
|
2
2
|
|
|
3
|
+
## 1.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 5972a1d: Added an export for the BiasedRandomOptions type. Improved documentation and added stricter type and value checking for inputs.
|
|
8
|
+
|
|
9
|
+
## 1.1.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- d2d99f0: Added package.json and explicit CDN import options. Explicitly stated the package has no side effects. Improved
|
|
14
|
+
documentation and fixed the yarn install command in README.
|
|
15
|
+
|
|
3
16
|
## 1.0.3
|
|
4
17
|
|
|
5
18
|
### Patch Changes
|
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024 Reid Moffat
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Reid Moffat
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -3,23 +3,22 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/bias-random)
|
|
4
4
|
[](https://www.npmjs.com/package/bias-random)
|
|
5
5
|
[](https://www.npmjs.com/package/bias-random)
|
|
6
|
+
[](https://buymeacoffee.com/reidmoffat)
|
|
6
7
|
|
|
7
8
|
Generates biased random numbers with a customizable bias level, direction, and range
|
|
8
9
|
|
|
9
10
|
## 📦 Installation
|
|
10
|
-
|
|
11
11
|
```bash
|
|
12
12
|
npm i bias-random
|
|
13
13
|
|
|
14
14
|
# or
|
|
15
|
-
yarn add
|
|
15
|
+
yarn add bias-random
|
|
16
16
|
|
|
17
17
|
# or
|
|
18
18
|
pnpm i bias-random
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
## 🚀 Usage
|
|
22
|
-
|
|
23
22
|
```ts
|
|
24
23
|
import biasedRandom from "bias-random";
|
|
25
24
|
|
|
@@ -33,3 +32,15 @@ const defaultResult = biasedRandom();
|
|
|
33
32
|
// Cutomize the parmeters (all parameters are optional, defaulting to the values above)
|
|
34
33
|
const customResult = biasedRandom({ upperBias: true, biasLevel: 4, min: 10, max: 1000 });
|
|
35
34
|
```
|
|
35
|
+
|
|
36
|
+
## 📃 Changelog
|
|
37
|
+
|
|
38
|
+
To view the release notes for each version, view the changelog:
|
|
39
|
+
|
|
40
|
+
* On GitHub: [Link](https://github.com/reid-moffat/bias-random/blob/main/CHANGELOG.md)
|
|
41
|
+
* On npm: [package page](https://www.npmjs.com/package/bias-random?activeTab=code) -> CHANGELOG.md
|
|
42
|
+
* In the repository: CHANGELOG.md
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
☕ [Buy me a coffee](https://buymeacoffee.com/reidmoffat) if this package helped you!
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var n=Object.defineProperty;var
|
|
1
|
+
"use strict";var n=Object.defineProperty;var m=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var p=Object.prototype.hasOwnProperty;var s=(t,e)=>{for(var r in e)n(t,r,{get:e[r],enumerable:!0})},f=(t,e,r,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of u(e))!p.call(t,a)&&a!==r&&n(t,a,{get:()=>e[a],enumerable:!(o=m(e,a))||o.enumerable});return t};var d=t=>f(n({},"__esModule",{value:!0}),t);var w={};s(w,{default:()=>y});module.exports=d(w);var b=({upperBias:t=!1,biasLevel:e=2,min:r=0,max:o=1}={})=>{if(typeof e!="number")throw new TypeError(`Parameter 'biasLevel' must be a number, received ${e} (type: ${typeof e})`);if(!Number.isFinite(e))throw new TypeError(`Parameter biasLevel must be a finite number (value: ${e})`);if(e<1)throw new TypeError(`Parameter 'biasLevel' must be >= 1 (value: ${e}); use upperBias to swap bias direction`);if(typeof r!="number"||typeof o!="number")throw new TypeError(`Parameters 'min' and 'max' must be numbers. Received min: ${r} (type: ${typeof r}), max: ${o} (type: ${typeof o})`);if(!Number.isFinite(r)||!Number.isFinite(o))throw new TypeError(`Parameters 'min' and 'max' must be finite numbers. Min value: ${r} Max value: ${o}`);if(r>=o)throw new TypeError(`Parameter 'min' must be less than 'max' (you can flip them for a valid result). Min value: ${r} Max value: ${o}`);if(typeof t!="boolean")throw new TypeError(`Parameter 'upperBias' must be a boolean, value '${t}' (type: ${typeof t}) is invalid`);let a=Math.pow(Math.random(),e);return t&&(a=1-a),r+a*(o-r)},i=b;var y=i;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Options object to customize the biased random generated result
|
|
3
|
+
*
|
|
4
|
+
* Every field, as well as providing this object itself, is optional
|
|
5
|
+
*/
|
|
6
|
+
type BiasedRandomOptions = {
|
|
7
|
+
/** Bias towards the maximum number if true, otherwise biased towards the minimum number (default false) */
|
|
2
8
|
upperBias?: boolean;
|
|
9
|
+
/** Bias factor (power to raise the random result by). Must be 1 (no bias) or greater, default is 2 */
|
|
3
10
|
biasLevel?: number;
|
|
11
|
+
/** Minimum value (default 0) */
|
|
4
12
|
min?: number;
|
|
13
|
+
/** Maximum value (default 1) */
|
|
5
14
|
max?: number;
|
|
6
|
-
}
|
|
15
|
+
};
|
|
16
|
+
|
|
7
17
|
/**
|
|
8
|
-
* Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound
|
|
18
|
+
* Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound
|
|
9
19
|
*
|
|
10
|
-
* @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation
|
|
11
|
-
* @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`)
|
|
12
|
-
* @param {number} [options.biasLevel=2] - Determines the strength of the bias. Must be 1 or greater, where `1` means no bias and higher values increase the bias
|
|
13
|
-
* @param {number} [options.min=0] - The minimum value for the random number range
|
|
14
|
-
* @param {number} [options.max=1] - The maximum value for the random number range
|
|
20
|
+
* @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation
|
|
21
|
+
* @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`)
|
|
22
|
+
* @param {number} [options.biasLevel=2] - Determines the strength of the bias (power to raise the random result by). Must be 1 or greater, where `1` means no bias and higher values increase the bias
|
|
23
|
+
* @param {number} [options.min=0] - The minimum value for the random number range
|
|
24
|
+
* @param {number} [options.max=1] - The maximum value for the random number range
|
|
15
25
|
*
|
|
16
|
-
* @returns {number} A random number between `min` and `max`, optionally biased based on the provided options
|
|
26
|
+
* @returns {number} A random number between `min` and `max`, optionally biased based on the provided options
|
|
17
27
|
*
|
|
18
|
-
* @throws {TypeError} If `biasLevel` is not a number or is less than 1
|
|
19
|
-
* @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number
|
|
20
|
-
* @throws {TypeError} If `upperBias` is not a boolean
|
|
28
|
+
* @throws {TypeError} If `biasLevel` is not a number or is less than 1
|
|
29
|
+
* @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number
|
|
30
|
+
* @throws {TypeError} If `upperBias` is not a boolean
|
|
21
31
|
*/
|
|
22
|
-
declare const biasedRandom: (
|
|
32
|
+
declare const biasedRandom: ((opts?: BiasedRandomOptions) => number);
|
|
23
33
|
|
|
24
|
-
export { biasedRandom as default };
|
|
34
|
+
export { type BiasedRandomOptions, biasedRandom as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,24 +1,34 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Options object to customize the biased random generated result
|
|
3
|
+
*
|
|
4
|
+
* Every field, as well as providing this object itself, is optional
|
|
5
|
+
*/
|
|
6
|
+
type BiasedRandomOptions = {
|
|
7
|
+
/** Bias towards the maximum number if true, otherwise biased towards the minimum number (default false) */
|
|
2
8
|
upperBias?: boolean;
|
|
9
|
+
/** Bias factor (power to raise the random result by). Must be 1 (no bias) or greater, default is 2 */
|
|
3
10
|
biasLevel?: number;
|
|
11
|
+
/** Minimum value (default 0) */
|
|
4
12
|
min?: number;
|
|
13
|
+
/** Maximum value (default 1) */
|
|
5
14
|
max?: number;
|
|
6
|
-
}
|
|
15
|
+
};
|
|
16
|
+
|
|
7
17
|
/**
|
|
8
|
-
* Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound
|
|
18
|
+
* Generates a random number between `min` and `max`, with an optional bias towards the lower or upper bound
|
|
9
19
|
*
|
|
10
|
-
* @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation
|
|
11
|
-
* @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`)
|
|
12
|
-
* @param {number} [options.biasLevel=2] - Determines the strength of the bias. Must be 1 or greater, where `1` means no bias and higher values increase the bias
|
|
13
|
-
* @param {number} [options.min=0] - The minimum value for the random number range
|
|
14
|
-
* @param {number} [options.max=1] - The maximum value for the random number range
|
|
20
|
+
* @param {Object} [options] - Optional configuration object to adjust the behavior of the random number generation
|
|
21
|
+
* @param {boolean} [options.upperBias=false] - If true, biases the result towards the higher bound (`max`), otherwise biases towards the lower bound (`min`)
|
|
22
|
+
* @param {number} [options.biasLevel=2] - Determines the strength of the bias (power to raise the random result by). Must be 1 or greater, where `1` means no bias and higher values increase the bias
|
|
23
|
+
* @param {number} [options.min=0] - The minimum value for the random number range
|
|
24
|
+
* @param {number} [options.max=1] - The maximum value for the random number range
|
|
15
25
|
*
|
|
16
|
-
* @returns {number} A random number between `min` and `max`, optionally biased based on the provided options
|
|
26
|
+
* @returns {number} A random number between `min` and `max`, optionally biased based on the provided options
|
|
17
27
|
*
|
|
18
|
-
* @throws {TypeError} If `biasLevel` is not a number or is less than 1
|
|
19
|
-
* @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number
|
|
20
|
-
* @throws {TypeError} If `upperBias` is not a boolean
|
|
28
|
+
* @throws {TypeError} If `biasLevel` is not a number or is less than 1
|
|
29
|
+
* @throws {TypeError} If `min` is not less than `max`, or if either `min` or `max` is not a number
|
|
30
|
+
* @throws {TypeError} If `upperBias` is not a boolean
|
|
21
31
|
*/
|
|
22
|
-
declare const biasedRandom: (
|
|
32
|
+
declare const biasedRandom: ((opts?: BiasedRandomOptions) => number);
|
|
23
33
|
|
|
24
|
-
export { biasedRandom as default };
|
|
34
|
+
export { type BiasedRandomOptions, biasedRandom as default };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var i=({upperBias:o=!1,biasLevel:r=2,min:e=0,max:t=1}={})=>{if(typeof r!="number")throw new TypeError(`Parameter 'biasLevel' must be a number, received ${r} (type: ${typeof r})`);if(!Number.isFinite(r))throw new TypeError(`Parameter biasLevel must be a finite number (value: ${r})`);if(r<1)throw new TypeError(`Parameter 'biasLevel' must be >= 1 (value: ${r}); use upperBias to swap bias direction`);if(typeof e!="number"||typeof t!="number")throw new TypeError(`Parameters 'min' and 'max' must be numbers. Received min: ${e} (type: ${typeof e}), max: ${t} (type: ${typeof t})`);if(!Number.isFinite(e)||!Number.isFinite(t))throw new TypeError(`Parameters 'min' and 'max' must be finite numbers. Min value: ${e} Max value: ${t}`);if(e>=t)throw new TypeError(`Parameter 'min' must be less than 'max' (you can flip them for a valid result). Min value: ${e} Max value: ${t}`);if(typeof o!="boolean")throw new TypeError(`Parameter 'upperBias' must be a boolean, value '${o}' (type: ${typeof o}) is invalid`);let a=Math.pow(Math.random(),r);return o&&(a=1-a),e+a*(t-e)},n=i;var p=n;export{p as default};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bias-random",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Generates biased random numbers with a customizable bias level, direction, and range",
|
|
5
5
|
"author": "Reid Moffat <reid.moffat9@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"types": "./dist/index.d.cts",
|
|
40
40
|
"default": "./dist/index.cjs"
|
|
41
41
|
}
|
|
42
|
-
}
|
|
42
|
+
},
|
|
43
|
+
"./package.json": "./package.json"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"lint": "tsc",
|
|
@@ -56,25 +57,42 @@
|
|
|
56
57
|
"README.md",
|
|
57
58
|
"package.json"
|
|
58
59
|
],
|
|
60
|
+
"devDependencies": {
|
|
61
|
+
"@changesets/cli": "^2.29.8",
|
|
62
|
+
"@types/chai": "^5.2.3",
|
|
63
|
+
"@types/mocha": "^10.0.10",
|
|
64
|
+
"@types/node": "^25.0.9",
|
|
65
|
+
"@types/stringify-object": "^4.0.5",
|
|
66
|
+
"chai": "^6.2.2",
|
|
67
|
+
"cross-env": "^10.1.0",
|
|
68
|
+
"generate-arrays": "^2.0.0",
|
|
69
|
+
"mocha": "^11.7.5",
|
|
70
|
+
"stringify-object": "^6.0.0",
|
|
71
|
+
"suite-metrics": "^2.5.0",
|
|
72
|
+
"test-inputs": "^1.4.0",
|
|
73
|
+
"ts-node": "^10.9.2",
|
|
74
|
+
"tsup": "^8.5.1",
|
|
75
|
+
"typescript": "^5.9.3"
|
|
76
|
+
},
|
|
59
77
|
"repository": {
|
|
60
78
|
"type": "git",
|
|
61
79
|
"url": "https://github.com/reid-moffat/bias-random"
|
|
62
80
|
},
|
|
81
|
+
"homepage": "https://www.npmjs.com/package/bias-random?activeTab=readme",
|
|
82
|
+
"funding": {
|
|
83
|
+
"type": "buymeacoffee",
|
|
84
|
+
"url": "https://buymeacoffee.com/reidmoffat"
|
|
85
|
+
},
|
|
63
86
|
"bugs": "https://github.com/reid-moffat/bias-random/issues",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"suite-metrics": "^1.3.1",
|
|
74
|
-
"test-inputs": "^1.3.0",
|
|
75
|
-
"ts-node": "^10.9.2",
|
|
76
|
-
"tsup": "^8.5.0",
|
|
77
|
-
"typescript": "^5.6.2"
|
|
87
|
+
"engines": {
|
|
88
|
+
"node": ">=18.0.0"
|
|
89
|
+
},
|
|
90
|
+
"sideEffects": false,
|
|
91
|
+
"pnpm": {
|
|
92
|
+
"onlyBuiltDependencies": [
|
|
93
|
+
"esbuild",
|
|
94
|
+
"microtime"
|
|
95
|
+
]
|
|
78
96
|
},
|
|
79
97
|
"packageManager": "pnpm@10.18.3"
|
|
80
98
|
}
|