Use a seed value with a PRNG
mainBy default, simplex-noise.js uses Math.random(). To use a specific seed, you must provide a Pseudo-Random Number Generator (PRNG) function to the creation functions. It is recommended to use the alea package for this purpose.
- Install
alea:npm install -S alea - Create a PRNG instance with your seed.
- Pass the PRNG instance to
createNoise2D,createNoise3D, orcreateNoise4D.
Note: If you are creating multiple noise functions (e.g., 2D and 3D) and want them to be independent/compatible with 3.x behavior, pass a fresh instance of alea to each call.
import alea from 'alea';
import { createNoise2D } from 'simplex-noise';
const prng = alea('seed');
const noise2D = createNoise2D(prng);
console.log(noise2D(x, y));import alea from 'alea';
// create a new random function based on the seed
const prng = alea('seed');
// use the seeded random function to initialize the noise function
const noise2D = createNoise2D(prng);
console.log(noise2D(x, y));