Random (but consistent) generation of values in the data-stage

Place to get help with not working mods / modding interface.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 407
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Random (but consistent) generation of values in the data-stage

Post by BraveCaperCat »

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...
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.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 407
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by BraveCaperCat »

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.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 407
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by BraveCaperCat »

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
I quote myself, but with boldness.
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.
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.
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.
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 840
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by IsaacOscar »

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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14798
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by Rseding91 »

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.
User avatar
BraveCaperCat
Filter Inserter
Filter Inserter
Posts: 407
Joined: Mon Jan 15, 2024 10:10 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by BraveCaperCat »

Rseding91 wrote: Wed Nov 27, 2024 11:53 am Math.random during data stage is a available and is deterministic.
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.
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 840
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by IsaacOscar »

BraveCaperCat wrote: Wed Nov 27, 2024 11:59 am
Rseding91 wrote: Wed Nov 27, 2024 11:53 am Math.random during data stage is a available and is deterministic.
and it doesn't just generate the same value over and over again like the documentation seems to imply?
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.
User avatar
BlueTemplar
Smart Inserter
Smart Inserter
Posts: 3234
Joined: Fri Jun 08, 2018 2:16 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by BlueTemplar »

Isn't the seed exposed for modders ?
BobDiggity (mod-scenario-pack)
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 840
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by IsaacOscar »

BlueTemplar wrote: Wed Nov 27, 2024 12:20 pm Isn't the seed exposed for modders ?
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.
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 840
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by IsaacOscar »

BlueTemplar wrote: Wed Nov 27, 2024 12:20 pm Isn't the seed exposed for modders ?
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.
Rseding91
Factorio Staff
Factorio Staff
Posts: 14798
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by Rseding91 »

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.
User avatar
IsaacOscar
Filter Inserter
Filter Inserter
Posts: 840
Joined: Sat Nov 09, 2024 2:36 pm
Contact:

Re: Random (but consistent) generation of values in the data-stage

Post by IsaacOscar »

Rseding91 wrote: Wed Nov 27, 2024 12:38 pm 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.
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).
Post Reply

Return to “Modding help”