Perlin Noise Randomization

Hello! recently I’ve been working a lot on Perlin Noise Terrain Generation however I’ve run into a issue with the randomizer I’m using this code block right here

local X = 225
local Z = 225
local randomNum = math.random(15, 200) --Defines the stretch of the terrain
local waterHeight = math.random(-35, -20) --Defines the height of the water
local sandHeight = math.random(waterHeight+2, waterHeight+4) --This determines how much extra sand will appear
local treeRarity = math.random(75, 100) --The higher the number the more rare trees become
-----------------------------------------------

local Seed = math.random(randomNum-20, randomNum+20)
local randomNumTwo = math.random(randomNum-10, randomNum+10)
local grid = {}

for x = 1, X do
	grid[x] = {}
	for z = 1, Z do
		grid[x][z] = math.noise(x/randomNum, z/randomNumTwo) --Issue Here
	end
end

and though it will use Perlin Noise Generation it won’t appear random. Any help is appreciated!

The density range is so vast that you get bigger ravines than we see in minecraft. Try uniforming that value with a linear function.

Well to start though it would work I’m trying to make my code custom I just want to know how I could make it more random than it is.

Basically we need to solve the equation of the alpha of the linear interpolation function.

Uhhhh. Not a clue what you just said

Say we have function

f(a,b,t) = a+(b-a)*t

what this means is our alpha value is equivalant to the parameters we pass for f(a,b,t) now let’s say we know what a and b and f(a,b,t) is. How could we find what t is? We would need to solve the equation for t. Now let’s start with a more simple example, lets say we have

f(x) = 2x

we know what f(x) is but we don’t know what value we passed, say f(x) was 4. We can rewrite this as

4=2x

and then we can simply solve the equation by moving the variable x by using a system of equation to get 4/2 = x
we can rephrase this as

h(v) = v/2

Wouldn’t this always generate the same terrain?

f(a,b,t) is the value we got from that math.random() function

Which one? I have three math.random functions.

You would apply that for each density (math.random()) function

[quote=“SloppyBanana225, post:1, topic:1056012”]

local X = 225
local Z = 225
local randomNum = math.random(15, 200) --Defines the stretch of the terrain
local waterHeight = math.random(-35, -20) --Defines the height of the water
local sandHeight = math.random(waterHeight+2, waterHeight+4) --This determines how much extra sand will appear
local treeRarity = math.random(75, 100) --The higher the number the more rare trees become
-----------------------------------------------

local Seed = math.random(randomNum-20, randomNum+20)
local randomNumTwo = math.random(randomNum-10, randomNum+10)
local grid = {}

for x = 1, X do
	grid[x] = {}
	for z = 1, Z do
		grid[x][z] = math.noise(x/f(a,b,t), z/f(a,b,t) --Issue Here
	end
end

is this what it would look like?

What I was describing to you earlier was just latex. You gotta code your lerp alpha function bro. Or just use my Math++ bound() function :wink:

Ok, yeah I’m clueless I’ll just mark you as solution.

You described it to me well I just don’t understand it, though you solved it so, heh.

Try reading this Solving Equations

in case anyone else is struggling this worked for me

local seed = math.random() * 1000
local res = 100
local freq = 3
local amp = 10
local noise = math.noise(
	(x+seed)/res * freq,
	(y+seed)/res * freq
) * amp