Math.randomseed randomness

I have made a fully functional adventure game and all I need now is to generate areas based on a seed. Currently I take the areas position and run it like so: math.randomseed((x*y)/(z+y)). This gets a seed that is area specific but most of the areas generate very similar patterns. How would I go about generating numbers that look random but can be reproduced with the same seed.

What do you mean? Changing the seed only changes what random numbers appear. So if you have a seed of 1, you are going to change what random numbers appear. If we were to change that seed to 2, the pattern would be changed, thus different random numbers would appear with that seed.

The problem I have is that i’m using different numbers for random seed but the results are very similar

How are you setting x, y, z then? Can I see the part of the script that is changing / setting those variables?

The most random I could think of is math.randomseed(tick()). Same seed makes it very consistent.


Why don’t you try the Random feature?

2 Likes

The x, y, z values are basically set in intervals of 50 so the areas are evenly spaced.

Thats exactly why you are getting similar results. You are setting them to the same value rather than making them random (Which still won’t fix your issue), then when feeding them into the math.randomeseed() function, the results are going to stay the same, because you are not setting them to different values every time you run the game, even if you set them to math.random(min, max), you are still going to get the same results, because the seed has not been changed before we set those values. Let me give you a snippet of code that I have which changes it’s seed in such a way, that is almost completely random.

Does the Random feature work in the same way as random seed where I can put it before math.random and it will generate the same number per seed?

Here is what I use to get almost completely random results:

local Seed = (math.random() % math.random() * tick())
math.randomseed(Seed)
print(math.random())

I need the world to be the same every time but each area has to be different from the other areas. What I have so far is that the script is generating the same world each time but all the areas look very similar.

Yes, but why are you beating about the bush on random seed? Just keep one seed and the randomness will be fine. Seriously.

1 Like

That’s the problem, I expected it to look random but all the areas look very similar.

You don’t need to generate new seeds, you need to generate new random numbers rather than using new seeds to generate. Even Minecraft used one seed and that’s it.

1 Like

That Random.new thing seemed to fix the problem. All the areas are looking different now, thanks. I was using one seed before but that wasn’t working out so I generated seeds per area but Random.new seems to work so I will switch back to a single seed.

If you need predicable randomness then using a seed for each instance is the way to go.
I have done this in the past by having a table of seeds where each has been tested by me and proved to be playable and then use a random selector for the index of that table.
Makes for easy testing if a player has problems with a specific area generated from a specific seed.
I hope this helps.

I was using that with randomseed but all the areas were looking similar so I switched it to Random.new instead and its working much better.

1 Like

You can use math.noise to generate these random seeds based on coordinates.

I see. I am not sure if you had tested each seed to ensure the result was playable and sufficiently different to be a good one. If you have I apologise.
I am assuming you are using the random function in build or selection processes within the game and wanted the game to look and feel different.

I am now using math.noise and Random.new together and I’m getting the exact results I was looking for, thanks everyone

1 Like

Don’t use randomseed. It changes the seed globally so if you use math.randomseed often, now you have several scripts clashing for a seed and using the same one when running operations. Random allows you to assign a seed to a Random object that other code will be unable to interfere with. It also allows results branching through the Clone method; seed is preserved.