How does one set the seed of Roblox's 3d noise generator?

I want to generate some cool terrain, which means I don’t want to use heightmaps, which means I need 3d noise. The problem I have with Roblox’s 3d noise is that there’s no easy way to set the seed.

Take this script:

math.randomseed(123)

print(math.noise(0.1, 0.2, 0.3))

math.randomseed(456)

print(math.noise(0.1, 0.2, 0.3))

math.noise(0.1, 0.2, 0.3) will always give 0.35122925043106, no matter how many times you run the script.

Is there another way to have a seed with Roblox’s 3d noise, or do I need to find/create a 3d noise library in Luau?

The function uses a perlin noise algorithm to assign fixed values to coordinates. For example, math.noise(1.158, 5.723) will always return 0.48397532105446 and math.noise(1.158, 6) will always return 0.15315161645412 .

math | Roblox Creator Documentation

Instead of a seed, you can add an offset to one or more of the coordinates:

local seed = 123

print(math.noise(seed + 0.1, 0.2, 0.3))

seed = 456

print(math.noise(seed + 0.1, 0.2, 0.3))

Wouldn’t players eventually notice that their generated worlds with supposedly different seeds are just offsets of each other?

Maybe I am misunderstanding how math.noise works…?

Maybe I could do this:

local seed = 123456
local range = 100 -- idk

local random = Random.new(seed)

local offsets = Vector3.new(
	random:NextNumber(-range, range),
	random:NextNumber(-range, range),
	random:NextNumber(-range, range)
)

print(math.noise(offsets.X + 0.1, offsets.Y + 0.2, offsets.Z + 0.3))

This way, seeds are more chaotic; a small change can drastically change the offsets.
I’m not sure how different generated worlds can get like this though…

The X value of math.noise is required. Usually, you add the seed to ‘X’ plus its actual value to get a randomly generated world.

This isn’t how math.noise works if I recall.

I thought I might be overthinking it. Thanks!

@nicemike40’s answer is basically the same, but I’ll mark @ZuIu_B’s answer as the solution since it’s a little clearer.

1 Like