Random generator behaviour

Place to post guides, observations, things related to modding that are not mods themselves.
orzelek
Smart Inserter
Smart Inserter
Posts: 3924
Joined: Fri Apr 03, 2015 10:20 am
Contact:

Random generator behaviour

Post by orzelek »

I've been playing around with replacing custom rng in RSO for new built in one. I didn't measure it but by looking at time stats it's also faster then lua one by quite a bit. Determinism also tested nicely - can regen ore exactly as before.

It seems to work very well with one small inconsistency.
If I have line like this:

Code: Select all

			shape = meta_shapes[rng(1,#meta_shapes)]
I would add 1 to amount of entries in table since docs state that rng is [low, high) but it would then fail on accessing a nil in the table.
In practice rolled value is [low, high] so it works as it should without +1 there. It's actually better for me this way but then docs could use an update.

Can you take a look and amend docs or code to make it consistent?
Rseding91
Factorio Staff
Factorio Staff
Posts: 14931
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: Random generator behaviour

Post by Rseding91 »

Thanks for the notice. I'll update the lua docs.
If you want to get ahold of me I'm almost always on Discord.
Post Reply

Return to “Modding discussion”