wgblas
    Preparing search index...

    Function randomFloat32Array

    • Returns a Float32Array of n random values uniformly sampled from [low, high).

      Default range [-1, 1):

      import { randomFloat32Array } from "wgblas";

      const x = randomFloat32Array(4);
      console.log(x); // Float32Array [ -0.42, 0.81, -0.07, 0.55 ] (values differ each run)

      Custom range [0, 10):

      import { randomFloat32Array } from "wgblas";

      const x = randomFloat32Array(4, 0, 10);
      console.log(x);

      Seeded (deterministic):

      import { randomFloat32Array } from "wgblas";

      // Same seed -> identical output every run, useful for reproducible
      // regression tests that need "random-looking" data without real randomness.
      const a = randomFloat32Array(4, -1, 1, 42);
      const b = randomFloat32Array(4, -1, 1, 42);
      console.log(a);
      console.log(b);
      console.log(
      "identical:",
      a.every((v, i) => v === b[i]),
      );

      Parameters

      • n: number

        number of elements

      • Optionallow: number

        lower bound (default: -1)

      • Optionalhigh: number

        upper bound (default: 1)

      • Optionalseed: number

        omit for genuine randomness (Math.random, the default); pass any number for a deterministic, reproducible sequence (mulberry32) — useful for regression tests that need "random-looking" data without flaking between runs

      Returns Float32Array