lib0 0.2.49 → 0.2.50
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 -1
- package/broadcastchannel.d.ts +3 -3
- package/broadcastchannel.d.ts.map +1 -1
- package/broadcastchannel.js +5 -4
- package/dist/{broadcastchannel-1ac6c212.cjs → broadcastchannel-6da71c2f.cjs} +6 -5
- package/dist/broadcastchannel-6da71c2f.cjs.map +1 -0
- package/dist/broadcastchannel.cjs +1 -1
- package/dist/broadcastchannel.d.ts +3 -3
- package/dist/broadcastchannel.d.ts.map +1 -1
- package/dist/index.cjs +2 -2
- package/dist/{prng-1aa0a1bc.cjs → prng-bbec83e2.cjs} +2 -2
- package/dist/prng-bbec83e2.cjs.map +1 -0
- package/dist/prng.cjs +1 -1
- package/dist/prng.d.ts +1 -1
- package/dist/random.cjs +7 -1
- package/dist/random.cjs.map +1 -1
- package/dist/random.d.ts +1 -0
- package/dist/random.d.ts.map +1 -1
- package/dist/random.test.d.ts +1 -0
- package/dist/random.test.d.ts.map +1 -1
- package/dist/test.cjs +43 -10
- package/dist/test.cjs.map +1 -1
- package/dist/test.js +69 -36
- package/dist/test.js.map +1 -1
- package/dist/testing.cjs +1 -1
- package/package.json +1 -1
- package/prng.d.ts +1 -1
- package/prng.js +1 -1
- package/random.d.ts +1 -0
- package/random.d.ts.map +1 -1
- package/random.js +6 -1
- package/random.test.d.ts +1 -0
- package/random.test.d.ts.map +1 -1
- package/dist/broadcastchannel-1ac6c212.cjs.map +0 -1
- package/dist/prng-1aa0a1bc.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -181,7 +181,7 @@ broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from t
|
|
|
181
181
|
<dd><p>Subscribe to global <code>publish</code> events.</p></dd>
|
|
182
182
|
<b><code>broadcastchannel.unsubscribe(room: string, f: function(any):any)</code></b><br>
|
|
183
183
|
<dd><p>Unsubscribe from <code>publish</code> global events.</p></dd>
|
|
184
|
-
<b><code>broadcastchannel.publish(room: string, data: any)</code></b><br>
|
|
184
|
+
<b><code>broadcastchannel.publish(room: string, data: any, origin: any)</code></b><br>
|
|
185
185
|
<dd><p>Publish data to all subscribers (including subscribers on this tab)</p></dd>
|
|
186
186
|
</dl>
|
|
187
187
|
</details>
|
|
@@ -1098,6 +1098,7 @@ library has some insane environment where global Promise objects are overwritten
|
|
|
1098
1098
|
<dl>
|
|
1099
1099
|
<b><code>random.rand</code></b><br>
|
|
1100
1100
|
<b><code>random.uint32</code></b><br>
|
|
1101
|
+
<b><code>random.uint53</code></b><br>
|
|
1101
1102
|
<b><code>random.oneOf(arr: Array<T>): T</code></b><br>
|
|
1102
1103
|
<b><code>random.uuidv4</code></b><br>
|
|
1103
1104
|
</dl>
|
package/broadcastchannel.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export function subscribe(room: string, f: (arg0: any) => any): Set<
|
|
1
|
+
export function subscribe(room: string, f: (arg0: any) => any): Set<(arg0: any, arg1: any) => any>;
|
|
2
2
|
export function unsubscribe(room: string, f: (arg0: any) => any): boolean;
|
|
3
|
-
export function publish(room: string, data: any): void;
|
|
3
|
+
export function publish(room: string, data: any, origin?: any): void;
|
|
4
4
|
export type Channel = {
|
|
5
|
-
subs: Set<
|
|
5
|
+
subs: Set<(arg0: any, arg1: any) => any>;
|
|
6
6
|
bc: any;
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=broadcastchannel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,KAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,KAAE,GAAG,cAvDD,GAAG,QAAE,GAAG,KAAE,GAAG,EAyD0B;AAS3D,kCAHI,MAAM,YACG,GAAG,KAAE,GAAG,WAE2C;AAUhE,8BAJI,MAAM,QACN,GAAG,WACH,GAAG,QAMb;;UAhFa,WAAa,GAAG,QAAE,GAAG,KAAE,GAAG,CAAC;QAC3B,GAAG"}
|
package/broadcastchannel.js
CHANGED
|
@@ -23,7 +23,7 @@ import * as storage from './storage.js'
|
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* @typedef {Object} Channel
|
|
26
|
-
* @property {Set<
|
|
26
|
+
* @property {Set<function(any, any):any>} Channel.subs
|
|
27
27
|
* @property {any} Channel.bc
|
|
28
28
|
*/
|
|
29
29
|
|
|
@@ -67,7 +67,7 @@ const getChannel = room =>
|
|
|
67
67
|
/**
|
|
68
68
|
* @param {{data:ArrayBuffer}} e
|
|
69
69
|
*/
|
|
70
|
-
bc.onmessage = e => subs.forEach(sub => sub(e.data))
|
|
70
|
+
bc.onmessage = e => subs.forEach(sub => sub(e.data, 'broadcastchannel'))
|
|
71
71
|
return {
|
|
72
72
|
bc, subs
|
|
73
73
|
}
|
|
@@ -97,9 +97,10 @@ export const unsubscribe = (room, f) => getChannel(room).subs.delete(f)
|
|
|
97
97
|
* @function
|
|
98
98
|
* @param {string} room
|
|
99
99
|
* @param {any} data
|
|
100
|
+
* @param {any} [origin]
|
|
100
101
|
*/
|
|
101
|
-
export const publish = (room, data) => {
|
|
102
|
+
export const publish = (room, data, origin = null) => {
|
|
102
103
|
const c = getChannel(room)
|
|
103
104
|
c.bc.postMessage(data)
|
|
104
|
-
c.subs.forEach(sub => sub(data))
|
|
105
|
+
c.subs.forEach(sub => sub(data, origin))
|
|
105
106
|
}
|
|
@@ -8,7 +8,7 @@ var storage = require('./storage.cjs');
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* @typedef {Object} Channel
|
|
11
|
-
* @property {Set<
|
|
11
|
+
* @property {Set<function(any, any):any>} Channel.subs
|
|
12
12
|
* @property {any} Channel.bc
|
|
13
13
|
*/
|
|
14
14
|
|
|
@@ -52,7 +52,7 @@ const getChannel = room =>
|
|
|
52
52
|
/**
|
|
53
53
|
* @param {{data:ArrayBuffer}} e
|
|
54
54
|
*/
|
|
55
|
-
bc.onmessage = e => subs.forEach(sub => sub(e.data));
|
|
55
|
+
bc.onmessage = e => subs.forEach(sub => sub(e.data, 'broadcastchannel'));
|
|
56
56
|
return {
|
|
57
57
|
bc, subs
|
|
58
58
|
}
|
|
@@ -82,11 +82,12 @@ const unsubscribe = (room, f) => getChannel(room).subs.delete(f);
|
|
|
82
82
|
* @function
|
|
83
83
|
* @param {string} room
|
|
84
84
|
* @param {any} data
|
|
85
|
+
* @param {any} [origin]
|
|
85
86
|
*/
|
|
86
|
-
const publish = (room, data) => {
|
|
87
|
+
const publish = (room, data, origin = null) => {
|
|
87
88
|
const c = getChannel(room);
|
|
88
89
|
c.bc.postMessage(data);
|
|
89
|
-
c.subs.forEach(sub => sub(data));
|
|
90
|
+
c.subs.forEach(sub => sub(data, origin));
|
|
90
91
|
};
|
|
91
92
|
|
|
92
93
|
var broadcastchannel = /*#__PURE__*/Object.freeze({
|
|
@@ -100,4 +101,4 @@ exports.broadcastchannel = broadcastchannel;
|
|
|
100
101
|
exports.publish = publish;
|
|
101
102
|
exports.subscribe = subscribe;
|
|
102
103
|
exports.unsubscribe = unsubscribe;
|
|
103
|
-
//# sourceMappingURL=broadcastchannel-
|
|
104
|
+
//# sourceMappingURL=broadcastchannel-6da71c2f.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"broadcastchannel-6da71c2f.cjs","sources":["../broadcastchannel.js"],"sourcesContent":["/* eslint-env browser */\n\n/**\n * Helpers for cross-tab communication using broadcastchannel with LocalStorage fallback.\n *\n * ```js\n * // In browser window A:\n * broadcastchannel.subscribe('my events', data => console.log(data))\n * broadcastchannel.publish('my events', 'Hello world!') // => A: 'Hello world!' fires synchronously in same tab\n *\n * // In browser window B:\n * broadcastchannel.publish('my events', 'hello from tab B') // => A: 'hello from tab B'\n * ```\n *\n * @module broadcastchannel\n */\n\n// @todo before next major: use Uint8Array instead as buffer object\n\nimport * as map from './map.js'\nimport * as buffer from './buffer.js'\nimport * as storage from './storage.js'\n\n/**\n * @typedef {Object} Channel\n * @property {Set<function(any, any):any>} Channel.subs\n * @property {any} Channel.bc\n */\n\n/**\n * @type {Map<string, Channel>}\n */\nconst channels = new Map()\n\nclass LocalStoragePolyfill {\n /**\n * @param {string} room\n */\n constructor (room) {\n this.room = room\n /**\n * @type {null|function({data:ArrayBuffer}):void}\n */\n this.onmessage = null\n storage.onChange(e => e.key === room && this.onmessage !== null && this.onmessage({ data: buffer.fromBase64(e.newValue || '') }))\n }\n\n /**\n * @param {ArrayBuffer} buf\n */\n postMessage (buf) {\n storage.varStorage.setItem(this.room, buffer.toBase64(buffer.createUint8ArrayFromArrayBuffer(buf)))\n }\n}\n\n// Use BroadcastChannel or Polyfill\nconst BC = typeof BroadcastChannel === 'undefined' ? LocalStoragePolyfill : BroadcastChannel\n\n/**\n * @param {string} room\n * @return {Channel}\n */\nconst getChannel = room =>\n map.setIfUndefined(channels, room, () => {\n const subs = new Set()\n const bc = new BC(room)\n /**\n * @param {{data:ArrayBuffer}} e\n */\n bc.onmessage = e => subs.forEach(sub => sub(e.data, 'broadcastchannel'))\n return {\n bc, subs\n }\n })\n\n/**\n * Subscribe to global `publish` events.\n *\n * @function\n * @param {string} room\n * @param {function(any):any} f\n */\nexport const subscribe = (room, f) => getChannel(room).subs.add(f)\n\n/**\n * Unsubscribe from `publish` global events.\n *\n * @function\n * @param {string} room\n * @param {function(any):any} f\n */\nexport const unsubscribe = (room, f) => getChannel(room).subs.delete(f)\n\n/**\n * Publish data to all subscribers (including subscribers on this tab)\n *\n * @function\n * @param {string} room\n * @param {any} data\n * @param {any} [origin]\n */\nexport const publish = (room, data, origin = null) => {\n const c = getChannel(room)\n c.bc.postMessage(data)\n c.subs.forEach(sub => sub(data, origin))\n}\n"],"names":["storage.onChange","buffer.fromBase64","storage.varStorage","buffer.toBase64","buffer.createUint8ArrayFromArrayBuffer","map.setIfUndefined"],"mappings":";;;;;;AAAA;AAsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAM,QAAQ,GAAG,IAAI,GAAG,GAAE;AAC1B;AACA,MAAM,oBAAoB,CAAC;AAC3B;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA;AACA;AACA,IAAI,IAAI,CAAC,SAAS,GAAG,KAAI;AACzB,IAAIA,gBAAgB,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,EAAE,IAAI,EAAEC,mBAAiB,CAAC,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAC,EAAE,CAAC,EAAC;AACrI,GAAG;AACH;AACA;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,GAAG,EAAE;AACpB,IAAIC,kBAAkB,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,EAAEC,iBAAe,CAACC,wCAAsC,CAAC,GAAG,CAAC,CAAC,EAAC;AACvG,GAAG;AACH,CAAC;AACD;AACA;AACA,MAAM,EAAE,GAAG,OAAO,gBAAgB,KAAK,WAAW,GAAG,oBAAoB,GAAG,iBAAgB;AAC5F;AACA;AACA;AACA;AACA;AACA,MAAM,UAAU,GAAG,IAAI;AACvB,EAAEC,kBAAkB,CAAC,QAAQ,EAAE,IAAI,EAAE,MAAM;AAC3C,IAAI,MAAM,IAAI,GAAG,IAAI,GAAG,GAAE;AAC1B,IAAI,MAAM,EAAE,GAAG,IAAI,EAAE,CAAC,IAAI,EAAC;AAC3B;AACA;AACA;AACA,IAAI,EAAE,CAAC,SAAS,GAAG,CAAC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,kBAAkB,CAAC,EAAC;AAC5E,IAAI,OAAO;AACX,MAAM,EAAE,EAAE,IAAI;AACd,KAAK;AACL,GAAG,EAAC;AACJ;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,SAAS,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAC;AAClE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,EAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,OAAO,GAAG,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,KAAK;AACtD,EAAE,MAAM,CAAC,GAAG,UAAU,CAAC,IAAI,EAAC;AAC5B,EAAE,CAAC,CAAC,EAAE,CAAC,WAAW,CAAC,IAAI,EAAC;AACxB,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EAAC;AAC1C;;;;;;;;;;;;;;"}
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
require('./map-28a001c9.cjs');
|
|
6
6
|
require('./buffer-c98f67d5.cjs');
|
|
7
7
|
require('./storage.cjs');
|
|
8
|
-
var broadcastchannel = require('./broadcastchannel-
|
|
8
|
+
var broadcastchannel = require('./broadcastchannel-6da71c2f.cjs');
|
|
9
9
|
require('./string-ad04f734.cjs');
|
|
10
10
|
require('./environment-60b83194.cjs');
|
|
11
11
|
require('./conditions-fb475c70.cjs');
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export function subscribe(room: string, f: (arg0: any) => any): Set<
|
|
1
|
+
export function subscribe(room: string, f: (arg0: any) => any): Set<(arg0: any, arg1: any) => any>;
|
|
2
2
|
export function unsubscribe(room: string, f: (arg0: any) => any): boolean;
|
|
3
|
-
export function publish(room: string, data: any): void;
|
|
3
|
+
export function publish(room: string, data: any, origin?: any): void;
|
|
4
4
|
export type Channel = {
|
|
5
|
-
subs: Set<
|
|
5
|
+
subs: Set<(arg0: any, arg1: any) => any>;
|
|
6
6
|
bc: any;
|
|
7
7
|
};
|
|
8
8
|
//# sourceMappingURL=broadcastchannel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["../broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,KAAE,GAAG,
|
|
1
|
+
{"version":3,"file":"broadcastchannel.d.ts","sourceRoot":"","sources":["../broadcastchannel.js"],"names":[],"mappings":"AAkFO,gCAHI,MAAM,YACG,GAAG,KAAE,GAAG,cAvDD,GAAG,QAAE,GAAG,KAAE,GAAG,EAyD0B;AAS3D,kCAHI,MAAM,YACG,GAAG,KAAE,GAAG,WAE2C;AAUhE,8BAJI,MAAM,QACN,GAAG,WACH,GAAG,QAMb;;UAhFa,WAAa,GAAG,QAAE,GAAG,KAAE,GAAG,CAAC;QAC3B,GAAG"}
|
package/dist/index.cjs
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var array = require('./array-acefe0f2.cjs');
|
|
6
6
|
var binary = require('./binary-ac8e39e2.cjs');
|
|
7
|
-
var broadcastchannel = require('./broadcastchannel-
|
|
7
|
+
var broadcastchannel = require('./broadcastchannel-6da71c2f.cjs');
|
|
8
8
|
var encoding = require('./buffer-c98f67d5.cjs');
|
|
9
9
|
var conditions = require('./conditions-fb475c70.cjs');
|
|
10
10
|
var diff = require('./diff-2593547b.cjs');
|
|
@@ -23,7 +23,7 @@ var mutex = require('./mutex-63f09c81.cjs');
|
|
|
23
23
|
var number = require('./number-e62129bc.cjs');
|
|
24
24
|
var object = require('./object-dcdd6eed.cjs');
|
|
25
25
|
var pair = require('./pair-ab022bc3.cjs');
|
|
26
|
-
var prng = require('./prng-
|
|
26
|
+
var prng = require('./prng-bbec83e2.cjs');
|
|
27
27
|
var promise = require('./promise-1a9fe712.cjs');
|
|
28
28
|
var set = require('./set-b596ef38.cjs');
|
|
29
29
|
var sort = require('./sort-b8702761.cjs');
|
|
@@ -160,7 +160,7 @@ int main(void)
|
|
|
160
160
|
/**
|
|
161
161
|
* Description of the function
|
|
162
162
|
* @callback generatorNext
|
|
163
|
-
* @return {number} A
|
|
163
|
+
* @return {number} A random float in the cange of [0,1)
|
|
164
164
|
*/
|
|
165
165
|
|
|
166
166
|
/**
|
|
@@ -383,4 +383,4 @@ exports.uint8Array = uint8Array;
|
|
|
383
383
|
exports.utf16Rune = utf16Rune;
|
|
384
384
|
exports.utf16String = utf16String;
|
|
385
385
|
exports.word = word;
|
|
386
|
-
//# sourceMappingURL=prng-
|
|
386
|
+
//# sourceMappingURL=prng-bbec83e2.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prng-bbec83e2.cjs","sources":["../prng/Xorshift32.js","../prng/Xoroshiro128plus.js","../prng.js"],"sourcesContent":["/**\n * @module prng\n */\n\nimport * as binary from '../binary.js'\n\n/**\n * Xorshift32 is a very simple but elegang PRNG with a period of `2^32-1`.\n */\nexport class Xorshift32 {\n /**\n * @param {number} seed Unsigned 32 bit number\n */\n constructor (seed) {\n this.seed = seed\n /**\n * @type {number}\n */\n this._state = seed\n }\n\n /**\n * Generate a random signed integer.\n *\n * @return {Number} A 32 bit signed integer.\n */\n next () {\n let x = this._state\n x ^= x << 13\n x ^= x >> 17\n x ^= x << 5\n this._state = x\n return (x >>> 0) / (binary.BITS32 + 1)\n }\n}\n","/**\n * @module prng\n */\n\nimport { Xorshift32 } from './Xorshift32.js'\nimport * as binary from '../binary.js'\n\n/**\n * This is a variant of xoroshiro128plus - the fastest full-period generator passing BigCrush without systematic failures.\n *\n * This implementation follows the idea of the original xoroshiro128plus implementation,\n * but is optimized for the JavaScript runtime. I.e.\n * * The operations are performed on 32bit integers (the original implementation works with 64bit values).\n * * The initial 128bit state is computed based on a 32bit seed and Xorshift32.\n * * This implementation returns two 32bit values based on the 64bit value that is computed by xoroshiro128plus.\n * Caution: The last addition step works slightly different than in the original implementation - the add carry of the\n * first 32bit addition is not carried over to the last 32bit.\n *\n * [Reference implementation](http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c)\n */\nexport class Xoroshiro128plus {\n /**\n * @param {number} seed Unsigned 32 bit number\n */\n constructor (seed) {\n this.seed = seed\n // This is a variant of Xoroshiro128plus to fill the initial state\n const xorshift32 = new Xorshift32(seed)\n this.state = new Uint32Array(4)\n for (let i = 0; i < 4; i++) {\n this.state[i] = xorshift32.next() * binary.BITS32\n }\n this._fresh = true\n }\n\n /**\n * @return {number} Float/Double in [0,1)\n */\n next () {\n const state = this.state\n if (this._fresh) {\n this._fresh = false\n return ((state[0] + state[2]) >>> 0) / (binary.BITS32 + 1)\n } else {\n this._fresh = true\n const s0 = state[0]\n const s1 = state[1]\n const s2 = state[2] ^ s0\n const s3 = state[3] ^ s1\n // function js_rotl (x, k) {\n // k = k - 32\n // const x1 = x[0]\n // const x2 = x[1]\n // x[0] = x2 << k | x1 >>> (32 - k)\n // x[1] = x1 << k | x2 >>> (32 - k)\n // }\n // rotl(s0, 55) // k = 23 = 55 - 32; j = 9 = 32 - 23\n state[0] = (s1 << 23 | s0 >>> 9) ^ s2 ^ (s2 << 14 | s3 >>> 18)\n state[1] = (s0 << 23 | s1 >>> 9) ^ s3 ^ (s3 << 14)\n // rol(s1, 36) // k = 4 = 36 - 32; j = 23 = 32 - 9\n state[2] = s3 << 4 | s2 >>> 28\n state[3] = s2 << 4 | s3 >>> 28\n return (((state[1] + state[3]) >>> 0) / (binary.BITS32 + 1))\n }\n }\n}\n\n/*\n// Reference implementation\n// Source: http://vigna.di.unimi.it/xorshift/xoroshiro128plus.c\n// By David Blackman and Sebastiano Vigna\n// Who published the reference implementation under Public Domain (CC0)\n\n#include <stdint.h>\n#include <stdio.h>\n\nuint64_t s[2];\n\nstatic inline uint64_t rotl(const uint64_t x, int k) {\n return (x << k) | (x >> (64 - k));\n}\n\nuint64_t next(void) {\n const uint64_t s0 = s[0];\n uint64_t s1 = s[1];\n s1 ^= s0;\n s[0] = rotl(s0, 55) ^ s1 ^ (s1 << 14); // a, b\n s[1] = rotl(s1, 36); // c\n return (s[0] + s[1]) & 0xFFFFFFFF;\n}\n\nint main(void)\n{\n int i;\n s[0] = 1111 | (1337ul << 32);\n s[1] = 1234 | (9999ul << 32);\n\n printf(\"1000 outputs of genrand_int31()\\n\");\n for (i=0; i<100; i++) {\n printf(\"%10lu \", i);\n printf(\"%10lu \", next());\n printf(\"- %10lu \", s[0] >> 32);\n printf(\"%10lu \", (s[0] << 32) >> 32);\n printf(\"%10lu \", s[1] >> 32);\n printf(\"%10lu \", (s[1] << 32) >> 32);\n printf(\"\\n\");\n // if (i%5==4) printf(\"\\n\");\n }\n return 0;\n}\n*/\n","/**\n * Fast Pseudo Random Number Generators.\n *\n * Given a seed a PRNG generates a sequence of numbers that cannot be reasonably predicted.\n * Two PRNGs must generate the same random sequence of numbers if given the same seed.\n *\n * @module prng\n */\n\nimport * as binary from './binary.js'\nimport { fromCharCode, fromCodePoint } from './string.js'\nimport * as math from './math.js'\nimport { Xoroshiro128plus } from './prng/Xoroshiro128plus.js'\nimport * as buffer from './buffer.js'\n\n/**\n * Description of the function\n * @callback generatorNext\n * @return {number} A random float in the cange of [0,1)\n */\n\n/**\n * A random type generator.\n *\n * @typedef {Object} PRNG\n * @property {generatorNext} next Generate new number\n */\n\nexport const DefaultPRNG = Xoroshiro128plus\n\n/**\n * Create a Xoroshiro128plus Pseudo-Random-Number-Generator.\n * This is the fastest full-period generator passing BigCrush without systematic failures.\n * But there are more PRNGs available in ./PRNG/.\n *\n * @param {number} seed A positive 32bit integer. Do not use negative numbers.\n * @return {PRNG}\n */\nexport const create = seed => new DefaultPRNG(seed)\n\n/**\n * Generates a single random bool.\n *\n * @param {PRNG} gen A random number generator.\n * @return {Boolean} A random boolean\n */\nexport const bool = gen => (gen.next() >= 0.5)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const int53 = (gen, min, max) => math.floor(gen.next() * (max + 1 - min) + min)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const uint53 = (gen, min, max) => math.abs(int53(gen, min, max))\n\n/**\n * Generates a random integer with 32 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const int32 = (gen, min, max) => math.floor(gen.next() * (max + 1 - min) + min)\n\n/**\n * Generates a random integer with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive).\n * @return {Number} A random integer on [min, max]\n */\nexport const uint32 = (gen, min, max) => int32(gen, min, max) >>> 0\n\n/**\n * @deprecated\n * Optimized version of prng.int32. It has the same precision as prng.int32, but should be preferred when\n * openaring on smaller ranges.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Number} min The lower bound of the allowed return values (inclusive).\n * @param {Number} max The upper bound of the allowed return values (inclusive). The max inclusive number is `binary.BITS31-1`\n * @return {Number} A random integer on [min, max]\n */\nexport const int31 = (gen, min, max) => int32(gen, min, max)\n\n/**\n * Generates a random real on [0, 1) with 53 bit resolution.\n *\n * @param {PRNG} gen A random number generator.\n * @return {Number} A random real number on [0, 1).\n */\nexport const real53 = gen => gen.next() // (((gen.next() >>> 5) * binary.BIT26) + (gen.next() >>> 6)) / MAX_SAFE_INTEGER\n\n/**\n * Generates a random character from char code 32 - 126. I.e. Characters, Numbers, special characters, and Space:\n *\n * @param {PRNG} gen A random number generator.\n * @return {string}\n *\n * (Space)!\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[/]^_`abcdefghijklmnopqrstuvwxyz{|}~\n */\nexport const char = gen => fromCharCode(int31(gen, 32, 126))\n\n/**\n * @param {PRNG} gen\n * @return {string} A single letter (a-z)\n */\nexport const letter = gen => fromCharCode(int31(gen, 97, 122))\n\n/**\n * @param {PRNG} gen\n * @param {number} [minLen=0]\n * @param {number} [maxLen=20]\n * @return {string} A random word (0-20 characters) without spaces consisting of letters (a-z)\n */\nexport const word = (gen, minLen = 0, maxLen = 20) => {\n const len = int31(gen, minLen, maxLen)\n let str = ''\n for (let i = 0; i < len; i++) {\n str += letter(gen)\n }\n return str\n}\n\n/**\n * TODO: this function produces invalid runes. Does not cover all of utf16!!\n *\n * @param {PRNG} gen\n * @return {string}\n */\nexport const utf16Rune = gen => {\n const codepoint = int31(gen, 0, 256)\n return fromCodePoint(codepoint)\n}\n\n/**\n * @param {PRNG} gen\n * @param {number} [maxlen = 20]\n */\nexport const utf16String = (gen, maxlen = 20) => {\n const len = int31(gen, 0, maxlen)\n let str = ''\n for (let i = 0; i < len; i++) {\n str += utf16Rune(gen)\n }\n return str\n}\n\n/**\n * Returns one element of a given array.\n *\n * @param {PRNG} gen A random number generator.\n * @param {Array<T>} array Non empty Array of possible values.\n * @return {T} One of the values of the supplied Array.\n * @template T\n */\nexport const oneOf = (gen, array) => array[int31(gen, 0, array.length - 1)]\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint8Array}\n */\nexport const uint8Array = (gen, len) => {\n const buf = buffer.createUint8ArrayFromLen(len)\n for (let i = 0; i < buf.length; i++) {\n buf[i] = int32(gen, 0, binary.BITS8)\n }\n return buf\n}\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint16Array}\n */\nexport const uint16Array = (gen, len) => new Uint16Array(uint8Array(gen, len * 2).buffer)\n\n/**\n * @param {PRNG} gen\n * @param {number} len\n * @return {Uint32Array}\n */\nexport const uint32Array = (gen, len) => new Uint32Array(uint8Array(gen, len * 4).buffer)\n"],"names":["binary.BITS32","math.floor","math.abs","fromCharCode","fromCodePoint","buffer.createUint8ArrayFromLen","binary.BITS8"],"mappings":";;;;;;;AAAA;AACA;AACA;AAGA;AACA;AACA;AACA;AACO,MAAM,UAAU,CAAC;AACxB;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA;AACA;AACA,IAAI,IAAI,CAAC,MAAM,GAAG,KAAI;AACtB,GAAG;AACH;AACA;AACA;AACA;AACA;AACA;AACA,EAAE,IAAI,CAAC,GAAG;AACV,IAAI,IAAI,CAAC,GAAG,IAAI,CAAC,OAAM;AACvB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAE;AAChB,IAAI,CAAC,IAAI,CAAC,IAAI,GAAE;AAChB,IAAI,CAAC,IAAI,CAAC,IAAI,EAAC;AACf,IAAI,IAAI,CAAC,MAAM,GAAG,EAAC;AACnB,IAAI,OAAO,CAAC,CAAC,KAAK,CAAC,KAAKA,aAAa,GAAG,CAAC,CAAC;AAC1C,GAAG;AACH;;AClCA;AACA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAM,gBAAgB,CAAC;AAC9B;AACA;AACA;AACA,EAAE,WAAW,CAAC,CAAC,IAAI,EAAE;AACrB,IAAI,IAAI,CAAC,IAAI,GAAG,KAAI;AACpB;AACA,IAAI,MAAM,UAA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AE,KAAK,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,EAAC;AACxD;AACA,MAAM,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,GAAE;AACpC,MAAM,KAAK,CAAC,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,KAAK,GAAE;AACpC,MAAM,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,KAAKA,aAAa,GAAG,CAAC,CAAC,CAAC;AAClE,KAAK;AACL,GAAG;AACH,CAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AC9GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,iBAAgB;AAC3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,MAAM,GAAG,IAAI,IAAI,IAAI,WAAW,CAAC,IAAI,EAAC;AACnD;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,IAAI,GAAG,GAAG,KAAK,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,EAAC;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,EAAC;AACtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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C,MAAM,EAAE,CAAC,EAAE,EAAE;AACvC,IAAI,GAAG,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,GAAG,EAAE,CAAC,EAAEC,YAAY,EAAC;AACxC,GAAG;AACH,EAAE,OAAO,GAAG;AACZ,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM,EAAC;AACzF;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,WAAW,GAAG,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,WAAW,CAAC,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/prng.cjs
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
require('./binary-ac8e39e2.cjs');
|
|
6
6
|
require('./string-ad04f734.cjs');
|
|
7
7
|
require('./math-08e068f9.cjs');
|
|
8
|
-
var prng = require('./prng-
|
|
8
|
+
var prng = require('./prng-bbec83e2.cjs');
|
|
9
9
|
require('./buffer-c98f67d5.cjs');
|
|
10
10
|
require('./environment-60b83194.cjs');
|
|
11
11
|
require('./map-28a001c9.cjs');
|
package/dist/prng.d.ts
CHANGED
package/dist/random.cjs
CHANGED
|
@@ -3,13 +3,18 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var math = require('./math-08e068f9.cjs');
|
|
6
|
+
var binary = require('./binary-ac8e39e2.cjs');
|
|
6
7
|
var isomorphic_js = require('isomorphic.js');
|
|
7
8
|
|
|
8
9
|
const rand = Math.random;
|
|
9
10
|
|
|
10
|
-
/* istanbul ignore next */
|
|
11
11
|
const uint32 = () => new Uint32Array(isomorphic_js.cryptoRandomBuffer(4))[0];
|
|
12
12
|
|
|
13
|
+
const uint53 = () => {
|
|
14
|
+
const arr = new Uint32Array(isomorphic_js.cryptoRandomBuffer(8));
|
|
15
|
+
return (arr[0] & binary.BITS21) * (binary.BITS32 + 1) + (arr[1] >>> 0)
|
|
16
|
+
};
|
|
17
|
+
|
|
13
18
|
/**
|
|
14
19
|
* @template T
|
|
15
20
|
* @param {Array<T>} arr
|
|
@@ -26,5 +31,6 @@ const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c
|
|
|
26
31
|
exports.oneOf = oneOf;
|
|
27
32
|
exports.rand = rand;
|
|
28
33
|
exports.uint32 = uint32;
|
|
34
|
+
exports.uint53 = uint53;
|
|
29
35
|
exports.uuidv4 = uuidv4;
|
|
30
36
|
//# sourceMappingURL=random.cjs.map
|
package/dist/random.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.cjs","sources":["../random.js"],"sourcesContent":["\n/**\n * Isomorphic module for true random numbers / buffers / uuids.\n *\n * Attention: falls back to Math.random if the browser does not support crypto.\n *\n * @module random\n */\n\nimport * as math from './math.js'\nimport { cryptoRandomBuffer } from './isomorphic.js'\n\nexport const rand = Math.random\n\
|
|
1
|
+
{"version":3,"file":"random.cjs","sources":["../random.js"],"sourcesContent":["\n/**\n * Isomorphic module for true random numbers / buffers / uuids.\n *\n * Attention: falls back to Math.random if the browser does not support crypto.\n *\n * @module random\n */\n\nimport * as math from './math.js'\nimport * as binary from './binary.js'\nimport { cryptoRandomBuffer } from './isomorphic.js'\n\nexport const rand = Math.random\n\nexport const uint32 = () => new Uint32Array(cryptoRandomBuffer(4))[0]\n\nexport const uint53 = () => {\n const arr = new Uint32Array(cryptoRandomBuffer(8))\n return (arr[0] & binary.BITS21) * (binary.BITS32 + 1) + (arr[1] >>> 0)\n}\n\n/**\n * @template T\n * @param {Array<T>} arr\n * @return {T}\n */\nexport const oneOf = arr => arr[math.floor(rand() * arr.length)]\n\n// @ts-ignore\nconst uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11\nexport const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>\n (c ^ uint32() & 15 >> c / 4).toString(16)\n)\n"],"names":["cryptoRandomBuffer","binary.BITS21","binary.BITS32","math.floor"],"mappings":";;;;;;;;AAaY,MAAC,IAAI,GAAG,IAAI,CAAC,OAAM;AAC/B;AACY,MAAC,MAAM,GAAG,MAAM,IAAI,WAAW,CAACA,gCAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;AACrE;AACY,MAAC,MAAM,GAAG,MAAM;AAC5B,EAAE,MAAM,GAAG,GAAG,IAAI,WAAW,CAACA,gCAAkB,CAAC,CAAC,CAAC,EAAC;AACpD,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAGC,aAAa,KAAKC,aAAa,GAAG,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;AACxE,EAAC;AACD;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,GAAG,IAAI,GAAG,CAACC,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,EAAC;AAChE;AACA;AACA,MAAM,cAAc,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,GAAG,GAAG,CAAC,KAAI;AAC7C,MAAC,MAAM,GAAG,MAAM,cAAc,CAAC,OAAO,CAAC,QAAQ,2BAA2B,CAAC;AACvF,EAAE,CAAC,CAAC,GAAG,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,QAAQ,CAAC,EAAE,CAAC;AAC3C;;;;;;;;"}
|
package/dist/random.d.ts
CHANGED
package/dist/random.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../random.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../random.js"],"names":[],"mappings":"AAaA,gCAA+B;AAExB,iCAA8D;AAE9D,iCAGN;AAOM,sCAAyD;AAIzD,8BAEN"}
|
package/dist/random.test.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"random.test.d.ts","sourceRoot":"","sources":["../random.test.js"],"names":[],"mappings":"AASO,+BAFI,EAAE,QAAQ,QA0BpB;AAKM,+BAFI,EAAE,QAAQ,QAIpB;AAKM,uCAFI,EAAE,QAAQ,QAkBpB"}
|
|
1
|
+
{"version":3,"file":"random.test.d.ts","sourceRoot":"","sources":["../random.test.js"],"names":[],"mappings":"AASO,+BAFI,EAAE,QAAQ,QA0BpB;AAKM,+BAFI,EAAE,QAAQ,QAyBpB;AAKM,+BAFI,EAAE,QAAQ,QAIpB;AAKM,uCAFI,EAAE,QAAQ,QAkBpB"}
|
package/dist/test.cjs
CHANGED
|
@@ -1548,15 +1548,6 @@ const simpleDiffStringWithCursor = (a, b, cursor) => {
|
|
|
1548
1548
|
}
|
|
1549
1549
|
};
|
|
1550
1550
|
|
|
1551
|
-
/* istanbul ignore next */
|
|
1552
|
-
const uint32$1 = () => new Uint32Array(isomorphic_js.cryptoRandomBuffer(4))[0];
|
|
1553
|
-
|
|
1554
|
-
// @ts-ignore
|
|
1555
|
-
const uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
|
|
1556
|
-
const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>
|
|
1557
|
-
(c ^ uint32$1() & 15 >> c / 4).toString(16)
|
|
1558
|
-
);
|
|
1559
|
-
|
|
1560
1551
|
/* eslint-env browser */
|
|
1561
1552
|
|
|
1562
1553
|
/**
|
|
@@ -1717,6 +1708,19 @@ var binary$1 = /*#__PURE__*/Object.freeze({
|
|
|
1717
1708
|
BITS32: BITS32
|
|
1718
1709
|
});
|
|
1719
1710
|
|
|
1711
|
+
const uint32$1 = () => new Uint32Array(isomorphic_js.cryptoRandomBuffer(4))[0];
|
|
1712
|
+
|
|
1713
|
+
const uint53$1 = () => {
|
|
1714
|
+
const arr = new Uint32Array(isomorphic_js.cryptoRandomBuffer(8));
|
|
1715
|
+
return (arr[0] & BITS21) * (BITS32 + 1) + (arr[1] >>> 0)
|
|
1716
|
+
};
|
|
1717
|
+
|
|
1718
|
+
// @ts-ignore
|
|
1719
|
+
const uuidv4Template = [1e7] + -1e3 + -4e3 + -8e3 + -1e11;
|
|
1720
|
+
const uuidv4 = () => uuidv4Template.replace(/[018]/g, /** @param {number} c */ c =>
|
|
1721
|
+
(c ^ uint32$1() & 15 >> c / 4).toString(16)
|
|
1722
|
+
);
|
|
1723
|
+
|
|
1720
1724
|
/**
|
|
1721
1725
|
* @module prng
|
|
1722
1726
|
*/
|
|
@@ -3389,7 +3393,7 @@ const decodeAny = buf => readAny(createDecoder(buf));
|
|
|
3389
3393
|
/**
|
|
3390
3394
|
* Description of the function
|
|
3391
3395
|
* @callback generatorNext
|
|
3392
|
-
* @return {number} A
|
|
3396
|
+
* @return {number} A random float in the cange of [0,1)
|
|
3393
3397
|
*/
|
|
3394
3398
|
|
|
3395
3399
|
/**
|
|
@@ -6053,6 +6057,34 @@ const testUint32 = tc => {
|
|
|
6053
6057
|
assert(((smallest & BITS32) >>> 0) === smallest, 'Smallest number is 32 bits long.');
|
|
6054
6058
|
};
|
|
6055
6059
|
|
|
6060
|
+
/**
|
|
6061
|
+
* @param {t.TestCase} tc
|
|
6062
|
+
*/
|
|
6063
|
+
const testUint53 = tc => {
|
|
6064
|
+
const iterations = 10000;
|
|
6065
|
+
let largest = 0;
|
|
6066
|
+
let smallest = MAX_SAFE_INTEGER;
|
|
6067
|
+
let newNum = 0;
|
|
6068
|
+
let lenSum = 0;
|
|
6069
|
+
let ones = 0;
|
|
6070
|
+
for (let i = 0; i < iterations; i++) {
|
|
6071
|
+
newNum = uint53$1();
|
|
6072
|
+
lenSum += newNum.toString().length;
|
|
6073
|
+
ones += newNum.toString(2).split('').filter(x => x === '1').length;
|
|
6074
|
+
if (newNum > largest) {
|
|
6075
|
+
largest = newNum;
|
|
6076
|
+
}
|
|
6077
|
+
if (newNum < smallest) {
|
|
6078
|
+
smallest = newNum;
|
|
6079
|
+
}
|
|
6080
|
+
}
|
|
6081
|
+
info(`Largest number generated is ${largest}`);
|
|
6082
|
+
info(`Smallest number generated is ${smallest}`);
|
|
6083
|
+
info(`Average decimal length of number is ${lenSum / iterations}`);
|
|
6084
|
+
info(`Average number of 1s in number is ${ones / iterations} (expecting ~26.5)`);
|
|
6085
|
+
assert(largest > MAX_SAFE_INTEGER * 0.9);
|
|
6086
|
+
};
|
|
6087
|
+
|
|
6056
6088
|
/**
|
|
6057
6089
|
* @param {t.TestCase} tc
|
|
6058
6090
|
*/
|
|
@@ -6084,6 +6116,7 @@ const testUuidv4Overlaps = tc => {
|
|
|
6084
6116
|
var random = /*#__PURE__*/Object.freeze({
|
|
6085
6117
|
__proto__: null,
|
|
6086
6118
|
testUint32: testUint32,
|
|
6119
|
+
testUint53: testUint53,
|
|
6087
6120
|
testUuidv4: testUuidv4,
|
|
6088
6121
|
testUuidv4Overlaps: testUuidv4Overlaps
|
|
6089
6122
|
});
|