lib0 0.2.48 → 0.2.51

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.
Files changed (41) hide show
  1. package/README.md +4 -3
  2. package/broadcastchannel.d.ts +4 -4
  3. package/broadcastchannel.d.ts.map +1 -1
  4. package/broadcastchannel.js +7 -6
  5. package/decoding.js +2 -2
  6. package/dist/{broadcastchannel-f22849e9.cjs → broadcastchannel-1e999014.cjs} +9 -8
  7. package/dist/broadcastchannel-1e999014.cjs.map +1 -0
  8. package/dist/broadcastchannel.cjs +2 -2
  9. package/dist/broadcastchannel.d.ts +4 -4
  10. package/dist/broadcastchannel.d.ts.map +1 -1
  11. package/dist/{buffer-f5603fd0.cjs → buffer-c98f67d5.cjs} +3 -3
  12. package/dist/{buffer-f5603fd0.cjs.map → buffer-c98f67d5.cjs.map} +1 -1
  13. package/dist/buffer.cjs +1 -1
  14. package/dist/decoding.cjs +1 -1
  15. package/dist/encoding.cjs +1 -1
  16. package/dist/index.cjs +3 -3
  17. package/dist/{prng-69dc1664.cjs → prng-bbec83e2.cjs} +3 -3
  18. package/dist/prng-bbec83e2.cjs.map +1 -0
  19. package/dist/prng.cjs +2 -2
  20. package/dist/prng.d.ts +1 -1
  21. package/dist/random.cjs +7 -1
  22. package/dist/random.cjs.map +1 -1
  23. package/dist/random.d.ts +1 -0
  24. package/dist/random.d.ts.map +1 -1
  25. package/dist/random.test.d.ts +1 -0
  26. package/dist/random.test.d.ts.map +1 -1
  27. package/dist/test.cjs +46 -13
  28. package/dist/test.cjs.map +1 -1
  29. package/dist/test.js +72 -39
  30. package/dist/test.js.map +1 -1
  31. package/dist/testing.cjs +2 -2
  32. package/package.json +1 -1
  33. package/prng.d.ts +1 -1
  34. package/prng.js +1 -1
  35. package/random.d.ts +1 -0
  36. package/random.d.ts.map +1 -1
  37. package/random.js +6 -1
  38. package/random.test.d.ts +1 -0
  39. package/random.test.d.ts.map +1 -1
  40. package/dist/broadcastchannel-f22849e9.cjs.map +0 -1
  41. package/dist/prng-69dc1664.cjs.map +0 -1
package/dist/decoding.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var encoding = require('./buffer-f5603fd0.cjs');
5
+ var encoding = require('./buffer-c98f67d5.cjs');
6
6
  require('./binary-ac8e39e2.cjs');
7
7
  require('./math-08e068f9.cjs');
8
8
  require('./string-ad04f734.cjs');
package/dist/encoding.cjs CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var encoding = require('./buffer-f5603fd0.cjs');
5
+ var encoding = require('./buffer-c98f67d5.cjs');
6
6
  require('./math-08e068f9.cjs');
7
7
  require('./number-e62129bc.cjs');
8
8
  require('./binary-ac8e39e2.cjs');
package/dist/index.cjs CHANGED
@@ -4,8 +4,8 @@ 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-f22849e9.cjs');
8
- var encoding = require('./buffer-f5603fd0.cjs');
7
+ var broadcastchannel = require('./broadcastchannel-1e999014.cjs');
8
+ var encoding = require('./buffer-c98f67d5.cjs');
9
9
  var conditions = require('./conditions-fb475c70.cjs');
10
10
  var diff = require('./diff-2593547b.cjs');
11
11
  var dom = require('./dom-58958c04.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-69dc1664.cjs');
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');
@@ -3,7 +3,7 @@
3
3
  var binary = require('./binary-ac8e39e2.cjs');
4
4
  var string = require('./string-ad04f734.cjs');
5
5
  var math = require('./math-08e068f9.cjs');
6
- var encoding = require('./buffer-f5603fd0.cjs');
6
+ var encoding = require('./buffer-c98f67d5.cjs');
7
7
 
8
8
  /**
9
9
  * @module prng
@@ -160,7 +160,7 @@ int main(void)
160
160
  /**
161
161
  * Description of the function
162
162
  * @callback generatorNext
163
- * @return {number} A 32bit integer
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-69dc1664.cjs.map
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,UAAU,GAAG,IAAI,UAAU,CAAC,IAAI,EAAC;AAC3C,IAAI,IAAI,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,CAAC,EAAC;AACnC,IAAI,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE;AAChC,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AAC,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;AACY,MAAC,MAAM,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,KAAKC,QAAQ,CAAC,KAAK,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EAAC;AACvE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACY,MAAC,KAAK,GAAG,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Y,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,8 +5,8 @@ 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-69dc1664.cjs');
9
- require('./buffer-f5603fd0.cjs');
8
+ var prng = require('./prng-bbec83e2.cjs');
9
+ require('./buffer-c98f67d5.cjs');
10
10
  require('./environment-60b83194.cjs');
11
11
  require('./map-28a001c9.cjs');
12
12
  require('./conditions-fb475c70.cjs');
package/dist/prng.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Description of the function
3
3
  * @callback generatorNext
4
- * @return {number} A 32bit integer
4
+ * @return {number} A random float in the cange of [0,1)
5
5
  */
6
6
  /**
7
7
  * A random type generator.
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
@@ -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\n/* istanbul ignore next */\nexport const uint32 = () => new Uint32Array(cryptoRandomBuffer(4))[0]\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","math.floor"],"mappings":";;;;;;;AAYY,MAAC,IAAI,GAAG,IAAI,CAAC,OAAM;AAC/B;AACA;AACY,MAAC,MAAM,GAAG,MAAM,IAAI,WAAW,CAACA,gCAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAC;AACrE;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;;;;;;;"}
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
@@ -1,5 +1,6 @@
1
1
  export const rand: () => number;
2
2
  export function uint32(): number;
3
+ export function uint53(): number;
3
4
  export function oneOf<T>(arr: T[]): T;
4
5
  export function uuidv4(): any;
5
6
  //# sourceMappingURL=random.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../random.js"],"names":[],"mappings":"AAYA,gCAA+B;AAGxB,iCAA8D;AAO9D,sCAAyD;AAIzD,8BAEN"}
1
+ {"version":3,"file":"random.d.ts","sourceRoot":"","sources":["../random.js"],"names":[],"mappings":"AAaA,gCAA+B;AAExB,iCAA8D;AAE9D,iCAGN;AAOM,sCAAyD;AAIzD,8BAEN"}
@@ -1,4 +1,5 @@
1
1
  export function testUint32(tc: t.TestCase): void;
2
+ export function testUint53(tc: t.TestCase): void;
2
3
  export function testUuidv4(tc: t.TestCase): void;
3
4
  export function testUuidv4Overlaps(tc: t.TestCase): void;
4
5
  import * as t from "./testing.js";
@@ -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
  */
@@ -2901,7 +2905,7 @@ const readVarUint = decoder => {
2901
2905
  return num >>> 0 // return unsigned number!
2902
2906
  }
2903
2907
  /* istanbul ignore if */
2904
- if (len > 35) {
2908
+ if (len > 53) {
2905
2909
  throw new Error('Integer out of range!')
2906
2910
  }
2907
2911
  }
@@ -2935,7 +2939,7 @@ const readVarInt = decoder => {
2935
2939
  return sign * (num >>> 0)
2936
2940
  }
2937
2941
  /* istanbul ignore if */
2938
- if (len > 41) {
2942
+ if (len > 53) {
2939
2943
  throw new Error('Integer out of range!')
2940
2944
  }
2941
2945
  }
@@ -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 32bit integer
3396
+ * @return {number} A random float in the cange of [0,1)
3393
3397
  */
3394
3398
 
3395
3399
  /**
@@ -4580,8 +4584,8 @@ const testStringDecodingPerformance = () => {
4580
4584
  }
4581
4585
  });
4582
4586
  });
4587
+ assert(durationConcatElements < durationConcatElementsNative * 1.3, '1.3x faster. We expect that the native approach is slower. If this fails, our expectantion is not met in your javascript environment. Please report this issue.');
4583
4588
  assert(durationConcatElements < durationSingleElements, 'We expect that the second approach is faster. If this fails, our expectantion is not met in your javascript environment. Please report this issue.');
4584
- assert(durationConcatElements < durationConcatElementsNative * 1.3, 'We expect that the native approach is slower. If this fails, our expectantion is not met in your javascript environment. Please report this issue.');
4585
4589
  };
4586
4590
 
4587
4591
  /**
@@ -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
  });