@libraz/libcantus - v1.1.0
    Preparing search index...

    Function deriveSeed

    • Derive a child seed from a root seed and a path.

      The result is a 32-bit integer, so it can be passed straight to createRng. Derivation is a pure function of its arguments — the same root and path give the same seed in every runtime — and near-identical paths ('drums' against 'drum', bar 1 against bar 2) give unrelated seeds: the path is hashed with FNV-1a and finished with the MurmurHash3 fmix32 avalanche step.

      Parameters

      • root: number

        The project seed; an integer in 0..0xffffffff.

      • ...path: SeedPath

        The address to derive at; string or finite number segments.

      Returns number

      The derived seed, an integer in 0..0xffffffff.

      If the root is not a 32-bit integer, or a segment is neither a string nor a finite number.

      import { createRng, deriveSeed } from '@libraz/libcantus';
      const drums = deriveSeed(42, 'drums', 'chorus', 3);
      const rng = createRng(drums); // rerolling only the drums: bump the 3