Math.randomseed

Place to get help with not working mods / modding interface.
Post Reply
Chocolatetthunder
Long Handed Inserter
Long Handed Inserter
Posts: 74
Joined: Sat Sep 03, 2016 12:00 am
Contact:

Math.randomseed

Post by Chocolatetthunder »

So i have been making a new scenario for factorio multiplayer basing a lot of my code off of what the devs made with the official team production challenge.
i am using a map blueprint I made in the map editor
i am also calling on math.random to generate random variables.
what i am learning from the forums is that math.random is always based off the seed of the map so i cant set a math.randomseed() of my own
I am here to see if anyone else has come to this before me and has found a good solution or could help walk me though it.

moar...
the problem i am having is the fact that i am using the map i created, with the math.random is always pulling the same number.
and i can't set math.randomseed(os.time) because from what i am understanding that would cause dyncs in multiplayer.
hence why they made it always based on the map seed, because that would make the same numbers for every client.
I had seen in the team production challenge that they added some interesting code function save_map_data(distance), and function recreate_map so instead of loading in a blueprint like i have been doing. They generate a map and erase it and load their map on top if the now empty map.
and i think( correct me if you know more than me..) they did all of that just to keep a stable use of math.random

what im getting at..
i am looking for clarification before i go do that same convoluted damn'd thing and not actually fix my problem.
3Ra Gaming Owner
join us on discord @ http://www.3RaGaming.com/discord

User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3700
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Math.randomseed

Post by DaveMcW »

If you want to set your own seed, you need to write you own RNG.

Here is an example: http://stackoverflow.com/questions/2015 ... 6#20177466

orzelek
Smart Inserter
Smart Inserter
Posts: 3911
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Re: Math.randomseed

Post by orzelek »

You can also find random generator impementations in RSO.
There are 2 or 3 different ones there in the lib folder drand.lua file.

Post Reply

Return to “Modding help”