1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.random = void 0;
|
4 | function mulberry32(a) {
|
5 | let t = a + 0x6d2b79f5;
|
6 | t = Math.imul(t ^ (t >>> 15), t | 1);
|
7 | t ^= t + Math.imul(t ^ (t >>> 7), t | 61);
|
8 | return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
9 | }
|
10 | function hashCode(str) {
|
11 | let i = 0;
|
12 | let chr = 0;
|
13 | let hash = 0;
|
14 | for (i = 0; i < str.length; i++) {
|
15 | chr = str.charCodeAt(i);
|
16 | hash = (hash << 5) - hash + chr;
|
17 | hash |= 0;
|
18 | }
|
19 | return hash;
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | const random = (seed, dummy) => {
|
27 | if (dummy !== undefined) {
|
28 | throw new TypeError('random() takes only one argument');
|
29 | }
|
30 | if (seed === null) {
|
31 | return Math.random();
|
32 | }
|
33 | if (typeof seed === 'string') {
|
34 | return mulberry32(hashCode(seed));
|
35 | }
|
36 | if (typeof seed === 'number') {
|
37 | return mulberry32(seed * 10000000000);
|
38 | }
|
39 | throw new Error('random() argument must be a number or a string');
|
40 | };
|
41 | exports.random = random;
|
42 |
|
\ | No newline at end of file |