2019-12-07 07:37 CET

View Issue Details Jump to Notes ] Related Changesets ]
IDProjectCategoryView StatusLast Update
0005423Spring engineGeneralpublic2016-12-24 19:59
Assigned ToKloot 
Product Version103.0 +git 
Target VersionFixed in Version 
Summary0005423: random number generation in defs.lua (-> and _post.lua)
DescriptionCurrently its not possible to produce "true" randomness inside defs.lua, and consequently in any of the _post files. The lua state that reads defs.lua has no access to anything that could be used to seed a random number generator.

Obviously such randomness would need to be synced. Maybe the gameID can be passed in?
Additional InformationUse case is procedural generation of defs.

I am making a frivolous (map) mutator that "randomly" mutates unit/weapondefs. Currently they only way I can find to seed its RNG is with a mapoption, which is clunky and poorly suited to autohosts.

There are sensible use cases in the same mould!
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files




Kloot (developer)

Unfortunately defs.lua is executed long before a client receives the game ID.

Another complication is that Spring's synced RNG uses the game ID as a seed itself, so you would end up with the same sequence of mutations on every run if that one were accessible.

Unless you are willing to add some kind of synced entropy source (like one client forwarding its /dev/random/ contents), this is just infeasible.


silentwings (reporter)

Sourcing entropy from the host seems natural to me.

Sending a single random seed (e.g. a hashed os.time() from the host machine) would be enough, but I don't know if the network interface even exists early enough?


Kloot (developer)

Amusingly enough host-based "preseeding" already exists but isn't used anywhere.

I'll be back.


Anonymous (viewer)

Fix 0df5fb566057eafe982db09740b50f910714b7c1 committed to develop branch: fix 0005423

math.random is now available during execution of defs.lua
(math.randomseed also exists, but will always be a no-op), repo: spring changeset id: 7714


hokomoko (developer)

compilation of dedicated server fails at the moment

+Related Changesets

-Issue History
Date Modified Username Field Change
2016-12-23 22:17 silentwings New Issue
2016-12-23 23:59 Kloot Note Added: 0016995
2016-12-24 14:24 silentwings Note Added: 0016997
2016-12-24 15:26 Kloot Note Added: 0016998
2016-12-24 15:29 Kloot Assigned To => Kloot
2016-12-24 15:29 Kloot Status new => assigned
2016-12-24 17:04 Changeset attached => spring develop 0df5fb56
2016-12-24 17:04 Anonymous Note Added: 0016999
2016-12-24 17:04 Anonymous Status assigned => resolved
2016-12-24 17:04 Anonymous Resolution open => fixed
2016-12-24 19:59 hokomoko Note Added: 0017000
+Issue History