MCPcopy
hub / github.com/nusu/avvvatars / constructor

Method constructor

src/lib/alea.ts:7–38  ·  view source on GitHub ↗
(seed: any)

Source from the content-addressed store, hash-verified

5 s2: number;
6
7 constructor(seed: any) {
8 if (seed == null) seed = +(new Date);
9
10 let n = 0xefc8249d;
11
12 // Apply the seeding algorithm from Baagoe.
13 this.c = 1;
14 this.s0 = mash(' ');
15 this.s1 = mash(' ');
16 this.s2 = mash(' ');
17 this.s0 -= mash(seed);
18 if (this.s0 < 0) { this.s0 += 1; }
19 this.s1 -= mash(seed);
20 if (this.s1 < 0) { this.s1 += 1; }
21 this.s2 -= mash(seed);
22 if (this.s2 < 0) { this.s2 += 1; }
23
24 function mash(data: string) {
25 data = String(data);
26 for (let i = 0; i < data.length; i++) {
27 n += data.charCodeAt(i);
28 let h = 0.02519603282416938 * n;
29 n = h >>> 0;
30 h -= n;
31 h *= n;
32 n = h >>> 0;
33 h -= n;
34 n += h * 0x100000000; // 2^32
35 }
36 return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
37 }
38 }
39
40 next() {
41 let {c,s0,s1,s2} = this;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected