Random (but consistent) generation of values in the data-stage
- BraveCaperCat
- Filter Inserter
- Posts: 407
- Joined: Mon Jan 15, 2024 10:10 pm
- Contact:
Random (but consistent) generation of values in the data-stage
Hi! I'm trying to make a mod which adds a galaxy to factorio, with the singular star system added by space age as part of it. I was wondering how I could create so many star systems in the data stage while staying within the size limitation on the mod portal. My idea was to consistently generate "random" planets and stars, like if you used an sRNG program with the same seed over and over again (re-running the program will produce the same results). That way it can't desync compared to an tRNG program generating truly random numbers (re-running the program will produce different results).
I was wondering how this could be implemented in my mod. Also, this would mean that, while I made the mod, I don't know all the content it adds...
I was wondering how this could be implemented in my mod. Also, this would mean that, while I made the mod, I don't know all the content it adds...
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
- BraveCaperCat
- Filter Inserter
- Posts: 407
- Joined: Mon Jan 15, 2024 10:10 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
Guess I'll have to figure that out myself...
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Re: Random (but consistent) generation of values in the data-stage
I'm not sure but this may be what you're looking for:
https://lua-api.factorio.com/latest/cla ... _generator
https://lua-api.factorio.com/latest/cla ... rator.html
https://lua-api.factorio.com/latest/cla ... _generator
https://lua-api.factorio.com/latest/cla ... rator.html
- BraveCaperCat
- Filter Inserter
- Posts: 407
- Joined: Mon Jan 15, 2024 10:10 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
I quote myself, but with boldness.wizmut wrote: ↑Wed Nov 27, 2024 1:26 am I'm not sure but this may be what you're looking for:
https://lua-api.factorio.com/latest/cla ... _generator
https://lua-api.factorio.com/latest/cla ... rator.html
As seen in the above quote (with boldness) I meant the data-stage. I'm not trying to be hard on you... but planets have to be made in the data-stage and you linked me to the control-stage random number generator.BraveCaperCat wrote: ↑Thu Nov 21, 2024 12:20 pm Hi! I'm trying to make a mod which adds a galaxy to factorio, with the singular star system added by space age as part of it. I was wondering how I could create so many star systems in the data stage while staying within the size limitation on the mod portal.
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
- IsaacOscar
- Filter Inserter
- Posts: 840
- Joined: Sat Nov 09, 2024 2:36 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
Just write your own code,
e.g. use this algorithm https://en.m.wikipedia.org/wiki/Xorshift
Note that Lua numbers can safely be used as 32-bit integers, or 64-bit floata/doubles, but not 64-bit int.
e.g. use this algorithm https://en.m.wikipedia.org/wiki/Xorshift
Note that Lua numbers can safely be used as 32-bit integers, or 64-bit floata/doubles, but not 64-bit int.
Re: Random (but consistent) generation of values in the data-stage
Math.random during data stage is a available and is deterministic.
If you want to get ahold of me I'm almost always on Discord.
- BraveCaperCat
- Filter Inserter
- Posts: 407
- Joined: Mon Jan 15, 2024 10:10 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
and it doesn't just generate the same value over and over again like the documentation seems to imply?
Creator of multiple mods, including Quality Assurance - My most popular one.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
Go check them out with the first and second links!
I'll probably be wanting or giving help with modding most of the time I spend here on the forum.
- IsaacOscar
- Filter Inserter
- Posts: 840
- Joined: Sat Nov 09, 2024 2:36 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
My reading of it is that the sequence it generates is constant, e.g. if the first time you call it will always return the same value, but the second time will give a different one.BraveCaperCat wrote: ↑Wed Nov 27, 2024 11:59 amand it doesn't just generate the same value over and over again like the documentation seems to imply?
- BlueTemplar
- Smart Inserter
- Posts: 3234
- Joined: Fri Jun 08, 2018 2:16 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
Isn't the seed exposed for modders ?
BobDiggity (mod-scenario-pack)
- IsaacOscar
- Filter Inserter
- Posts: 840
- Joined: Sat Nov 09, 2024 2:36 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
I don't see anywhere in the documentation, also it specifically says that you can't change the seed, so knowing it would be pointless.
- IsaacOscar
- Filter Inserter
- Posts: 840
- Joined: Sat Nov 09, 2024 2:36 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
The other generator https://lua-api.factorio.com/latest/cla ... or.htmdoes let you set the seed (I don't see an option to get it though), but that generator can't be used in the data stage.
Re: Random (but consistent) generation of values in the data-stage
Setting the seed is pointless because you don’t have any data to give it that isn’t already deterministic. So one deterministic seed is as good as the next.
If you want to get ahold of me I'm almost always on Discord.
- IsaacOscar
- Filter Inserter
- Posts: 840
- Joined: Sat Nov 09, 2024 2:36 pm
- Contact:
Re: Random (but consistent) generation of values in the data-stage
I guess you could want the seed to change each time you release a new version of the mod. Also some seeds may produce nicer looking results so you might want to use them (just like when choosing a map to play on).