Skip to content

2.18.0

Choose a tag to compare

@fuzzie360 fuzzie360 released this 22 Jul 12:24

Feature release: reproducible Math.random() via custom seeds.

Added

  • Custom seed for Math.random() (#850). Seed a kernel with kernel.setRandomSeed(seed) or the randomSeed kernel 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 setRandomSeed again — 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); cpu mode 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>