@tktb-tess/util-fns 0.11.1 → 0.11.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/README.md +2 -0
- package/dist/bundle.js +374 -482
- package/dist/bundle.min.js +2 -2
- package/dist/pcg_minimal.d.ts +4 -6
- package/dist/random.d.ts +1 -23
- package/dist/util.d.ts +1 -6
- package/dist/worker_stream.d.ts +1 -1
- package/dist/xoshiro_minimal.d.ts +7 -8
- package/package.json +8 -7
- package/dist/icon.svg +0 -23
package/dist/bundle.js
CHANGED
|
@@ -1,252 +1,253 @@
|
|
|
1
|
-
const T = new TextEncoder(),
|
|
2
|
-
if (typeof
|
|
3
|
-
const
|
|
4
|
-
if (
|
|
5
|
-
if (typeof
|
|
6
|
-
return
|
|
7
|
-
if (typeof
|
|
8
|
-
return
|
|
9
|
-
if (typeof
|
|
1
|
+
const T = new TextEncoder(), H = (n, t) => [n].includes(t), h = (n, t) => {
|
|
2
|
+
if (typeof n != typeof t) return !1;
|
|
3
|
+
const e = Object.prototype.toString.call(n), r = Object.prototype.toString.call(t);
|
|
4
|
+
if (e !== r) return !1;
|
|
5
|
+
if (typeof n == "string" || typeof n == "bigint" || typeof n == "boolean" || typeof n == "symbol" || n == null)
|
|
6
|
+
return n === t;
|
|
7
|
+
if (typeof n == "number")
|
|
8
|
+
return n !== n && t !== t || n === t;
|
|
9
|
+
if (typeof n == "function")
|
|
10
10
|
return !1;
|
|
11
|
-
if (Array.isArray(
|
|
12
|
-
if (
|
|
13
|
-
for (let s = 0; s <
|
|
14
|
-
if (!
|
|
11
|
+
if (Array.isArray(n) && Array.isArray(t)) {
|
|
12
|
+
if (n.length !== t.length) return !1;
|
|
13
|
+
for (let s = 0; s < n.length; s++)
|
|
14
|
+
if (!h(n[s], t[s])) return !1;
|
|
15
15
|
return !0;
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
18
|
-
const s = [...
|
|
19
|
-
return !!
|
|
20
|
-
}
|
|
21
|
-
if (
|
|
22
|
-
const s = [...
|
|
23
|
-
if (!
|
|
24
|
-
const i = [...
|
|
25
|
-
return !!
|
|
26
|
-
}
|
|
27
|
-
if (
|
|
28
|
-
const s =
|
|
29
|
-
for (const
|
|
30
|
-
const
|
|
31
|
-
if (
|
|
32
|
-
const [f,
|
|
33
|
-
if (!
|
|
17
|
+
if (n instanceof Set && t instanceof Set) {
|
|
18
|
+
const s = [...n.values()], o = [...t.values()];
|
|
19
|
+
return !!h(s, o);
|
|
20
|
+
}
|
|
21
|
+
if (n instanceof Map && t instanceof Map) {
|
|
22
|
+
const s = [...n.keys()], o = [...t.keys()];
|
|
23
|
+
if (!h(s, o)) return !1;
|
|
24
|
+
const i = [...n.values()], c = [...t.values()];
|
|
25
|
+
return !!h(i, c);
|
|
26
|
+
}
|
|
27
|
+
if (e === "[object Object]") {
|
|
28
|
+
const s = n, o = t, i = Object.keys(s), c = Object.keys(o);
|
|
29
|
+
for (const l of i) {
|
|
30
|
+
const u = c.find((x) => x === l);
|
|
31
|
+
if (u === void 0) return !1;
|
|
32
|
+
const [f, g] = [s[l], o[u]];
|
|
33
|
+
if (!h(f, g)) return !1;
|
|
34
34
|
}
|
|
35
35
|
return !0;
|
|
36
36
|
}
|
|
37
|
-
throw Error(`comparing these objects is unavailable: ${
|
|
38
|
-
cause: [
|
|
37
|
+
throw Error(`comparing these objects is unavailable: ${n}, ${t}`, {
|
|
38
|
+
cause: [n, t]
|
|
39
39
|
});
|
|
40
|
-
},
|
|
41
|
-
let
|
|
40
|
+
}, J = () => {
|
|
41
|
+
let n, t;
|
|
42
42
|
return {
|
|
43
43
|
promise: new Promise((r, s) => {
|
|
44
|
-
|
|
44
|
+
n = r, t = s;
|
|
45
45
|
}),
|
|
46
|
-
resolve:
|
|
46
|
+
resolve: n,
|
|
47
47
|
reject: t
|
|
48
48
|
};
|
|
49
|
-
},
|
|
50
|
-
setTimeout(() => t(),
|
|
51
|
-
}),
|
|
52
|
-
const t = Object.prototype.toString.call(
|
|
49
|
+
}, Y = (n) => new Promise((t) => {
|
|
50
|
+
setTimeout(() => t(), n);
|
|
51
|
+
}), Z = (n) => {
|
|
52
|
+
const t = Object.prototype.toString.call(n);
|
|
53
53
|
return t.slice(8, t.length - 1);
|
|
54
|
-
},
|
|
54
|
+
}, Q = (n) => (...t) => () => n(...t), tt = (n) => {
|
|
55
55
|
const t = [];
|
|
56
|
-
let
|
|
57
|
-
for (let o = 0; o <
|
|
58
|
-
const i =
|
|
59
|
-
i === '"' && (o === 0 ||
|
|
60
|
-
` && !s ? (
|
|
61
|
-
}
|
|
62
|
-
return
|
|
63
|
-
},
|
|
64
|
-
const
|
|
56
|
+
let e = [], r = "", s = !1;
|
|
57
|
+
for (let o = 0; o < n.length; o++) {
|
|
58
|
+
const i = n[o];
|
|
59
|
+
i === '"' && (o === 0 || n[o - 1] !== "\\") ? s = !s : i === "," && !s ? (e.push(r.trim()), r = "") : i === `
|
|
60
|
+
` && !s ? (e.push(r.trim()), t.push(e), e = [], r = "") : r += i;
|
|
61
|
+
}
|
|
62
|
+
return e.push(r.trim()), t.push(e), t;
|
|
63
|
+
}, nt = async (n, t) => {
|
|
64
|
+
const e = T.encode(n), r = await crypto.subtle.digest(t, e);
|
|
65
65
|
return new Uint8Array(r);
|
|
66
|
-
},
|
|
66
|
+
}, et = (n) => encodeURIComponent(n).replace(
|
|
67
67
|
/[!'()*]/g,
|
|
68
|
-
(
|
|
69
|
-
),
|
|
70
|
-
if (
|
|
68
|
+
(e) => `%${e.charCodeAt(0).toString(16).toUpperCase()}`
|
|
69
|
+
), rt = (n) => {
|
|
70
|
+
if (n.includes("+"))
|
|
71
71
|
throw Error("An input string has '+'");
|
|
72
|
-
return decodeURIComponent(
|
|
73
|
-
},
|
|
74
|
-
const r = new Blob([
|
|
72
|
+
return decodeURIComponent(n);
|
|
73
|
+
}, st = async (n, t) => {
|
|
74
|
+
const r = new Blob([n]).stream().pipeThrough(new CompressionStream(t));
|
|
75
75
|
return new Response(r).bytes();
|
|
76
|
-
},
|
|
77
|
-
const r = new Blob([
|
|
76
|
+
}, ot = async (n, t) => {
|
|
77
|
+
const r = new Blob([n]).stream().pipeThrough(new DecompressionStream(t));
|
|
78
78
|
return new Response(r).bytes();
|
|
79
|
-
},
|
|
79
|
+
}, it = (n, t) => new Promise((e, r) => {
|
|
80
80
|
setTimeout(async () => {
|
|
81
81
|
try {
|
|
82
|
-
const s = await
|
|
83
|
-
|
|
82
|
+
const s = await n();
|
|
83
|
+
e(s);
|
|
84
84
|
} catch (s) {
|
|
85
85
|
r(s);
|
|
86
86
|
}
|
|
87
87
|
}, t);
|
|
88
88
|
}), N = "NamedError";
|
|
89
|
-
class
|
|
90
|
-
constructor(t,
|
|
91
|
-
super(
|
|
89
|
+
class I extends Error {
|
|
90
|
+
constructor(t, e, r) {
|
|
91
|
+
super(e, r), this.errName = t;
|
|
92
92
|
}
|
|
93
93
|
static name = N;
|
|
94
94
|
toJSON() {
|
|
95
95
|
const t = (() => {
|
|
96
96
|
const o = this.cause;
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
if (o != null)
|
|
98
|
+
return typeof o == "string" || typeof o == "number" || typeof o == "boolean" ? o : typeof o == "bigint" ? o.toString() : typeof o == "object" ? o instanceof Set || o instanceof Map ? Object.fromEntries(o) : o : void 0;
|
|
99
|
+
})(), { errName: e, message: r, stack: s } = this;
|
|
99
100
|
return {
|
|
100
|
-
errName:
|
|
101
|
+
errName: e,
|
|
101
102
|
message: r,
|
|
102
103
|
stack: s,
|
|
103
104
|
cause: t
|
|
104
105
|
};
|
|
105
106
|
}
|
|
106
107
|
}
|
|
107
|
-
Object.defineProperty(
|
|
108
|
+
Object.defineProperty(I.prototype, Symbol.toStringTag, {
|
|
108
109
|
value: N
|
|
109
110
|
});
|
|
110
|
-
const
|
|
111
|
+
const ct = (n, t) => Math.floor(Math.random() * (t - n) + n), d = (n, t) => {
|
|
111
112
|
t < 0n && (t *= -1n);
|
|
112
|
-
const
|
|
113
|
-
return
|
|
114
|
-
},
|
|
115
|
-
if (!Number.isFinite(
|
|
116
|
-
if (
|
|
117
|
-
const
|
|
118
|
-
let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0,
|
|
113
|
+
const e = n % t;
|
|
114
|
+
return e < 0n ? e + t : e;
|
|
115
|
+
}, U = (n, t = !1) => {
|
|
116
|
+
if (!Number.isFinite(n)) throw Error("`length` is not a valid number");
|
|
117
|
+
if (n <= 0) throw Error("`length` must be positive");
|
|
118
|
+
const e = Math.ceil(n / 8), r = crypto.getRandomValues(new Uint8Array(e));
|
|
119
|
+
let s = Array.from(r, (o) => o.toString(2).padStart(8, "0")).join("").slice(0, n);
|
|
119
120
|
return t && (s = s.replace(/^\d/, "1")), BigInt("0b" + s);
|
|
120
|
-
},
|
|
121
|
-
if (
|
|
122
|
-
throw new
|
|
123
|
-
const
|
|
121
|
+
}, R = (n, t) => {
|
|
122
|
+
if (n >= t)
|
|
123
|
+
throw new I("RangeError", "min is larger than max");
|
|
124
|
+
const e = t - n, r = e.toString(2).length, s = (() => {
|
|
124
125
|
for (let i = 0; i < 1e5; i++) {
|
|
125
|
-
const c =
|
|
126
|
-
if (c >= m(2n, BigInt(r),
|
|
127
|
-
return c %
|
|
126
|
+
const c = U(r);
|
|
127
|
+
if (c >= m(2n, BigInt(r), e))
|
|
128
|
+
return c % e;
|
|
128
129
|
}
|
|
129
130
|
throw Error("Failed to generate a random bigint");
|
|
130
131
|
})();
|
|
131
|
-
return
|
|
132
|
-
}, m = (
|
|
133
|
-
if (
|
|
132
|
+
return n + s;
|
|
133
|
+
}, m = (n, t, e) => {
|
|
134
|
+
if (e < 1n) throw Error("`mod` must be positive");
|
|
134
135
|
if (t < 0n) throw Error("`power` must not be negative");
|
|
135
|
-
if (
|
|
136
|
-
if (
|
|
137
|
-
if (
|
|
136
|
+
if (n = d(n, e), e === 1n) return 0n;
|
|
137
|
+
if (n % e === 1n || n % e === 0n) return n;
|
|
138
|
+
if (n === e - 1n) return t & 1n ? e - 1n : 1n;
|
|
138
139
|
let r = 1n;
|
|
139
140
|
for (; t > 0n; )
|
|
140
|
-
t & 1n && (r = r *
|
|
141
|
+
t & 1n && (r = r * n % e), n = n * n % e, t >>= 1n;
|
|
141
142
|
return r;
|
|
142
|
-
},
|
|
143
|
-
if (
|
|
144
|
-
if (
|
|
143
|
+
}, P = (n, t) => {
|
|
144
|
+
if (n === 0n && t === 0n) return { x: 0n, y: 0n, gcd: 0n };
|
|
145
|
+
if (n === 0n)
|
|
145
146
|
return t > 0n ? { x: 0n, y: -1n, gcd: t } : { x: 0n, y: 1n, gcd: -t };
|
|
146
147
|
if (t === 0n)
|
|
147
|
-
return
|
|
148
|
-
let [
|
|
148
|
+
return n > 0n ? { x: 1n, y: 0n, gcd: n } : { x: -1n, y: 0n, gcd: -n };
|
|
149
|
+
let [e, r, s] = [1n, 0n, n], [o, i, c] = [0n, -1n, t];
|
|
149
150
|
for (; ; ) {
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
[
|
|
151
|
+
const l = s / c, u = s - l * c;
|
|
152
|
+
if (u === 0n) break;
|
|
153
|
+
[e, o] = [o, e - l * o], [r, i] = [i, r - l * i], [s, c] = [c, u];
|
|
153
154
|
}
|
|
154
155
|
return c < 0n && (o *= -1n, i *= -1n, c *= -1n), { x: o, y: i, gcd: c };
|
|
155
|
-
},
|
|
156
|
-
if (
|
|
157
|
-
const
|
|
158
|
-
if (
|
|
159
|
-
let c =
|
|
160
|
-
for (let
|
|
161
|
-
c *=
|
|
156
|
+
}, y = (n, t) => {
|
|
157
|
+
if (n >= t) return 1n;
|
|
158
|
+
const e = BigInt((t - 2n).toString(2).length), r = (t - n) / 2n;
|
|
159
|
+
if (e * r < 63n) {
|
|
160
|
+
let c = n;
|
|
161
|
+
for (let l = n + 2n; l < t; l += 2n)
|
|
162
|
+
c *= l;
|
|
162
163
|
return c;
|
|
163
164
|
}
|
|
164
|
-
const s =
|
|
165
|
+
const s = n + r | 1n, o = y(n, s), i = y(s, t);
|
|
165
166
|
return o * i;
|
|
166
|
-
}, j = (
|
|
167
|
-
let t = 3n,
|
|
168
|
-
const s = BigInt(
|
|
167
|
+
}, j = (n) => {
|
|
168
|
+
let t = 3n, e = 1n, r = 1n;
|
|
169
|
+
const s = BigInt(n.toString(2).length) - 1n;
|
|
169
170
|
for (let o = s - 1n; o > -1n; --o) {
|
|
170
|
-
const i = (
|
|
171
|
-
r *=
|
|
172
|
-
}
|
|
173
|
-
return
|
|
174
|
-
},
|
|
175
|
-
if (
|
|
176
|
-
if (
|
|
177
|
-
const t =
|
|
178
|
-
return j(
|
|
179
|
-
},
|
|
171
|
+
const i = (n >> o) + 1n | 1n;
|
|
172
|
+
r *= y(t, i), t = i, e *= r;
|
|
173
|
+
}
|
|
174
|
+
return e;
|
|
175
|
+
}, lt = (n) => {
|
|
176
|
+
if (n < 0n) throw Error("'n' must be non-negative");
|
|
177
|
+
if (n === 0n) return 1n;
|
|
178
|
+
const t = n - BigInt(n.toString(2).match(/1/g)?.length ?? 0);
|
|
179
|
+
return j(n) << t;
|
|
180
|
+
}, _ = (n, t) => (n >>> (t & 31) | n << (-t & 31)) >>> 0, w = (n, t) => BigInt.asUintN(64, n >> (t & 63n) | n << (-t & 63n)), E = (n, t) => {
|
|
180
181
|
if (t < 1n || t % 2n === 0n)
|
|
181
182
|
throw Error("`n` is invalid");
|
|
182
|
-
for (;
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
let
|
|
186
|
-
for (;
|
|
187
|
-
for (;
|
|
188
|
-
|
|
183
|
+
for (; n < 0n; )
|
|
184
|
+
n += t;
|
|
185
|
+
n %= t;
|
|
186
|
+
let e = 1n;
|
|
187
|
+
for (; n !== 0n; ) {
|
|
188
|
+
for (; n % 2n === 0n; ) {
|
|
189
|
+
n /= 2n;
|
|
189
190
|
const r = t % 8n;
|
|
190
|
-
(r === 3n || r === 5n) && (
|
|
191
|
+
(r === 3n || r === 5n) && (e *= -1n);
|
|
191
192
|
}
|
|
192
|
-
[
|
|
193
|
-
}
|
|
194
|
-
return t === 1n ?
|
|
195
|
-
},
|
|
196
|
-
if (
|
|
197
|
-
if (
|
|
198
|
-
let t = 1n,
|
|
199
|
-
for (; t + 1n <
|
|
200
|
-
const r = (t +
|
|
201
|
-
r * r <
|
|
202
|
-
}
|
|
203
|
-
return
|
|
204
|
-
},
|
|
205
|
-
if (
|
|
206
|
-
if (
|
|
207
|
-
let t =
|
|
193
|
+
[n, t] = [t, n], n % 4n === 3n && t % 4n === 3n && (e *= -1n), n %= t;
|
|
194
|
+
}
|
|
195
|
+
return t === 1n ? e : 0n;
|
|
196
|
+
}, C = (n) => {
|
|
197
|
+
if (n < 0n) return !1;
|
|
198
|
+
if (n === 0n) return !0;
|
|
199
|
+
let t = 1n, e = n;
|
|
200
|
+
for (; t + 1n < e; ) {
|
|
201
|
+
const r = (t + e) / 2n;
|
|
202
|
+
r * r < n ? t = r : e = r;
|
|
203
|
+
}
|
|
204
|
+
return n === t ** 2n || n === (t + 1n) ** 2n;
|
|
205
|
+
}, O = (n) => {
|
|
206
|
+
if (n <= 1n) return !1;
|
|
207
|
+
if (n % 2n === 0n) return n === 2n;
|
|
208
|
+
let t = n - 1n, e = 0n;
|
|
208
209
|
for (; t % 2n === 0n; )
|
|
209
|
-
t >>= 1n,
|
|
210
|
-
const [r, s] = [t,
|
|
211
|
-
let i = m(2n, r,
|
|
210
|
+
t >>= 1n, e += 1n;
|
|
211
|
+
const [r, s] = [t, e];
|
|
212
|
+
let i = m(2n, r, n);
|
|
212
213
|
if (i === 1n) return !0;
|
|
213
214
|
for (let c = 0n; c < s; c++) {
|
|
214
|
-
if (i ===
|
|
215
|
-
i = i * i %
|
|
215
|
+
if (i === n - 1n) return !0;
|
|
216
|
+
i = i * i % n;
|
|
216
217
|
}
|
|
217
218
|
return !1;
|
|
218
|
-
}, V = (
|
|
219
|
-
let t = 5n,
|
|
220
|
-
for (;
|
|
221
|
-
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n &&
|
|
219
|
+
}, V = (n) => {
|
|
220
|
+
let t = 5n, e = E(t, n);
|
|
221
|
+
for (; e > 0n; ) {
|
|
222
|
+
if (t = t > 0n ? t + 2n : t - 2n, t *= -1n, t === -15n && C(n))
|
|
222
223
|
return [0n, 0n];
|
|
223
|
-
|
|
224
|
+
e = E(t, n);
|
|
224
225
|
}
|
|
225
|
-
return [t,
|
|
226
|
-
},
|
|
227
|
-
let s = 1n, o =
|
|
228
|
-
const i =
|
|
226
|
+
return [t, e];
|
|
227
|
+
}, p = (n, t) => (n & 1n) === 1n ? d(n + t >> 1n, t) : d(n >> 1n, t), F = (n, t, e, r) => {
|
|
228
|
+
let s = 1n, o = e;
|
|
229
|
+
const i = n.toString(2).slice(1);
|
|
229
230
|
for (const c of i)
|
|
230
|
-
[s, o] = [
|
|
231
|
+
[s, o] = [d(s * o, t), p(o * o + r * s * s, t)], c === "1" && ([s, o] = [p(e * s + o, t), p(r * s + e * o, t)]);
|
|
231
232
|
return [s, o];
|
|
232
|
-
},
|
|
233
|
-
if (
|
|
233
|
+
}, $ = (n, t, e, r) => {
|
|
234
|
+
if (n % 2n !== 1n)
|
|
234
235
|
throw Error("`n` must be odd");
|
|
235
|
-
let s =
|
|
236
|
+
let s = n + 1n, o = 0n;
|
|
236
237
|
for (; s % 2n === 0n; )
|
|
237
238
|
s >>= 1n, o += 1n;
|
|
238
|
-
const [i, c] =
|
|
239
|
-
let
|
|
239
|
+
const [i, c] = F(s, n, e, t);
|
|
240
|
+
let l = c;
|
|
240
241
|
if (i === 0n) return !0;
|
|
241
|
-
r = m(r, s,
|
|
242
|
-
for (let
|
|
243
|
-
if (
|
|
244
|
-
|
|
242
|
+
r = m(r, s, n);
|
|
243
|
+
for (let u = 0n; u < o; u++) {
|
|
244
|
+
if (l === 0n) return !0;
|
|
245
|
+
l = d(l * l - 2n * r, n), r = m(r, 2n, n);
|
|
245
246
|
}
|
|
246
247
|
return !1;
|
|
247
|
-
},
|
|
248
|
-
if (
|
|
249
|
-
if (
|
|
248
|
+
}, v = (n) => {
|
|
249
|
+
if (n <= 1n) return !1;
|
|
250
|
+
if (n % 2n === 0n) return n === 2n;
|
|
250
251
|
const t = [
|
|
251
252
|
2n,
|
|
252
253
|
3n,
|
|
@@ -276,88 +277,88 @@ const ut = (e, t) => Math.floor(Math.random() * (t - e) + e), g = (e, t) => {
|
|
|
276
277
|
101n
|
|
277
278
|
];
|
|
278
279
|
for (const o of t)
|
|
279
|
-
if (
|
|
280
|
-
return
|
|
281
|
-
if (!
|
|
280
|
+
if (n % o === 0n)
|
|
281
|
+
return n === o;
|
|
282
|
+
if (!O(n))
|
|
282
283
|
return !1;
|
|
283
|
-
const [
|
|
284
|
+
const [e, r] = V(n);
|
|
284
285
|
if (r === 0n) return !1;
|
|
285
|
-
const s = (1n -
|
|
286
|
-
return
|
|
287
|
-
},
|
|
286
|
+
const s = (1n - e) / 4n;
|
|
287
|
+
return $(n, e, 1n, s);
|
|
288
|
+
}, ut = (n, t) => {
|
|
288
289
|
if (t < 2n)
|
|
289
290
|
throw Error("NoPrimesFound");
|
|
290
291
|
for (let r = 0; r < 1e5; r++) {
|
|
291
|
-
const s =
|
|
292
|
-
if (
|
|
292
|
+
const s = R(n, t);
|
|
293
|
+
if (v(s)) return s;
|
|
293
294
|
}
|
|
294
295
|
throw Error("NoPrimesFound");
|
|
295
|
-
},
|
|
296
|
-
if (
|
|
296
|
+
}, at = (n, t = !1) => {
|
|
297
|
+
if (n < 2)
|
|
297
298
|
throw Error("NoPrimesFound");
|
|
298
299
|
for (let r = 0; r < 1e5; r++) {
|
|
299
|
-
const s =
|
|
300
|
-
if (
|
|
300
|
+
const s = U(n, t);
|
|
301
|
+
if (v(s)) return s;
|
|
301
302
|
}
|
|
302
303
|
throw Error("NoPrimesFound");
|
|
303
|
-
},
|
|
304
|
-
class
|
|
304
|
+
}, L = "Rational";
|
|
305
|
+
class a {
|
|
305
306
|
#t;
|
|
306
|
-
#
|
|
307
|
-
static name =
|
|
307
|
+
#n;
|
|
308
|
+
static name = L;
|
|
308
309
|
/**
|
|
309
310
|
* fraction (rational) class
|
|
310
311
|
* @param numerator
|
|
311
312
|
* @param denominator
|
|
312
313
|
*/
|
|
313
|
-
constructor(t,
|
|
314
|
-
|
|
314
|
+
constructor(t, e) {
|
|
315
|
+
e === 0n ? (this.#n = 0n, this.#t = t === 0n ? 0n : t > 0n ? 1n : -1n) : e > 0n ? (this.#t = t, this.#n = e) : (this.#t = -t, this.#n = -e), this.#e();
|
|
315
316
|
}
|
|
316
317
|
/**
|
|
317
318
|
* generates fraction from `number` decimal using continued fraction
|
|
318
319
|
* @param value decimal
|
|
319
320
|
* @param denominatorDigits limit of digits of denominator
|
|
320
321
|
*/
|
|
321
|
-
static fromDecimal(t,
|
|
322
|
+
static fromDecimal(t, e = 5) {
|
|
322
323
|
if (Number.isNaN(t))
|
|
323
|
-
return new
|
|
324
|
+
return new a(0n, 0n);
|
|
324
325
|
if (Math.abs(t) === 1 / 0)
|
|
325
|
-
return new
|
|
326
|
+
return new a(t > 0 ? 1n : -1n, 0n);
|
|
326
327
|
const r = t < 0;
|
|
327
328
|
r && (t *= -1);
|
|
328
329
|
const s = BigInt(Math.floor(t)), o = t - Number(s);
|
|
329
330
|
if (o === 0)
|
|
330
|
-
return new
|
|
331
|
+
return new a(r ? -s : s, 1n);
|
|
331
332
|
t = 1 / o;
|
|
332
|
-
let [i, c] = [1n, s], [
|
|
333
|
-
for (; `${
|
|
334
|
-
const f = BigInt(Math.floor(t)),
|
|
335
|
-
if ([i, c] = [c, f * c + i], [
|
|
336
|
-
return new
|
|
337
|
-
t = 1 /
|
|
333
|
+
let [i, c] = [1n, s], [l, u] = [0n, 1n];
|
|
334
|
+
for (; `${u}`.length < e + 1; ) {
|
|
335
|
+
const f = BigInt(Math.floor(t)), g = t - Number(f);
|
|
336
|
+
if ([i, c] = [c, f * c + i], [l, u] = [u, f * u + l], g === 0)
|
|
337
|
+
return new a(r ? -c : c, u);
|
|
338
|
+
t = 1 / g;
|
|
338
339
|
}
|
|
339
|
-
return new
|
|
340
|
+
return new a(r ? -i : i, l);
|
|
340
341
|
}
|
|
341
342
|
/**
|
|
342
343
|
* reduction
|
|
343
344
|
*/
|
|
344
|
-
#
|
|
345
|
-
const { gcd: t } =
|
|
346
|
-
t !== 0n && (this.#t /= t, this.#
|
|
345
|
+
#e() {
|
|
346
|
+
const { gcd: t } = P(this.#t, this.#n);
|
|
347
|
+
t !== 0n && (this.#t /= t, this.#n /= t);
|
|
347
348
|
}
|
|
348
349
|
/**
|
|
349
350
|
* returns a fraction multiplied by -1
|
|
350
351
|
* @returns
|
|
351
352
|
*/
|
|
352
353
|
minus() {
|
|
353
|
-
return new
|
|
354
|
+
return new a(-this.#t, this.#n);
|
|
354
355
|
}
|
|
355
356
|
/**
|
|
356
357
|
* returns inverse of this fraction
|
|
357
358
|
* @returns
|
|
358
359
|
*/
|
|
359
360
|
inverse() {
|
|
360
|
-
return new
|
|
361
|
+
return new a(this.#n, this.#t);
|
|
361
362
|
}
|
|
362
363
|
/**
|
|
363
364
|
* returns `this + right`
|
|
@@ -365,8 +366,8 @@ class u {
|
|
|
365
366
|
* @returns
|
|
366
367
|
*/
|
|
367
368
|
add(t) {
|
|
368
|
-
const
|
|
369
|
-
return new
|
|
369
|
+
const e = this.#n * t.#n, r = this.#t * t.#n + t.#t * this.#n;
|
|
370
|
+
return new a(r, e);
|
|
370
371
|
}
|
|
371
372
|
/**
|
|
372
373
|
* returns `this - right`
|
|
@@ -382,8 +383,8 @@ class u {
|
|
|
382
383
|
* @returns
|
|
383
384
|
*/
|
|
384
385
|
multiply(t) {
|
|
385
|
-
const
|
|
386
|
-
return new
|
|
386
|
+
const e = this.#n * t.#n, r = this.#t * t.#t;
|
|
387
|
+
return new a(r, e);
|
|
387
388
|
}
|
|
388
389
|
/**
|
|
389
390
|
* returns `this / right`
|
|
@@ -400,22 +401,22 @@ class u {
|
|
|
400
401
|
* @returns `(a+c)/(b+d)`
|
|
401
402
|
*/
|
|
402
403
|
mediant(t) {
|
|
403
|
-
const
|
|
404
|
-
return new
|
|
404
|
+
const e = this.#n + t.#n, r = this.#t + t.#t;
|
|
405
|
+
return new a(r, e);
|
|
405
406
|
}
|
|
406
407
|
/**
|
|
407
408
|
* returns `number` type decimal
|
|
408
409
|
* @returns decimal
|
|
409
410
|
*/
|
|
410
411
|
toDecimal() {
|
|
411
|
-
return Number(this.#t) / Number(this.#
|
|
412
|
+
return Number(this.#t) / Number(this.#n);
|
|
412
413
|
}
|
|
413
414
|
/**
|
|
414
415
|
* returns `'numerator/denominator'`
|
|
415
416
|
* @returns string form
|
|
416
417
|
*/
|
|
417
418
|
toString() {
|
|
418
|
-
return this.#t === 0n && this.#
|
|
419
|
+
return this.#t === 0n && this.#n === 0n ? "NaN" : this.#t === 0n ? "0" : this.#n === 0n ? this.#t < 0n ? "-Infinity" : "Infinity" : this.#n === 1n ? `${this.#t}` : `${this.#t}/${this.#n}`;
|
|
419
420
|
}
|
|
420
421
|
valueOf() {
|
|
421
422
|
return this.toDecimal();
|
|
@@ -423,7 +424,7 @@ class u {
|
|
|
423
424
|
toJSON() {
|
|
424
425
|
return {
|
|
425
426
|
type: "Rational",
|
|
426
|
-
value: ["0x" + this.#t.toString(16), "0x" + this.#
|
|
427
|
+
value: ["0x" + this.#t.toString(16), "0x" + this.#n.toString(16)]
|
|
427
428
|
};
|
|
428
429
|
}
|
|
429
430
|
/**
|
|
@@ -432,8 +433,8 @@ class u {
|
|
|
432
433
|
* @returns
|
|
433
434
|
*/
|
|
434
435
|
static fromData(t) {
|
|
435
|
-
const
|
|
436
|
-
return new
|
|
436
|
+
const e = BigInt(t.value[0]), r = BigInt(t.value[1]);
|
|
437
|
+
return new a(e, r);
|
|
437
438
|
}
|
|
438
439
|
/**
|
|
439
440
|
* pases string whose form is `'numerator/denominator'`
|
|
@@ -447,212 +448,104 @@ class u {
|
|
|
447
448
|
const s = r.at(1), o = r.at(2);
|
|
448
449
|
if (!s || !o)
|
|
449
450
|
throw Error("cannot parse");
|
|
450
|
-
return new
|
|
451
|
+
return new a(BigInt(s), BigInt(o));
|
|
451
452
|
}
|
|
452
453
|
}
|
|
453
|
-
Object.defineProperty(
|
|
454
|
-
value:
|
|
454
|
+
Object.defineProperty(a.prototype, Symbol.toStringTag, {
|
|
455
|
+
value: L
|
|
455
456
|
});
|
|
456
|
-
const
|
|
457
|
-
const t = Array.from(
|
|
457
|
+
const D = (n) => {
|
|
458
|
+
const t = Array.from(n, (e) => String.fromCharCode(e));
|
|
458
459
|
return btoa(t.join(""));
|
|
459
|
-
}, q = (
|
|
460
|
-
const t = atob(
|
|
461
|
-
return Uint8Array.from(t, (
|
|
462
|
-
},
|
|
463
|
-
const t =
|
|
464
|
-
t > 0 && (
|
|
465
|
-
const
|
|
466
|
-
return q(
|
|
467
|
-
},
|
|
468
|
-
let t = Array.from(
|
|
469
|
-
const
|
|
470
|
-
|
|
460
|
+
}, q = (n) => {
|
|
461
|
+
const t = atob(n);
|
|
462
|
+
return Uint8Array.from(t, (e) => e.charCodeAt(0));
|
|
463
|
+
}, ft = (n) => D(n).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, ""), ht = (n) => {
|
|
464
|
+
const t = n.length & 3;
|
|
465
|
+
t > 0 && (n = n + "=".repeat(4 - t));
|
|
466
|
+
const e = n.replaceAll("-", "+").replaceAll("_", "/");
|
|
467
|
+
return q(e);
|
|
468
|
+
}, dt = (n) => {
|
|
469
|
+
let t = Array.from(n, (o) => o.toString(16).padStart(2, "0")).join("");
|
|
470
|
+
const e = t.length % 6;
|
|
471
|
+
e && (t = "0".repeat(6 - e) + t);
|
|
471
472
|
const r = t.matchAll(/.{6}/g);
|
|
472
473
|
return Array.from(
|
|
473
474
|
r,
|
|
474
475
|
(o) => Number.parseInt(o[0], 16).toString(8).padStart(8, "0")
|
|
475
476
|
).join("").replace(/^0+/, "");
|
|
476
|
-
},
|
|
477
|
-
const t =
|
|
478
|
-
t && (
|
|
479
|
-
const
|
|
477
|
+
}, gt = (n) => {
|
|
478
|
+
const t = n.length & 7;
|
|
479
|
+
t && (n = "0".repeat(8 - t) + n);
|
|
480
|
+
const e = n.matchAll(/.{8}/g), s = Array.from(e, (o) => {
|
|
480
481
|
const i = o[0];
|
|
481
482
|
return Number.parseInt(i, 8).toString(16).padStart(6, "0");
|
|
482
483
|
}).join("").matchAll(/.{2}/g);
|
|
483
484
|
return Uint8Array.from(s, (o) => Number.parseInt(o[0], 16));
|
|
484
|
-
}, K = (
|
|
485
|
-
const t =
|
|
486
|
-
t && (
|
|
487
|
-
const
|
|
485
|
+
}, K = (n) => {
|
|
486
|
+
const t = n < 0n;
|
|
487
|
+
t && (n *= -1n);
|
|
488
|
+
const e = n.toString(2).length, r = n === 1n << BigInt(e - 1) && !(e % 7) && t, s = Math.floor(e / 7) + 1;
|
|
488
489
|
return r ? s - 1 : s;
|
|
489
|
-
},
|
|
490
|
-
const t = K(
|
|
491
|
-
|
|
492
|
-
const
|
|
490
|
+
}, mt = (n) => {
|
|
491
|
+
const t = K(n);
|
|
492
|
+
n = BigInt.asUintN(t * 7, n);
|
|
493
|
+
const e = new Uint8Array(t);
|
|
493
494
|
for (let s = 0; s < t - 1; ++s) {
|
|
494
|
-
const o = Number(
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
const r = Number(
|
|
498
|
-
return
|
|
499
|
-
},
|
|
500
|
-
const t =
|
|
501
|
-
let
|
|
495
|
+
const o = Number(n & 127n) | 128;
|
|
496
|
+
e[s] = o, n >>= 7n;
|
|
497
|
+
}
|
|
498
|
+
const r = Number(n & 127n);
|
|
499
|
+
return e[t - 1] = r, n >>= 7n, e;
|
|
500
|
+
}, pt = (n) => {
|
|
501
|
+
const t = n.length;
|
|
502
|
+
let e = 0n;
|
|
502
503
|
for (let r = 0; r < t; ++r) {
|
|
503
|
-
const s = BigInt(
|
|
504
|
-
|
|
505
|
-
}
|
|
506
|
-
return BigInt.asIntN(7 * t,
|
|
507
|
-
},
|
|
508
|
-
if (
|
|
509
|
-
let t = 0;
|
|
510
|
-
for (; e > 0 && !(e & 1); )
|
|
511
|
-
++t, e >>>= 1;
|
|
512
|
-
return t;
|
|
513
|
-
}, M = "FloatRng", S = (e) => {
|
|
514
|
-
if (e === 0n) return 64n;
|
|
504
|
+
const s = BigInt(n[r] & 127);
|
|
505
|
+
e += s << BigInt(7 * r);
|
|
506
|
+
}
|
|
507
|
+
return BigInt.asIntN(7 * t, e);
|
|
508
|
+
}, b = (n) => {
|
|
509
|
+
if (n === 0n) return 64n;
|
|
515
510
|
let t = 0n;
|
|
516
|
-
for (;
|
|
517
|
-
++t,
|
|
511
|
+
for (; n > 0n && !(n & 1n); )
|
|
512
|
+
++t, n >>= 1n;
|
|
518
513
|
return BigInt.asUintN(64, t);
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
throw Error("loop exceeded limit");
|
|
545
|
-
const f = (() => {
|
|
546
|
-
switch (this.#t.bits) {
|
|
547
|
-
case 32:
|
|
548
|
-
return this.#t.getU32Rand() >>> 0;
|
|
549
|
-
case 64: {
|
|
550
|
-
const h = BigInt.asUintN(32, this.#t.getU64Rand());
|
|
551
|
-
return Number(h);
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
})();
|
|
555
|
-
if (f === 0) {
|
|
556
|
-
if (o -= 32, o < 0) {
|
|
557
|
-
o = 0;
|
|
558
|
-
break t;
|
|
559
|
-
}
|
|
560
|
-
} else {
|
|
561
|
-
o -= B(f);
|
|
562
|
-
break t;
|
|
563
|
-
}
|
|
564
|
-
++l;
|
|
565
|
-
}
|
|
566
|
-
} else
|
|
567
|
-
o -= B(s);
|
|
568
|
-
const i = r >>> 8 & 8388607;
|
|
569
|
-
i === 0 && r >>> 31 && ++o;
|
|
570
|
-
const c = Uint32Array.from([o << 23 | i]);
|
|
571
|
-
return new Float32Array(c.buffer)[0];
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* returns a random single-precision floating-point number (float32) in the range of [0.0, 1.0)
|
|
575
|
-
* @returns
|
|
576
|
-
*/
|
|
577
|
-
getF32Rand() {
|
|
578
|
-
for (let n = 0; n < 1e5; ++n) {
|
|
579
|
-
const r = this.#e();
|
|
580
|
-
if (r < 1)
|
|
581
|
-
return r;
|
|
582
|
-
}
|
|
583
|
-
throw Error("exceeded loop limit");
|
|
584
|
-
}
|
|
585
|
-
#n() {
|
|
586
|
-
const t = 0n, n = 1023n, r = (() => {
|
|
587
|
-
switch (this.#t.bits) {
|
|
588
|
-
case 32: {
|
|
589
|
-
const a = BigInt(this.#t.getU32Rand() >>> 0), l = BigInt(this.#t.getU32Rand() >>> 0);
|
|
590
|
-
return a << 32n | l;
|
|
591
|
-
}
|
|
592
|
-
case 64:
|
|
593
|
-
return BigInt.asUintN(64, this.#t.getU64Rand());
|
|
594
|
-
}
|
|
595
|
-
})(), s = r & 0x7ffn;
|
|
596
|
-
let o = n - 1n;
|
|
597
|
-
if (s === 0n) {
|
|
598
|
-
o -= 11n;
|
|
599
|
-
const a = 1e5;
|
|
600
|
-
let l = 0;
|
|
601
|
-
t: for (; ; ) {
|
|
602
|
-
if (l > a)
|
|
603
|
-
throw Error("loop exceeded limit");
|
|
604
|
-
const f = (() => {
|
|
605
|
-
switch (this.#t.bits) {
|
|
606
|
-
case 32: {
|
|
607
|
-
const h = BigInt(this.#t.getU32Rand() >>> 0), p = BigInt(this.#t.getU32Rand() >>> 0);
|
|
608
|
-
return h << 32n | p;
|
|
609
|
-
}
|
|
610
|
-
case 64:
|
|
611
|
-
return BigInt.asUintN(64, this.#t.getU64Rand());
|
|
612
|
-
}
|
|
613
|
-
})();
|
|
614
|
-
if (f === 0n) {
|
|
615
|
-
if (o -= 64n, o < t) {
|
|
616
|
-
o = t;
|
|
617
|
-
break t;
|
|
618
|
-
}
|
|
619
|
-
} else {
|
|
620
|
-
o -= S(f);
|
|
621
|
-
break t;
|
|
622
|
-
}
|
|
623
|
-
++l;
|
|
624
|
-
}
|
|
625
|
-
} else
|
|
626
|
-
o -= S(s);
|
|
627
|
-
const i = BigInt.asUintN(52, r >> 11n);
|
|
628
|
-
i === 0n && r >> 63n && ++o;
|
|
629
|
-
const c = BigUint64Array.from([o << 52n | i]);
|
|
630
|
-
return new Float64Array(c.buffer)[0];
|
|
631
|
-
}
|
|
632
|
-
/**
|
|
633
|
-
* returns a random double-precision floating-point number (float64) in the range of [0.0, 1.0)
|
|
634
|
-
* @returns
|
|
635
|
-
*/
|
|
636
|
-
getF64Rand() {
|
|
637
|
-
for (let n = 0; n < 1e5; ++n) {
|
|
638
|
-
const r = this.#n();
|
|
639
|
-
if (r < 1)
|
|
640
|
-
return r;
|
|
514
|
+
}, S = (n, t) => {
|
|
515
|
+
const e = 0n, r = 1023n, s = n & 0x7ffn;
|
|
516
|
+
let o = r - 1n;
|
|
517
|
+
if (s > 0n)
|
|
518
|
+
return o -= b(s), o;
|
|
519
|
+
o -= 11n;
|
|
520
|
+
const i = 1e5;
|
|
521
|
+
for (let c = 0; c < i; ++c) {
|
|
522
|
+
const l = t();
|
|
523
|
+
if (l > 0n)
|
|
524
|
+
return o -= b(l), o;
|
|
525
|
+
if (o -= 64n, o < e)
|
|
526
|
+
return e;
|
|
527
|
+
}
|
|
528
|
+
throw Error("loop exceeded limit");
|
|
529
|
+
}, yt = (n) => {
|
|
530
|
+
const t = () => BigInt.asUintN(64, n()), e = () => {
|
|
531
|
+
const r = t(), s = BigInt.asUintN(52, r >> 11n), i = s === 0n && r >> 63n === 1n ? S(r, t) + 1n : S(r, t), { buffer: c } = BigUint64Array.from([i << 52n | s]);
|
|
532
|
+
return new Float64Array(c)[0];
|
|
533
|
+
};
|
|
534
|
+
return () => {
|
|
535
|
+
for (let s = 0; s < 1e5; ++s) {
|
|
536
|
+
const o = e();
|
|
537
|
+
if (o < 1)
|
|
538
|
+
return o;
|
|
641
539
|
}
|
|
642
|
-
throw Error("
|
|
643
|
-
}
|
|
644
|
-
}
|
|
645
|
-
Object.defineProperty(G.prototype, Symbol.toStringTag, {
|
|
646
|
-
value: M
|
|
647
|
-
});
|
|
648
|
-
const W = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], z = 0x5851f42d4c957f2dn, A = "PCGMinimal";
|
|
540
|
+
throw Error("Loop limit exceeded");
|
|
541
|
+
};
|
|
542
|
+
}, G = [0x853c49e6748fea9bn, 0xda3e39cb94b95bdbn], W = 0x5851f42d4c957f2dn, A = "PCGMinimal";
|
|
649
543
|
class X {
|
|
650
544
|
/**
|
|
651
545
|
* length = 2, `[state, increment]`
|
|
652
546
|
*/
|
|
653
547
|
#t;
|
|
654
548
|
static name = A;
|
|
655
|
-
bits = 32;
|
|
656
549
|
/**
|
|
657
550
|
* @param seeds
|
|
658
551
|
* `BigUint64Array` with length 2. \
|
|
@@ -667,34 +560,34 @@ class X {
|
|
|
667
560
|
* const betterRng = new PCGMinimal(seed);
|
|
668
561
|
*/
|
|
669
562
|
constructor(t) {
|
|
670
|
-
t && t.length >= 2 ? (this.#t = new BigUint64Array(2), this.#t[1] = t[1] << 1n | 1n, this.#
|
|
563
|
+
t && t.length >= 2 ? (this.#t = new BigUint64Array(2), this.#t[1] = t[1] << 1n | 1n, this.#n(), this.#t[0] += t[0], this.#n()) : this.#t = BigUint64Array.from(G);
|
|
671
564
|
}
|
|
672
565
|
/** step inner state */
|
|
673
|
-
#
|
|
674
|
-
this.#t[0] = this.#t[0] *
|
|
566
|
+
#n() {
|
|
567
|
+
this.#t[0] = this.#t[0] * W + this.#t[1];
|
|
675
568
|
}
|
|
676
569
|
/** 32bit 乱数を返す (内部状態は変わらない) */
|
|
677
|
-
get #
|
|
678
|
-
const t = this.#t[0],
|
|
679
|
-
return
|
|
570
|
+
get #e() {
|
|
571
|
+
const t = this.#t[0], e = Number(t >> 59n), r = Number(BigInt.asUintN(32, (t ^ t >> 18n) >> 27n));
|
|
572
|
+
return _(r, e);
|
|
680
573
|
}
|
|
681
574
|
/**
|
|
682
575
|
*
|
|
683
576
|
* @returns a random 32-bit unsigned integer
|
|
684
577
|
*/
|
|
685
|
-
|
|
686
|
-
return this.#
|
|
578
|
+
getRandU32() {
|
|
579
|
+
return this.#n(), this.#e;
|
|
687
580
|
}
|
|
688
581
|
/**
|
|
689
582
|
* @returns a random 32-bit unsigned integer less than `bound`
|
|
690
583
|
*/
|
|
691
|
-
|
|
584
|
+
getBoundedRandU32(t) {
|
|
692
585
|
if (t > 4294967296) throw Error("`bound` exceeded limit (2^32)");
|
|
693
586
|
if (t <= 0)
|
|
694
587
|
throw Error("'bound' must be positive");
|
|
695
588
|
const r = 4294967296 % t, s = 1e5;
|
|
696
589
|
for (let o = 0; o < s; ++o) {
|
|
697
|
-
const i = this.
|
|
590
|
+
const i = this.getRandU32();
|
|
698
591
|
if (i >= r)
|
|
699
592
|
return i % t;
|
|
700
593
|
}
|
|
@@ -708,23 +601,23 @@ class X {
|
|
|
708
601
|
* the iterator that generates random 32-bit unsigned integers `step` times \
|
|
709
602
|
* if `bound` is given, random integers are less than `bound`
|
|
710
603
|
*/
|
|
711
|
-
*
|
|
604
|
+
*genRandU32s(t, e) {
|
|
712
605
|
if (t <= 0)
|
|
713
606
|
throw Error("'step' must be positive");
|
|
714
607
|
for (let r = 0; r < t; r++)
|
|
715
|
-
yield typeof
|
|
608
|
+
yield typeof e == "number" ? this.getBoundedRandU32(e) : this.getRandU32();
|
|
716
609
|
}
|
|
717
610
|
}
|
|
718
611
|
Object.defineProperty(X.prototype, Symbol.toStringTag, {
|
|
719
612
|
value: A
|
|
720
613
|
});
|
|
721
|
-
const
|
|
614
|
+
const k = [
|
|
722
615
|
0xbe562cb412e2260en,
|
|
723
616
|
0x2e4284137d641affn,
|
|
724
617
|
0x4e19b36ee933e27en,
|
|
725
618
|
0x7581cf8c4f4d4f7dn
|
|
726
619
|
];
|
|
727
|
-
class
|
|
620
|
+
class B {
|
|
728
621
|
bits = 64;
|
|
729
622
|
#t;
|
|
730
623
|
static name = "XoshiroMinimal";
|
|
@@ -742,68 +635,68 @@ class U {
|
|
|
742
635
|
* const betterRng = new XoshiroMinimal(seed);
|
|
743
636
|
*/
|
|
744
637
|
constructor(t) {
|
|
745
|
-
t && t.length >= 4 ? (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#
|
|
638
|
+
t && t.length >= 4 ? (this.#t = new BigUint64Array(4), this.#t[0] = t[0], this.#t[1] = t[1], this.#n(), this.#t[2] += t[2], this.#t[3] += t[3]) : this.#t = BigUint64Array.from(k);
|
|
746
639
|
}
|
|
747
|
-
#
|
|
640
|
+
#n() {
|
|
748
641
|
const t = this.#t[1] << 17n;
|
|
749
|
-
this.#t[2] ^= this.#t[0], this.#t[3] ^= this.#t[1], this.#t[1] ^= this.#t[2], this.#t[0] ^= this.#t[3], this.#t[2] ^= t, this.#t[3] =
|
|
642
|
+
this.#t[2] ^= this.#t[0], this.#t[3] ^= this.#t[1], this.#t[1] ^= this.#t[2], this.#t[0] ^= this.#t[3], this.#t[2] ^= t, this.#t[3] = w(this.#t[3], 45n);
|
|
750
643
|
}
|
|
751
644
|
get value() {
|
|
752
|
-
const t =
|
|
645
|
+
const t = w(this.#t[0] + this.#t[3], 23n) + this.#t[0];
|
|
753
646
|
return BigInt.asUintN(64, t);
|
|
754
647
|
}
|
|
755
|
-
|
|
648
|
+
getRandU64() {
|
|
756
649
|
const t = this.value;
|
|
757
|
-
return this.#
|
|
650
|
+
return this.#n(), t;
|
|
758
651
|
}
|
|
759
|
-
|
|
760
|
-
const t = BigInt.asUintN(32, this.
|
|
652
|
+
getRandU32() {
|
|
653
|
+
const t = BigInt.asUintN(32, this.getRandU64());
|
|
761
654
|
return Number(t);
|
|
762
655
|
}
|
|
763
|
-
|
|
764
|
-
const
|
|
765
|
-
if (t >
|
|
656
|
+
getBoundedRandU64(t) {
|
|
657
|
+
const e = 1n << 64n;
|
|
658
|
+
if (t > e)
|
|
766
659
|
throw Error("'bound' exceeded limit");
|
|
767
660
|
if (t <= 0n)
|
|
768
661
|
throw Error("'bound' must be positive");
|
|
769
|
-
const r =
|
|
662
|
+
const r = e % t, s = 1e5;
|
|
770
663
|
for (let o = 0; o < s; ++o) {
|
|
771
|
-
const i = this.
|
|
664
|
+
const i = this.getRandU64();
|
|
772
665
|
if (i >= r)
|
|
773
666
|
return i % t;
|
|
774
667
|
}
|
|
775
668
|
throw Error("exceeded loop limit");
|
|
776
669
|
}
|
|
777
|
-
|
|
670
|
+
getBoundedRandU32(t) {
|
|
778
671
|
if (t > 4294967296)
|
|
779
672
|
throw Error("'bound' exceeded limit");
|
|
780
673
|
if (t <= 0n)
|
|
781
674
|
throw Error("'bound' must be positive");
|
|
782
|
-
const r = this.
|
|
675
|
+
const r = this.getBoundedRandU64(BigInt(t));
|
|
783
676
|
return Number(r);
|
|
784
677
|
}
|
|
785
|
-
*
|
|
678
|
+
*genRandU64s(t, e) {
|
|
786
679
|
if (t <= 0)
|
|
787
680
|
throw Error("'step' must be positive");
|
|
788
681
|
for (let r = 0; r < t; ++r)
|
|
789
|
-
yield
|
|
682
|
+
yield e === void 0 ? this.getRandU64() : this.getBoundedRandU64(e);
|
|
790
683
|
}
|
|
791
|
-
*
|
|
684
|
+
*genRandU32s(t, e) {
|
|
792
685
|
if (t <= 0)
|
|
793
686
|
throw Error("'step' must be positive");
|
|
794
687
|
for (let r = 0; r < t; ++r)
|
|
795
|
-
yield
|
|
688
|
+
yield e === void 0 ? this.getRandU32() : this.getBoundedRandU32(e);
|
|
796
689
|
}
|
|
797
690
|
}
|
|
798
|
-
Object.defineProperty(
|
|
799
|
-
value:
|
|
691
|
+
Object.defineProperty(B.prototype, Symbol.toStringTag, {
|
|
692
|
+
value: B.name
|
|
800
693
|
});
|
|
801
|
-
const
|
|
802
|
-
class
|
|
694
|
+
const M = "WorkerStream";
|
|
695
|
+
class z extends ReadableStream {
|
|
803
696
|
close;
|
|
804
697
|
#t;
|
|
805
|
-
static name =
|
|
806
|
-
constructor(t,
|
|
698
|
+
static name = M;
|
|
699
|
+
constructor(t, e) {
|
|
807
700
|
let r, s, o;
|
|
808
701
|
super(
|
|
809
702
|
{
|
|
@@ -812,10 +705,10 @@ class J extends ReadableStream {
|
|
|
812
705
|
i.enqueue(c.data);
|
|
813
706
|
}, s = (c) => {
|
|
814
707
|
t.removeEventListener("message", r), t.removeEventListener("error", s);
|
|
815
|
-
const
|
|
708
|
+
const l = new I("WorkerStreamError", c.message, {
|
|
816
709
|
cause: c.error
|
|
817
710
|
});
|
|
818
|
-
i.error(
|
|
711
|
+
i.error(l);
|
|
819
712
|
}, o = () => {
|
|
820
713
|
t.removeEventListener("message", r), t.removeEventListener("error", s), i.close();
|
|
821
714
|
}, t.addEventListener("message", r), t.addEventListener("error", s);
|
|
@@ -824,57 +717,56 @@ class J extends ReadableStream {
|
|
|
824
717
|
console.log("Canceled reason:", i), t.removeEventListener("message", r), t.removeEventListener("error", s);
|
|
825
718
|
}
|
|
826
719
|
},
|
|
827
|
-
|
|
720
|
+
e
|
|
828
721
|
), this.close = o, this.#t = t;
|
|
829
722
|
}
|
|
830
|
-
postMessage(t,
|
|
831
|
-
this.#t.postMessage(t,
|
|
723
|
+
postMessage(t, e) {
|
|
724
|
+
this.#t.postMessage(t, e);
|
|
832
725
|
}
|
|
833
726
|
}
|
|
834
|
-
Object.defineProperty(
|
|
835
|
-
value:
|
|
727
|
+
Object.defineProperty(z.prototype, Symbol.toStringTag, {
|
|
728
|
+
value: M
|
|
836
729
|
});
|
|
837
730
|
export {
|
|
838
|
-
|
|
839
|
-
w as NamedError,
|
|
731
|
+
I as NamedError,
|
|
840
732
|
X as PCGMinimal,
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
733
|
+
a as Rational,
|
|
734
|
+
z as WorkerStream,
|
|
735
|
+
B as XoshiroMinimal,
|
|
736
|
+
v as bailliePSW,
|
|
737
|
+
st as compress,
|
|
738
|
+
pt as decodeLEB128,
|
|
739
|
+
rt as decodeRFC3986URIComponent,
|
|
740
|
+
ot as decompress,
|
|
741
|
+
mt as encodeLEB128,
|
|
742
|
+
et as encodeRFC3986URIComponent,
|
|
743
|
+
P as exEuclidean,
|
|
744
|
+
lt as factorial,
|
|
745
|
+
yt as floatRng,
|
|
853
746
|
q as fromBase64,
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
O as isSquare,
|
|
747
|
+
ht as fromBase64Url,
|
|
748
|
+
gt as fromOct,
|
|
749
|
+
nt as getHash,
|
|
750
|
+
U as getRandBIByBitLength,
|
|
751
|
+
R as getRandBIByRange,
|
|
752
|
+
at as getRandPrimeByBitLength,
|
|
753
|
+
ut as getRandPrimeByRange,
|
|
754
|
+
ct as getRndInt,
|
|
755
|
+
Z as getStringTag,
|
|
756
|
+
h as isDeepStrictEqual,
|
|
757
|
+
C as isSquare,
|
|
866
758
|
E as jacobiSymbol,
|
|
867
|
-
|
|
759
|
+
Q as lazify,
|
|
868
760
|
m as modPow,
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
761
|
+
tt as parseCSV,
|
|
762
|
+
d as residue,
|
|
763
|
+
_ as rot32,
|
|
764
|
+
w as rot64,
|
|
765
|
+
H as sameValueZero,
|
|
766
|
+
it as setTimeoutPromise,
|
|
767
|
+
Y as sleep,
|
|
768
|
+
D as toBase64,
|
|
769
|
+
ft as toBase64Url,
|
|
770
|
+
dt as toOct,
|
|
771
|
+
J as withResolvers
|
|
880
772
|
};
|