Page 1 of 1

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

Posted: Thu Nov 21, 2024 12:20 pm
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...

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

Posted: Fri Nov 22, 2024 10:30 am
by BraveCaperCat
Guess I'll have to figure that out myself...

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

Posted: Wed Nov 27, 2024 1:26 am
by wizmut

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

Posted: Wed Nov 27, 2024 11:25 am
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.

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

Posted: Wed Nov 27, 2024 11:47 am
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.

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

Posted: Wed Nov 27, 2024 11:53 am
by Rseding91
Math.random during data stage is a available and is deterministic.

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

Posted: Wed Nov 27, 2024 11:59 am
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?

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

Posted: Wed Nov 27, 2024 12:04 pm
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.

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

Posted: Wed Nov 27, 2024 12:20 pm
by BlueTemplar
Isn't the seed exposed for modders ?

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

Posted: Wed Nov 27, 2024 12:26 pm
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.

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

Posted: Wed Nov 27, 2024 12:29 pm
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.

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

Posted: Wed Nov 27, 2024 12:38 pm
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.

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

Posted: Wed Nov 27, 2024 12:47 pm
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).