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.
- package/dist/Random.d.ts +7 -0
- package/dist/Random.js +38 -0
- package/dist/Random.js.map +1 -0
- package/index.js +2 -1
- package/package.json +1 -1
- package/source/Random.ts +27 -0
package/dist/Random.d.ts
ADDED
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
package/package.json
CHANGED
package/source/Random.ts
ADDED
|
@@ -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
|
+
}
|