How can i do TRUE random generation?

hey, I’ve been working on a funny overused concept game for months before it was popularised and during those agonizing 6 months I STILL HAVE NOT figured out how to do TRUE random generation.
My goal here is to generate in chunks randomly and add the occasional props here and there randomly as well, the only problem is I have no idea how to do this.
I have a general idea of random/procedural generation, with set rooms and those rooms are positioned randomly to make a dungeon or maze.

How should I go about this? How should I use math.Random()? Is there an easy way to do this?

Any help is extremely appreciated, I really need this right now. Thank you in advance

EDIT: Please do let me know if this is not possible, and let me know if there is a way around it. Thank you

Math.random is rather easy to use.

result = math.random(MIN, MAX) -- Ex: math.random(1, 3) will give 1<=result<=3

Further reading.
math (roblox.com)
Edit: Forgot a closing parenthesis & added example comment.

I don’t get how this is going to help me randomly generate chunks, all it is is telling me how to use functions I know how to use to some capacity, my question is how I would go about it; as in how would I randomly generate a completely random room? What parameters should I use (if any)? Is this even possible?

you will need to use math.noise

local seed1 = 8974239.462
local seed2 = 2484754.734
local scale1 = 0.001
local scale2 = 0.04
for x = -100, 100 do
	for z = -100, 100 do
		local noise = math.noise(x * scale1, seed1, z ^ scale1)
		noise += math.noise(x * scale2 , seed2, z * scale2)
		if noise > 0.1 then
			local part = Instance.new("Part")
			part.Position = vector3.new(x, 0, z)
			part.Parent = game.Workspace
		end
	end
end

here you can see how I’m using math noise to generate random terrain and models around the terrain

and if you edit this place you can view the source code to my infinite terrain plugin that might help you

3 Likes

yes your terrain plugin does help a lot more than I thought it would, when I originally looked through the source code I thought I’d be able to modify it to do what I needed, but the problem is that my game ISN’T terrain, and I wasn’t sure how to go about making it parts of a set size but keeping the room size itself random… if that makes sense.

Sorry. It’s getting late and I for some reason got the impression you had chunks (like minecraft) and simply wanted to randomly distribute them.

Well, solution anyway is to use random numbers. If you are using a non-terrain world you may need to create “holders”, places where prebuilt items go. You can then use random numbers to decide which and if a prop should go there.

1 Like

the original plan was actually to use set chunks so it’d be easier on me, but because I’m a bit too much of a perfectionist and I want to be the best at everything I do, I decided to make it truly random, but as I said in the post itself and in the reply to yours, I’m not even sure if truly random generation is possible to adjust to the way I want it

It is, but if you do true random it may be unplayable.

  • Random placements
  • Random parts (no models, no houses etc.)
  • Random colors
  • Random lighting

While this is sure to be an interesting sight to see. However, I’m not sure a truly random game would be too much fun, since there is no guarantee that you can move anywhere (random means gaps may occur).

1 Like

alright, this does answer some of my questions.
so how would I make it “Truly” random WITHOUT making it truly random? If that makes sense?

what if you generate the game in grids and each square is lets says 50 x 50 studs and then you design lots of different 50x50 size rooms but some rooms dont have walls so there open to the room next to it you would get maybe something like this

and you would use math.noise to select what room to place in each square

1 Like

I don’t quite understand what you mean, I know what I’d need to do to an extent but I’m not 100% sure how I’d actually apply the concept. Any advice?

local rooms = game.ReplicatedStorage.Rooms:GetChildren()
local roomSize = 50
local seed1 = 8974239.462
local seed2 = 2484754.734
local scale1 = 0.001
local scale2 = 0.04
for x = -100, 100 do
	for z = -100, 100 do
		local noise = (math.noise(x * scale1, seed1, z ^ scale1) + 0.5) / 2
		noise += (math.noise(x * scale2 , seed2, z * scale2) + 0.5) / 2
		noise = math.clamp(noise / 2, 0, 1)
		noise = math.round(noise * (#rooms - 1) + 1)
		local room = rooms[noise]
		local clone = room:Clone()
		clone:PivotTo(CFrame.new(x * roomSize, 0, z * roomSize)) -- you can also use noise to rotate the room
		clone.Parent = game.Workspace
	end
end

its a bit ugly but maybe this will help

its also possible to do it with random if the world is not infinite

1 Like

gives me this error in the output
image

local seed = 90802948
local random = Random.new(seed)

local rooms = game.ReplicatedStorage.Rooms:GetChildren()
local roomSize = 50
local mapSize = 8
for x = -mapSize, mapSize do
	for z = -mapSize, mapSize do
		local i = random:NextInteger(1, #rooms)
		local room = rooms[i]
		local clone = room:Clone()
		clone:PivotTo(CFrame.new(x * roomSize, 0, z * roomSize)) 
		clone.Parent = game.Workspace
	end
end

and this is how you can do it with random but the seed will only generate the same map if the mapSize stays the same if you change the map size then the seed will generate a different map

1 Like

i tried this script and this was the result

image

some parts are clipping into each other incorrectly and they’re spread out randomly for some reason

Make sure you have a folder in game.ReplicatedStorage called Rooms
and inside this folder you need models

make sure all models are the same size as

local roomSize = 50

so this means all models need to be 50x50 studs in size

also make sure the models pivot in the center

1 Like

ohhh i see, i’ll do that right now and I’ll let you know what happens

Is this the backrooms??

Anyhow, that doesn’t really matter. What you can do are a few things, but making a defined grid-size will make everything so much easier.

One way to make it very simple for you is to make sure every room covers an entire grid slot (slim corridors may have walls filling out to the sides) and then randomly generate each new grid tile with random number generation.

Another way is to generate grid tiles based on neighboring tiles, for example tile X can not exist if tile Y is to the left of it.

1 Like

alright, well how would I go about doing this? is there a specific method?
edit: for the generation, I know what you mean by the grid because I’ve done it before but I’m not sure how to make it actually possible