MathUtils.seededRandom()
is a method provided by the Three.js library, which generates a random number between 0 and 1 using a specified seed value. This function is useful in scenarios where randomness needs to be deterministic or predictable.
THREE.MathUtils.seededRandom( seed )
seed (Number) - The seed value to use for generating the random number.
(Number) - A random number between 0 and 1 generated using the specified seed value.
// Generate a random number with seed 123
const random1 = THREE.MathUtils.seededRandom(123);
// Generate a different random number with the same seed value
const random2 = THREE.MathUtils.seededRandom(123);
// Both random numbers will be the same since they have the same seed value
console.log(random1); // 0.2567673914543395
console.log(random2); // 0.2567673914543395
// Generate another random number with a different seed value
const random3 = THREE.MathUtils.seededRandom(456);
// This random number will be different since it has a different seed value
console.log(random3); // 0.7530115807579014
In the above example, we use MathUtils.seededRandom()
to generate random numbers with different seed values. We can see that invoking this function with the same seed value results in the same random number being generated, which can be useful in situations where we need to ensure consistency in our random number generation.
MathUtils.seededRandom()
is a simple but useful function provided by the Three.js library that enables developers to generate deterministic and predictable random numbers using a specified seed value. Its ease of use and flexibility make it a popular choice for developers in various use cases.