BufferGeometry
Object3D
Raycaster
Camera
CubeCamera
PerspectiveCamera
OrthographicCamera
StereoCamera
Clock
Curve
CurvePath
Path
Shape
ShapePath
ArrowHelper
AxesHelper
BoxHelper
Box3Helper
CameraHelper
DirectionalLightHelper
GridHelper
PolarGridHelper
HemisphereLightHelper
PlaneHelper
PointLightHelper
SkeletonHelper
SpotLightHelper
Light
PointLight
RectAreaLight
SpotLight
DirectionalLight
HemisphereLight
LightShadow
PointLightShadow
AnimationLoader
AudioLoader
BufferGeometryLoader
CompressedTextureLoader
CubeTextureLoader
DataTextureLoader
FileLoader
ImageBitmapLoader
ImageLoader
Loader
LoaderUtils
MaterialLoader
ObjectLoader
TextureLoader
LoadingManager
Material
Box2
Box3
Color
Cylindrical
Euler
Frustum
Interpolant
Line3
MathUtils
Matrix3
Matrix4
Plane
Quaternion
AnimationAction
AnimationClip
AnimationMixer
AnimationObjectGroup
AnimationUtils
keyframeTrack
PropertyBinding
PropertyMixer
BooleanKeyframeTrack
QuaternionKeyframeTrack
StringKeyframeTrack
Audio
AudioAnalyser
AudioContext
AudioListener
PositionalAudio

MathUtils.seededRandom()

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.

Syntax

THREE.MathUtils.seededRandom( seed )

Parameters

seed (Number) - The seed value to use for generating the random number.

Return Value

(Number) - A random number between 0 and 1 generated using the specified seed value.

Example Usage

// 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.

Conclusion

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.