MCPcopy
hub / github.com/tiagozip/cap / prng

Function prng

solver/index.js:4–31  ·  view source on GitHub ↗
(seed, length)

Source from the content-addressed store, hash-verified

2import { Worker } from "node:worker_threads";
3
4function prng(seed, length) {
5 function fnv1a(str) {
6 let hash = 2166136261;
7 for (let i = 0; i < str.length; i++) {
8 hash ^= str.charCodeAt(i);
9 hash +=
10 (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
11 }
12 return hash >>> 0;
13 }
14
15 let state = fnv1a(seed);
16 let result = "";
17
18 function next() {
19 state ^= state << 13;
20 state ^= state >>> 17;
21 state ^= state << 5;
22 return state >>> 0;
23 }
24
25 while (result.length < length) {
26 const rnd = next();
27 result += rnd.toString(16).padStart(8, "0");
28 }
29
30 return result.substring(0, length);
31}
32
33const workerBlob = new Blob(
34 [

Callers 1

solveFunction · 0.70

Calls 2

fnv1aFunction · 0.70
nextFunction · 0.70

Tested by

no test coverage detected