UNPKG

1.22 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.random = void 0;
4function 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}
10function 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; // Convert to 32bit integer
18 }
19 return hash;
20}
21/**
22 * A deterministic pseudo-random number generator.
23 * Pass in the same seed and get the same pseudorandom number.
24 * See: https://remotion.dev/docs/random
25 */
26const 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};
41exports.random = random;
42//# sourceMappingURL=random.js.map
\No newline at end of file