Page 1 of 1

mapinfo math.random & math.randomseed

Posted: 14 Apr 2015, 22:18
by eronoobos
inside mapconfig/mapinfo/80_startlocations.lua

Code: Select all

Spring.Echo(math, math.floor, math.abs, math.random, math.randomseed)
result:

Code: Select all

[f=0000000] <table>, <function>, <function>, nil, nil
</3

edit: i mean, i understand the rationale for not giving access to the random number generator in mapinfo (desync hell). but ironically, we know that the random number generator has predictable behaviour before the game starts (although this may not be the desired behaviour), and is therefore not dangerous.

Re: mapinfo math.random & math.randomseed

Posted: 14 Apr 2015, 22:46
by jK
No, the defs.lua stage (returning UnitDefs, WeaponDefs, etc.) has to be `static` - means it same results for same input, which are the ModOptions - cause the unitsync already loads that stage. So that the lobby can already show available units etc. and allows to disable some of them etc.
So in the past many ppl disabled nukes, planes, ...

These days it's a less used features, but it's still there.

Re: mapinfo math.random & math.randomseed

Posted: 14 Apr 2015, 22:59
by eronoobos
jK wrote:No, the defs.lua stage (returning UnitDefs, WeaponDefs, etc.) has to be `static` - means it same results for same input, which are the ModOptions
Right. (And MapOptions?) Oddly, what I want to use the random number generator to do *would* give the same results for the same input, because math.randomseed() would use a seed from the MapOptions. Or is this still too unpredictable, because lua's random number generator is different depending on the hardware & OS?

I suppose I could use a pure lua pseudorandom number generator for this purpose.

Re: mapinfo math.random & math.randomseed

Posted: 15 Apr 2015, 02:06
by gajop
This is pretty trivial to implement iirc: http://en.wikipedia.org/wiki/Linear_con ... _generator

Re: mapinfo math.random & math.randomseed

Posted: 15 Apr 2015, 18:53
by eronoobos
so i was going to use this to set dynamic start locations, but HexFarm has a way of doing this within the gadget, by replacing Spring.GetTeamStartPosition

Re: mapinfo math.random & math.randomseed

Posted: 16 Apr 2015, 21:42
by zwzsg
The way I do it in HexFarm is super ugly. It's just that I didn't want to duplicate the map layout generation code into mapinfo.