jspsych 7.2.0 → 7.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,5 +1,3 @@
1
- import require$$0 from 'crypto';
2
-
3
1
  /*! *****************************************************************************
4
2
  Copyright (c) Microsoft Corporation.
5
3
 
@@ -69,7 +67,7 @@ var autoBind = (self, {include, exclude} = {}) => {
69
67
  return self;
70
68
  };
71
69
 
72
- var version = "7.2.0";
70
+ var version = "7.2.1";
73
71
 
74
72
  class MigrationError extends Error {
75
73
  constructor(message = "The global `jsPsych` variable is no longer available in jsPsych v7.") {
@@ -1626,7 +1624,7 @@ var randomWords$1 = words;
1626
1624
  // Export the word list as it is often useful
1627
1625
  words.wordList = wordList;
1628
1626
 
1629
- var alea$1 = {exports: {}};
1627
+ var alea = {exports: {}};
1630
1628
 
1631
1629
  (function (module) {
1632
1630
  // A port of an algorithm by Johannes Baagøe <baagoe@baagoe.com>, 2010
@@ -1741,852 +1739,9 @@ if (module && module.exports) {
1741
1739
  module, // present in node.js
1742
1740
  (typeof undefined) == 'function' // present with an AMD loader
1743
1741
  );
1744
- }(alea$1));
1745
-
1746
- var xor128$1 = {exports: {}};
1747
-
1748
- (function (module) {
1749
- // A Javascript implementaion of the "xor128" prng algorithm by
1750
- // George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper
1751
-
1752
- (function(global, module, define) {
1753
-
1754
- function XorGen(seed) {
1755
- var me = this, strseed = '';
1756
-
1757
- me.x = 0;
1758
- me.y = 0;
1759
- me.z = 0;
1760
- me.w = 0;
1761
-
1762
- // Set up generator function.
1763
- me.next = function() {
1764
- var t = me.x ^ (me.x << 11);
1765
- me.x = me.y;
1766
- me.y = me.z;
1767
- me.z = me.w;
1768
- return me.w ^= (me.w >>> 19) ^ t ^ (t >>> 8);
1769
- };
1770
-
1771
- if (seed === (seed | 0)) {
1772
- // Integer seed.
1773
- me.x = seed;
1774
- } else {
1775
- // String seed.
1776
- strseed += seed;
1777
- }
1778
-
1779
- // Mix in string seed, then discard an initial batch of 64 values.
1780
- for (var k = 0; k < strseed.length + 64; k++) {
1781
- me.x ^= strseed.charCodeAt(k) | 0;
1782
- me.next();
1783
- }
1784
- }
1785
-
1786
- function copy(f, t) {
1787
- t.x = f.x;
1788
- t.y = f.y;
1789
- t.z = f.z;
1790
- t.w = f.w;
1791
- return t;
1792
- }
1793
-
1794
- function impl(seed, opts) {
1795
- var xg = new XorGen(seed),
1796
- state = opts && opts.state,
1797
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
1798
- prng.double = function() {
1799
- do {
1800
- var top = xg.next() >>> 11,
1801
- bot = (xg.next() >>> 0) / 0x100000000,
1802
- result = (top + bot) / (1 << 21);
1803
- } while (result === 0);
1804
- return result;
1805
- };
1806
- prng.int32 = xg.next;
1807
- prng.quick = prng;
1808
- if (state) {
1809
- if (typeof(state) == 'object') copy(state, xg);
1810
- prng.state = function() { return copy(xg, {}); };
1811
- }
1812
- return prng;
1813
- }
1814
-
1815
- if (module && module.exports) {
1816
- module.exports = impl;
1817
- } else if (define && define.amd) {
1818
- define(function() { return impl; });
1819
- } else {
1820
- this.xor128 = impl;
1821
- }
1822
-
1823
- })(
1824
- commonjsGlobal,
1825
- module, // present in node.js
1826
- (typeof undefined) == 'function' // present with an AMD loader
1827
- );
1828
- }(xor128$1));
1829
-
1830
- var xorwow$1 = {exports: {}};
1831
-
1832
- (function (module) {
1833
- // A Javascript implementaion of the "xorwow" prng algorithm by
1834
- // George Marsaglia. See http://www.jstatsoft.org/v08/i14/paper
1835
-
1836
- (function(global, module, define) {
1837
-
1838
- function XorGen(seed) {
1839
- var me = this, strseed = '';
1840
-
1841
- // Set up generator function.
1842
- me.next = function() {
1843
- var t = (me.x ^ (me.x >>> 2));
1844
- me.x = me.y; me.y = me.z; me.z = me.w; me.w = me.v;
1845
- return (me.d = (me.d + 362437 | 0)) +
1846
- (me.v = (me.v ^ (me.v << 4)) ^ (t ^ (t << 1))) | 0;
1847
- };
1848
-
1849
- me.x = 0;
1850
- me.y = 0;
1851
- me.z = 0;
1852
- me.w = 0;
1853
- me.v = 0;
1854
-
1855
- if (seed === (seed | 0)) {
1856
- // Integer seed.
1857
- me.x = seed;
1858
- } else {
1859
- // String seed.
1860
- strseed += seed;
1861
- }
1862
-
1863
- // Mix in string seed, then discard an initial batch of 64 values.
1864
- for (var k = 0; k < strseed.length + 64; k++) {
1865
- me.x ^= strseed.charCodeAt(k) | 0;
1866
- if (k == strseed.length) {
1867
- me.d = me.x << 10 ^ me.x >>> 4;
1868
- }
1869
- me.next();
1870
- }
1871
- }
1872
-
1873
- function copy(f, t) {
1874
- t.x = f.x;
1875
- t.y = f.y;
1876
- t.z = f.z;
1877
- t.w = f.w;
1878
- t.v = f.v;
1879
- t.d = f.d;
1880
- return t;
1881
- }
1882
-
1883
- function impl(seed, opts) {
1884
- var xg = new XorGen(seed),
1885
- state = opts && opts.state,
1886
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
1887
- prng.double = function() {
1888
- do {
1889
- var top = xg.next() >>> 11,
1890
- bot = (xg.next() >>> 0) / 0x100000000,
1891
- result = (top + bot) / (1 << 21);
1892
- } while (result === 0);
1893
- return result;
1894
- };
1895
- prng.int32 = xg.next;
1896
- prng.quick = prng;
1897
- if (state) {
1898
- if (typeof(state) == 'object') copy(state, xg);
1899
- prng.state = function() { return copy(xg, {}); };
1900
- }
1901
- return prng;
1902
- }
1903
-
1904
- if (module && module.exports) {
1905
- module.exports = impl;
1906
- } else if (define && define.amd) {
1907
- define(function() { return impl; });
1908
- } else {
1909
- this.xorwow = impl;
1910
- }
1911
-
1912
- })(
1913
- commonjsGlobal,
1914
- module, // present in node.js
1915
- (typeof undefined) == 'function' // present with an AMD loader
1916
- );
1917
- }(xorwow$1));
1918
-
1919
- var xorshift7$1 = {exports: {}};
1920
-
1921
- (function (module) {
1922
- // A Javascript implementaion of the "xorshift7" algorithm by
1923
- // François Panneton and Pierre L'ecuyer:
1924
- // "On the Xorgshift Random Number Generators"
1925
- // http://saluc.engr.uconn.edu/refs/crypto/rng/panneton05onthexorshift.pdf
1926
-
1927
- (function(global, module, define) {
1928
-
1929
- function XorGen(seed) {
1930
- var me = this;
1931
-
1932
- // Set up generator function.
1933
- me.next = function() {
1934
- // Update xor generator.
1935
- var X = me.x, i = me.i, t, v;
1936
- t = X[i]; t ^= (t >>> 7); v = t ^ (t << 24);
1937
- t = X[(i + 1) & 7]; v ^= t ^ (t >>> 10);
1938
- t = X[(i + 3) & 7]; v ^= t ^ (t >>> 3);
1939
- t = X[(i + 4) & 7]; v ^= t ^ (t << 7);
1940
- t = X[(i + 7) & 7]; t = t ^ (t << 13); v ^= t ^ (t << 9);
1941
- X[i] = v;
1942
- me.i = (i + 1) & 7;
1943
- return v;
1944
- };
1945
-
1946
- function init(me, seed) {
1947
- var j, X = [];
1948
-
1949
- if (seed === (seed | 0)) {
1950
- // Seed state array using a 32-bit integer.
1951
- X[0] = seed;
1952
- } else {
1953
- // Seed state using a string.
1954
- seed = '' + seed;
1955
- for (j = 0; j < seed.length; ++j) {
1956
- X[j & 7] = (X[j & 7] << 15) ^
1957
- (seed.charCodeAt(j) + X[(j + 1) & 7] << 13);
1958
- }
1959
- }
1960
- // Enforce an array length of 8, not all zeroes.
1961
- while (X.length < 8) X.push(0);
1962
- for (j = 0; j < 8 && X[j] === 0; ++j);
1963
- if (j == 8) X[7] = -1;
1964
-
1965
- me.x = X;
1966
- me.i = 0;
1967
-
1968
- // Discard an initial 256 values.
1969
- for (j = 256; j > 0; --j) {
1970
- me.next();
1971
- }
1972
- }
1973
-
1974
- init(me, seed);
1975
- }
1976
-
1977
- function copy(f, t) {
1978
- t.x = f.x.slice();
1979
- t.i = f.i;
1980
- return t;
1981
- }
1982
-
1983
- function impl(seed, opts) {
1984
- if (seed == null) seed = +(new Date);
1985
- var xg = new XorGen(seed),
1986
- state = opts && opts.state,
1987
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
1988
- prng.double = function() {
1989
- do {
1990
- var top = xg.next() >>> 11,
1991
- bot = (xg.next() >>> 0) / 0x100000000,
1992
- result = (top + bot) / (1 << 21);
1993
- } while (result === 0);
1994
- return result;
1995
- };
1996
- prng.int32 = xg.next;
1997
- prng.quick = prng;
1998
- if (state) {
1999
- if (state.x) copy(state, xg);
2000
- prng.state = function() { return copy(xg, {}); };
2001
- }
2002
- return prng;
2003
- }
2004
-
2005
- if (module && module.exports) {
2006
- module.exports = impl;
2007
- } else if (define && define.amd) {
2008
- define(function() { return impl; });
2009
- } else {
2010
- this.xorshift7 = impl;
2011
- }
2012
-
2013
- })(
2014
- commonjsGlobal,
2015
- module, // present in node.js
2016
- (typeof undefined) == 'function' // present with an AMD loader
2017
- );
2018
- }(xorshift7$1));
2019
-
2020
- var xor4096$1 = {exports: {}};
2021
-
2022
- (function (module) {
2023
- // A Javascript implementaion of Richard Brent's Xorgens xor4096 algorithm.
2024
- //
2025
- // This fast non-cryptographic random number generator is designed for
2026
- // use in Monte-Carlo algorithms. It combines a long-period xorshift
2027
- // generator with a Weyl generator, and it passes all common batteries
2028
- // of stasticial tests for randomness while consuming only a few nanoseconds
2029
- // for each prng generated. For background on the generator, see Brent's
2030
- // paper: "Some long-period random number generators using shifts and xors."
2031
- // http://arxiv.org/pdf/1004.3115v1.pdf
2032
- //
2033
- // Usage:
2034
- //
2035
- // var xor4096 = require('xor4096');
2036
- // random = xor4096(1); // Seed with int32 or string.
2037
- // assert.equal(random(), 0.1520436450538547); // (0, 1) range, 53 bits.
2038
- // assert.equal(random.int32(), 1806534897); // signed int32, 32 bits.
2039
- //
2040
- // For nonzero numeric keys, this impelementation provides a sequence
2041
- // identical to that by Brent's xorgens 3 implementaion in C. This
2042
- // implementation also provides for initalizing the generator with
2043
- // string seeds, or for saving and restoring the state of the generator.
2044
- //
2045
- // On Chrome, this prng benchmarks about 2.1 times slower than
2046
- // Javascript's built-in Math.random().
2047
-
2048
- (function(global, module, define) {
2049
-
2050
- function XorGen(seed) {
2051
- var me = this;
2052
-
2053
- // Set up generator function.
2054
- me.next = function() {
2055
- var w = me.w,
2056
- X = me.X, i = me.i, t, v;
2057
- // Update Weyl generator.
2058
- me.w = w = (w + 0x61c88647) | 0;
2059
- // Update xor generator.
2060
- v = X[(i + 34) & 127];
2061
- t = X[i = ((i + 1) & 127)];
2062
- v ^= v << 13;
2063
- t ^= t << 17;
2064
- v ^= v >>> 15;
2065
- t ^= t >>> 12;
2066
- // Update Xor generator array state.
2067
- v = X[i] = v ^ t;
2068
- me.i = i;
2069
- // Result is the combination.
2070
- return (v + (w ^ (w >>> 16))) | 0;
2071
- };
2072
-
2073
- function init(me, seed) {
2074
- var t, v, i, j, w, X = [], limit = 128;
2075
- if (seed === (seed | 0)) {
2076
- // Numeric seeds initialize v, which is used to generates X.
2077
- v = seed;
2078
- seed = null;
2079
- } else {
2080
- // String seeds are mixed into v and X one character at a time.
2081
- seed = seed + '\0';
2082
- v = 0;
2083
- limit = Math.max(limit, seed.length);
2084
- }
2085
- // Initialize circular array and weyl value.
2086
- for (i = 0, j = -32; j < limit; ++j) {
2087
- // Put the unicode characters into the array, and shuffle them.
2088
- if (seed) v ^= seed.charCodeAt((j + 32) % seed.length);
2089
- // After 32 shuffles, take v as the starting w value.
2090
- if (j === 0) w = v;
2091
- v ^= v << 10;
2092
- v ^= v >>> 15;
2093
- v ^= v << 4;
2094
- v ^= v >>> 13;
2095
- if (j >= 0) {
2096
- w = (w + 0x61c88647) | 0; // Weyl.
2097
- t = (X[j & 127] ^= (v + w)); // Combine xor and weyl to init array.
2098
- i = (0 == t) ? i + 1 : 0; // Count zeroes.
2099
- }
2100
- }
2101
- // We have detected all zeroes; make the key nonzero.
2102
- if (i >= 128) {
2103
- X[(seed && seed.length || 0) & 127] = -1;
2104
- }
2105
- // Run the generator 512 times to further mix the state before using it.
2106
- // Factoring this as a function slows the main generator, so it is just
2107
- // unrolled here. The weyl generator is not advanced while warming up.
2108
- i = 127;
2109
- for (j = 4 * 128; j > 0; --j) {
2110
- v = X[(i + 34) & 127];
2111
- t = X[i = ((i + 1) & 127)];
2112
- v ^= v << 13;
2113
- t ^= t << 17;
2114
- v ^= v >>> 15;
2115
- t ^= t >>> 12;
2116
- X[i] = v ^ t;
2117
- }
2118
- // Storing state as object members is faster than using closure variables.
2119
- me.w = w;
2120
- me.X = X;
2121
- me.i = i;
2122
- }
2123
-
2124
- init(me, seed);
2125
- }
2126
-
2127
- function copy(f, t) {
2128
- t.i = f.i;
2129
- t.w = f.w;
2130
- t.X = f.X.slice();
2131
- return t;
2132
- }
2133
- function impl(seed, opts) {
2134
- if (seed == null) seed = +(new Date);
2135
- var xg = new XorGen(seed),
2136
- state = opts && opts.state,
2137
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
2138
- prng.double = function() {
2139
- do {
2140
- var top = xg.next() >>> 11,
2141
- bot = (xg.next() >>> 0) / 0x100000000,
2142
- result = (top + bot) / (1 << 21);
2143
- } while (result === 0);
2144
- return result;
2145
- };
2146
- prng.int32 = xg.next;
2147
- prng.quick = prng;
2148
- if (state) {
2149
- if (state.X) copy(state, xg);
2150
- prng.state = function() { return copy(xg, {}); };
2151
- }
2152
- return prng;
2153
- }
2154
-
2155
- if (module && module.exports) {
2156
- module.exports = impl;
2157
- } else if (define && define.amd) {
2158
- define(function() { return impl; });
2159
- } else {
2160
- this.xor4096 = impl;
2161
- }
2162
-
2163
- })(
2164
- commonjsGlobal, // window object or global
2165
- module, // present in node.js
2166
- (typeof undefined) == 'function' // present with an AMD loader
2167
- );
2168
- }(xor4096$1));
2169
-
2170
- var tychei$1 = {exports: {}};
2171
-
2172
- (function (module) {
2173
- // A Javascript implementaion of the "Tyche-i" prng algorithm by
2174
- // Samuel Neves and Filipe Araujo.
2175
- // See https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf
2176
-
2177
- (function(global, module, define) {
2178
-
2179
- function XorGen(seed) {
2180
- var me = this, strseed = '';
2181
-
2182
- // Set up generator function.
2183
- me.next = function() {
2184
- var b = me.b, c = me.c, d = me.d, a = me.a;
2185
- b = (b << 25) ^ (b >>> 7) ^ c;
2186
- c = (c - d) | 0;
2187
- d = (d << 24) ^ (d >>> 8) ^ a;
2188
- a = (a - b) | 0;
2189
- me.b = b = (b << 20) ^ (b >>> 12) ^ c;
2190
- me.c = c = (c - d) | 0;
2191
- me.d = (d << 16) ^ (c >>> 16) ^ a;
2192
- return me.a = (a - b) | 0;
2193
- };
2194
-
2195
- /* The following is non-inverted tyche, which has better internal
2196
- * bit diffusion, but which is about 25% slower than tyche-i in JS.
2197
- me.next = function() {
2198
- var a = me.a, b = me.b, c = me.c, d = me.d;
2199
- a = (me.a + me.b | 0) >>> 0;
2200
- d = me.d ^ a; d = d << 16 ^ d >>> 16;
2201
- c = me.c + d | 0;
2202
- b = me.b ^ c; b = b << 12 ^ d >>> 20;
2203
- me.a = a = a + b | 0;
2204
- d = d ^ a; me.d = d = d << 8 ^ d >>> 24;
2205
- me.c = c = c + d | 0;
2206
- b = b ^ c;
2207
- return me.b = (b << 7 ^ b >>> 25);
2208
- }
2209
- */
2210
-
2211
- me.a = 0;
2212
- me.b = 0;
2213
- me.c = 2654435769 | 0;
2214
- me.d = 1367130551;
2215
-
2216
- if (seed === Math.floor(seed)) {
2217
- // Integer seed.
2218
- me.a = (seed / 0x100000000) | 0;
2219
- me.b = seed | 0;
2220
- } else {
2221
- // String seed.
2222
- strseed += seed;
2223
- }
2224
-
2225
- // Mix in string seed, then discard an initial batch of 64 values.
2226
- for (var k = 0; k < strseed.length + 20; k++) {
2227
- me.b ^= strseed.charCodeAt(k) | 0;
2228
- me.next();
2229
- }
2230
- }
2231
-
2232
- function copy(f, t) {
2233
- t.a = f.a;
2234
- t.b = f.b;
2235
- t.c = f.c;
2236
- t.d = f.d;
2237
- return t;
2238
- }
2239
- function impl(seed, opts) {
2240
- var xg = new XorGen(seed),
2241
- state = opts && opts.state,
2242
- prng = function() { return (xg.next() >>> 0) / 0x100000000; };
2243
- prng.double = function() {
2244
- do {
2245
- var top = xg.next() >>> 11,
2246
- bot = (xg.next() >>> 0) / 0x100000000,
2247
- result = (top + bot) / (1 << 21);
2248
- } while (result === 0);
2249
- return result;
2250
- };
2251
- prng.int32 = xg.next;
2252
- prng.quick = prng;
2253
- if (state) {
2254
- if (typeof(state) == 'object') copy(state, xg);
2255
- prng.state = function() { return copy(xg, {}); };
2256
- }
2257
- return prng;
2258
- }
2259
-
2260
- if (module && module.exports) {
2261
- module.exports = impl;
2262
- } else if (define && define.amd) {
2263
- define(function() { return impl; });
2264
- } else {
2265
- this.tychei = impl;
2266
- }
2267
-
2268
- })(
2269
- commonjsGlobal,
2270
- module, // present in node.js
2271
- (typeof undefined) == 'function' // present with an AMD loader
2272
- );
2273
- }(tychei$1));
2274
-
2275
- var seedrandom$1 = {exports: {}};
2276
-
2277
- /*
2278
- Copyright 2019 David Bau.
2279
-
2280
- Permission is hereby granted, free of charge, to any person obtaining
2281
- a copy of this software and associated documentation files (the
2282
- "Software"), to deal in the Software without restriction, including
2283
- without limitation the rights to use, copy, modify, merge, publish,
2284
- distribute, sublicense, and/or sell copies of the Software, and to
2285
- permit persons to whom the Software is furnished to do so, subject to
2286
- the following conditions:
2287
-
2288
- The above copyright notice and this permission notice shall be
2289
- included in all copies or substantial portions of the Software.
2290
-
2291
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
2292
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
2293
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
2294
- IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
2295
- CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
2296
- TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
2297
- SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2298
-
2299
- */
2300
-
2301
- (function (module) {
2302
- (function (global, pool, math) {
2303
- //
2304
- // The following constants are related to IEEE 754 limits.
2305
- //
2306
-
2307
- var width = 256, // each RC4 output is 0 <= x < 256
2308
- chunks = 6, // at least six RC4 outputs for each double
2309
- digits = 52, // there are 52 significant digits in a double
2310
- rngname = 'random', // rngname: name for Math.random and Math.seedrandom
2311
- startdenom = math.pow(width, chunks),
2312
- significance = math.pow(2, digits),
2313
- overflow = significance * 2,
2314
- mask = width - 1,
2315
- nodecrypto; // node.js crypto module, initialized at the bottom.
2316
-
2317
- //
2318
- // seedrandom()
2319
- // This is the seedrandom function described above.
2320
- //
2321
- function seedrandom(seed, options, callback) {
2322
- var key = [];
2323
- options = (options == true) ? { entropy: true } : (options || {});
2324
-
2325
- // Flatten the seed string or build one from local entropy if needed.
2326
- var shortseed = mixkey(flatten(
2327
- options.entropy ? [seed, tostring(pool)] :
2328
- (seed == null) ? autoseed() : seed, 3), key);
2329
-
2330
- // Use the seed to initialize an ARC4 generator.
2331
- var arc4 = new ARC4(key);
2332
-
2333
- // This function returns a random double in [0, 1) that contains
2334
- // randomness in every bit of the mantissa of the IEEE 754 value.
2335
- var prng = function() {
2336
- var n = arc4.g(chunks), // Start with a numerator n < 2 ^ 48
2337
- d = startdenom, // and denominator d = 2 ^ 48.
2338
- x = 0; // and no 'extra last byte'.
2339
- while (n < significance) { // Fill up all significant digits by
2340
- n = (n + x) * width; // shifting numerator and
2341
- d *= width; // denominator and generating a
2342
- x = arc4.g(1); // new least-significant-byte.
2343
- }
2344
- while (n >= overflow) { // To avoid rounding up, before adding
2345
- n /= 2; // last byte, shift everything
2346
- d /= 2; // right using integer math until
2347
- x >>>= 1; // we have exactly the desired bits.
2348
- }
2349
- return (n + x) / d; // Form the number within [0, 1).
2350
- };
2351
-
2352
- prng.int32 = function() { return arc4.g(4) | 0; };
2353
- prng.quick = function() { return arc4.g(4) / 0x100000000; };
2354
- prng.double = prng;
2355
-
2356
- // Mix the randomness into accumulated entropy.
2357
- mixkey(tostring(arc4.S), pool);
2358
-
2359
- // Calling convention: what to return as a function of prng, seed, is_math.
2360
- return (options.pass || callback ||
2361
- function(prng, seed, is_math_call, state) {
2362
- if (state) {
2363
- // Load the arc4 state from the given state if it has an S array.
2364
- if (state.S) { copy(state, arc4); }
2365
- // Only provide the .state method if requested via options.state.
2366
- prng.state = function() { return copy(arc4, {}); };
2367
- }
2368
-
2369
- // If called as a method of Math (Math.seedrandom()), mutate
2370
- // Math.random because that is how seedrandom.js has worked since v1.0.
2371
- if (is_math_call) { math[rngname] = prng; return seed; }
2372
-
2373
- // Otherwise, it is a newer calling convention, so return the
2374
- // prng directly.
2375
- else return prng;
2376
- })(
2377
- prng,
2378
- shortseed,
2379
- 'global' in options ? options.global : (this == math),
2380
- options.state);
2381
- }
2382
-
2383
- //
2384
- // ARC4
2385
- //
2386
- // An ARC4 implementation. The constructor takes a key in the form of
2387
- // an array of at most (width) integers that should be 0 <= x < (width).
2388
- //
2389
- // The g(count) method returns a pseudorandom integer that concatenates
2390
- // the next (count) outputs from ARC4. Its return value is a number x
2391
- // that is in the range 0 <= x < (width ^ count).
2392
- //
2393
- function ARC4(key) {
2394
- var t, keylen = key.length,
2395
- me = this, i = 0, j = me.i = me.j = 0, s = me.S = [];
2396
-
2397
- // The empty key [] is treated as [0].
2398
- if (!keylen) { key = [keylen++]; }
2399
-
2400
- // Set up S using the standard key scheduling algorithm.
2401
- while (i < width) {
2402
- s[i] = i++;
2403
- }
2404
- for (i = 0; i < width; i++) {
2405
- s[i] = s[j = mask & (j + key[i % keylen] + (t = s[i]))];
2406
- s[j] = t;
2407
- }
2408
-
2409
- // The "g" method returns the next (count) outputs as one number.
2410
- (me.g = function(count) {
2411
- // Using instance members instead of closure state nearly doubles speed.
2412
- var t, r = 0,
2413
- i = me.i, j = me.j, s = me.S;
2414
- while (count--) {
2415
- t = s[i = mask & (i + 1)];
2416
- r = r * width + s[mask & ((s[i] = s[j = mask & (j + t)]) + (s[j] = t))];
2417
- }
2418
- me.i = i; me.j = j;
2419
- return r;
2420
- // For robust unpredictability, the function call below automatically
2421
- // discards an initial batch of values. This is called RC4-drop[256].
2422
- // See http://google.com/search?q=rsa+fluhrer+response&btnI
2423
- })(width);
2424
- }
2425
-
2426
- //
2427
- // copy()
2428
- // Copies internal state of ARC4 to or from a plain object.
2429
- //
2430
- function copy(f, t) {
2431
- t.i = f.i;
2432
- t.j = f.j;
2433
- t.S = f.S.slice();
2434
- return t;
2435
- }
2436
- //
2437
- // flatten()
2438
- // Converts an object tree to nested arrays of strings.
2439
- //
2440
- function flatten(obj, depth) {
2441
- var result = [], typ = (typeof obj), prop;
2442
- if (depth && typ == 'object') {
2443
- for (prop in obj) {
2444
- try { result.push(flatten(obj[prop], depth - 1)); } catch (e) {}
2445
- }
2446
- }
2447
- return (result.length ? result : typ == 'string' ? obj : obj + '\0');
2448
- }
2449
-
2450
- //
2451
- // mixkey()
2452
- // Mixes a string seed into a key that is an array of integers, and
2453
- // returns a shortened string seed that is equivalent to the result key.
2454
- //
2455
- function mixkey(seed, key) {
2456
- var stringseed = seed + '', smear, j = 0;
2457
- while (j < stringseed.length) {
2458
- key[mask & j] =
2459
- mask & ((smear ^= key[mask & j] * 19) + stringseed.charCodeAt(j++));
2460
- }
2461
- return tostring(key);
2462
- }
2463
-
2464
- //
2465
- // autoseed()
2466
- // Returns an object for autoseeding, using window.crypto and Node crypto
2467
- // module if available.
2468
- //
2469
- function autoseed() {
2470
- try {
2471
- var out;
2472
- if (nodecrypto && (out = nodecrypto.randomBytes)) {
2473
- // The use of 'out' to remember randomBytes makes tight minified code.
2474
- out = out(width);
2475
- } else {
2476
- out = new Uint8Array(width);
2477
- (global.crypto || global.msCrypto).getRandomValues(out);
2478
- }
2479
- return tostring(out);
2480
- } catch (e) {
2481
- var browser = global.navigator,
2482
- plugins = browser && browser.plugins;
2483
- return [+new Date, global, plugins, global.screen, tostring(pool)];
2484
- }
2485
- }
2486
-
2487
- //
2488
- // tostring()
2489
- // Converts an array of charcodes to a string
2490
- //
2491
- function tostring(a) {
2492
- return String.fromCharCode.apply(0, a);
2493
- }
2494
-
2495
- //
2496
- // When seedrandom.js is loaded, we immediately mix a few bits
2497
- // from the built-in RNG into the entropy pool. Because we do
2498
- // not want to interfere with deterministic PRNG state later,
2499
- // seedrandom will not call math.random on its own again after
2500
- // initialization.
2501
- //
2502
- mixkey(math.random(), pool);
2503
-
2504
- //
2505
- // Nodejs and AMD support: export the implementation as a module using
2506
- // either convention.
2507
- //
2508
- if (module.exports) {
2509
- module.exports = seedrandom;
2510
- // When in node.js, try using crypto package for autoseeding.
2511
- try {
2512
- nodecrypto = require$$0;
2513
- } catch (ex) {}
2514
- } else {
2515
- // When included as a plain script, set up Math.seedrandom global.
2516
- math['seed' + rngname] = seedrandom;
2517
- }
2518
-
2519
-
2520
- // End anonymous scope, and pass initial values.
2521
- })(
2522
- // global: `self` in browsers (including strict mode and web workers),
2523
- // otherwise `this` in Node and other environments
2524
- (typeof self !== 'undefined') ? self : commonjsGlobal,
2525
- [], // pool: entropy pool starts empty
2526
- Math // math: package containing random, pow, and seedrandom
2527
- );
2528
- }(seedrandom$1));
2529
-
2530
- // A library of seedable RNGs implemented in Javascript.
2531
- //
2532
- // Usage:
2533
- //
2534
- // var seedrandom = require('seedrandom');
2535
- // var random = seedrandom(1); // or any seed.
2536
- // var x = random(); // 0 <= x < 1. Every bit is random.
2537
- // var x = random.quick(); // 0 <= x < 1. 32 bits of randomness.
2538
-
2539
- // alea, a 53-bit multiply-with-carry generator by Johannes Baagøe.
2540
- // Period: ~2^116
2541
- // Reported to pass all BigCrush tests.
2542
- var alea = alea$1.exports;
2543
-
2544
- // xor128, a pure xor-shift generator by George Marsaglia.
2545
- // Period: 2^128-1.
2546
- // Reported to fail: MatrixRank and LinearComp.
2547
- var xor128 = xor128$1.exports;
2548
-
2549
- // xorwow, George Marsaglia's 160-bit xor-shift combined plus weyl.
2550
- // Period: 2^192-2^32
2551
- // Reported to fail: CollisionOver, SimpPoker, and LinearComp.
2552
- var xorwow = xorwow$1.exports;
2553
-
2554
- // xorshift7, by François Panneton and Pierre L'ecuyer, takes
2555
- // a different approach: it adds robustness by allowing more shifts
2556
- // than Marsaglia's original three. It is a 7-shift generator
2557
- // with 256 bits, that passes BigCrush with no systmatic failures.
2558
- // Period 2^256-1.
2559
- // No systematic BigCrush failures reported.
2560
- var xorshift7 = xorshift7$1.exports;
1742
+ }(alea));
2561
1743
 
2562
- // xor4096, by Richard Brent, is a 4096-bit xor-shift with a
2563
- // very long period that also adds a Weyl generator. It also passes
2564
- // BigCrush with no systematic failures. Its long period may
2565
- // be useful if you have many generators and need to avoid
2566
- // collisions.
2567
- // Period: 2^4128-2^32.
2568
- // No systematic BigCrush failures reported.
2569
- var xor4096 = xor4096$1.exports;
2570
-
2571
- // Tyche-i, by Samuel Neves and Filipe Araujo, is a bit-shifting random
2572
- // number generator derived from ChaCha, a modern stream cipher.
2573
- // https://eden.dei.uc.pt/~sneves/pubs/2011-snfa2.pdf
2574
- // Period: ~2^127
2575
- // No systematic BigCrush failures reported.
2576
- var tychei = tychei$1.exports;
2577
-
2578
- // The original ARC4-based prng included in this library.
2579
- // Period: ~2^1600
2580
- var sr = seedrandom$1.exports;
2581
-
2582
- sr.alea = alea;
2583
- sr.xor128 = xor128;
2584
- sr.xorwow = xorwow;
2585
- sr.xorshift7 = xorshift7;
2586
- sr.xor4096 = xor4096;
2587
- sr.tychei = tychei;
2588
-
2589
- var seedrandom = sr;
1744
+ var seedrandom = alea.exports;
2590
1745
 
2591
1746
  /**
2592
1747
  * Uses the `seedrandom` package to replace Math.random() with a seedable PRNG.
@@ -2594,12 +1749,8 @@ var seedrandom = sr;
2594
1749
  * @param seed An optional seed. If none is given, a random seed will be generated.
2595
1750
  * @returns The seed value.
2596
1751
  */
2597
- function setSeed(seed) {
2598
- if (!seed) {
2599
- const prng = seedrandom();
2600
- seed = prng.int32().toString();
2601
- }
2602
- seedrandom(seed, { global: true });
1752
+ function setSeed(seed = Math.random().toString()) {
1753
+ Math.random = seedrandom(seed);
2603
1754
  return seed;
2604
1755
  }
2605
1756
  function repeat(array, repetitions, unpack = false) {