nlptoolkit-util 1.0.2 → 1.0.3

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.
@@ -0,0 +1,7 @@
1
+ export declare class Random {
2
+ private seed;
3
+ constructor(seed?: number);
4
+ private nextRandom;
5
+ nextDouble(min?: number, max?: number): number;
6
+ nextInt(maxRange: number): number;
7
+ }
package/dist/Random.js ADDED
@@ -0,0 +1,38 @@
1
+ (function (factory) {
2
+ if (typeof module === "object" && typeof module.exports === "object") {
3
+ var v = factory(require, exports);
4
+ if (v !== undefined) module.exports = v;
5
+ }
6
+ else if (typeof define === "function" && define.amd) {
7
+ define(["require", "exports"], factory);
8
+ }
9
+ })(function (require, exports) {
10
+ "use strict";
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Random = void 0;
13
+ var Random = /** @class */ (function () {
14
+ function Random(seed) {
15
+ this.seed = 0;
16
+ if (seed != undefined) {
17
+ this.seed = seed;
18
+ }
19
+ }
20
+ Random.prototype.nextRandom = function () {
21
+ this.seed = (1664525 * this.seed + 1013904223) % Number.MAX_SAFE_INTEGER;
22
+ };
23
+ Random.prototype.nextDouble = function (min, max) {
24
+ this.nextRandom();
25
+ if (min != undefined && max != undefined) {
26
+ return min + (this.seed / Number.MAX_SAFE_INTEGER) * (max - min);
27
+ }
28
+ return this.seed / Number.MAX_SAFE_INTEGER;
29
+ };
30
+ Random.prototype.nextInt = function (maxRange) {
31
+ this.nextRandom();
32
+ return this.seed % maxRange;
33
+ };
34
+ return Random;
35
+ }());
36
+ exports.Random = Random;
37
+ });
38
+ //# sourceMappingURL=Random.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Random.js","sourceRoot":"","sources":["../source/Random.ts"],"names":[],"mappings":";;;;;;;;;;;;IAAA;QAII,gBAAY,IAAa;YAFjB,SAAI,GAAW,CAAC,CAAA;YAGpB,IAAI,IAAI,IAAI,SAAS,EAAC;gBAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;aACnB;QACL,CAAC;QAEO,2BAAU,GAAlB;YACI,IAAI,CAAC,IAAI,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAC7E,CAAC;QAED,2BAAU,GAAV,UAAW,GAAY,EAAE,GAAY;YACjC,IAAI,CAAC,UAAU,EAAE,CAAA;YACjB,IAAI,GAAG,IAAI,SAAS,IAAI,GAAG,IAAI,SAAS,EAAC;gBACrC,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,gBAAgB,CAAC,GAAG,CAAC,GAAG,GAAG,GAAG,CAAC,CAAA;aACnE;YACD,OAAO,IAAI,CAAC,IAAI,GAAG,MAAM,CAAC,gBAAgB,CAAC;QAC/C,CAAC;QAED,wBAAO,GAAP,UAAQ,QAAgB;YACpB,IAAI,CAAC,UAAU,EAAE,CAAA;YACjB,OAAO,IAAI,CAAC,IAAI,GAAG,QAAQ,CAAC;QAChC,CAAC;QACL,aAAC;IAAD,CAAC,AA1BD,IA0BC;IA1BY,wBAAM"}
package/index.js CHANGED
@@ -3,4 +3,5 @@ export * from "./dist/Permutation"
3
3
  export * from "./dist/RandomNormalizedArray"
4
4
  export * from "./dist/Subset"
5
5
  export * from "./dist/SubsetFromList"
6
- export * from "./dist/Tuple"
6
+ export * from "./dist/Tuple"
7
+ export * from "./dist/Random"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nlptoolkit-util",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Simple Utils Library",
5
5
  "main": "index.js",
6
6
  "types": "index.js",
@@ -0,0 +1,27 @@
1
+ export class Random {
2
+
3
+ private seed: number = 0
4
+
5
+ constructor(seed?: number) {
6
+ if (seed != undefined){
7
+ this.seed = seed
8
+ }
9
+ }
10
+
11
+ private nextRandom(){
12
+ this.seed = (1664525 * this.seed + 1013904223) % Number.MAX_SAFE_INTEGER;
13
+ }
14
+
15
+ nextDouble(min?: number, max?: number): number{
16
+ this.nextRandom()
17
+ if (min != undefined && max != undefined){
18
+ return min + (this.seed / Number.MAX_SAFE_INTEGER) * (max - min)
19
+ }
20
+ return this.seed / Number.MAX_SAFE_INTEGER;
21
+ }
22
+
23
+ nextInt(maxRange: number): number{
24
+ this.nextRandom()
25
+ return this.seed % maxRange;
26
+ }
27
+ }