mapinfo math.random & math.randomseed

mapinfo math.random & math.randomseed

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
User avatar
eronoobos
Posts: 73
Joined: 27 Mar 2015, 20:25

mapinfo math.random & math.randomseed

Post 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.
User avatar
jK
Spring Developer
Posts: 2299
Joined: 28 Jun 2007, 07:30

Re: mapinfo math.random & math.randomseed

Post 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.
User avatar
eronoobos
Posts: 73
Joined: 27 Mar 2015, 20:25

Re: mapinfo math.random & math.randomseed

Post 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.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: mapinfo math.random & math.randomseed

Post by gajop »

This is pretty trivial to implement iirc: http://en.wikipedia.org/wiki/Linear_con ... _generator
User avatar
eronoobos
Posts: 73
Joined: 27 Mar 2015, 20:25

Re: mapinfo math.random & math.randomseed

Post 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
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7052
Joined: 16 Nov 2004, 13:08

Re: mapinfo math.random & math.randomseed

Post 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.
Post Reply

Return to “Lua Scripts”