Feature release: reproducible Math.random() via custom seeds.
Added
-
Custom seed for
Math.random()(#850). Seed a kernel withkernel.setRandomSeed(seed)or therandomSeedkernel setting:const kernel = gpu.createKernel(function() { return Math.random(); }, { output: [64], randomSeed: 42 });
A seeded kernel draws its per-run GPU seed uniforms from a deterministic stream (mulberry32): consecutive runs differ, but recreating the kernel — or calling
setRandomSeedagain — with the same seed replays the exact same sequence of runs. Unseeded kernels behave exactly as before.Applies to GPU modes (
gpu,webgl,webgl2,headlessgl);cpumode logs a warning and stays unseeded. TypeScript definitions included.
Installing
npm install gpu.js@2.18.0<script src="https://unpkg.com/gpu.js@2.18.0/dist/gpu-browser.min.js"></script>