Synced randomness?

Synced randomness?

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

Moderators: Moderators, Moderators

Post Reply
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Synced randomness?

Post by KDR_11k »

If I use the synced random number generator it will produce the same results for every game, is there a way to prevent that?
0 x

User avatar
ILMTitan
Spring Developer
Posts: 410
Joined: 13 Nov 2004, 08:35

Re: Synced randomness?

Post by ILMTitan »

It does? For some reason I thought that a random seed was sent out to all of the clients before the game started, or does Lua use a different synced random number generator?
0 x

User avatar
TheFatController
Balanced Annihilation Developer
Posts: 1177
Joined: 10 Dec 2006, 18:46

Re: Synced randomness?

Post by TheFatController »

a hackish workaround would be have it generate a load of random numbers in a loop at the start with the size based off everyones start position or ping or something.. :P
0 x

Torrasque
Posts: 1022
Joined: 05 Oct 2004, 23:55

Re: Synced randomness?

Post by Torrasque »

KDR_11k wrote:If I use the synced random number generator it will produce the same results for every game, is there a way to prevent that?
Have you tested it or it's just a though? Because there is no reason that the synced random number generator behave like that
.
0 x

User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Synced randomness?

Post by KDR_11k »

It's behaving like that, I'm placing a fixed number of planets at random positions in gadget:Initialize() but the resulting positions are the same every time.
0 x

imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Re: Synced randomness?

Post by imbaczek »

guess the seed isn't used or is always the same. looks like a simple one-line omission.
0 x

Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Synced randomness?

Post by Kloot »

The synced RNG indeed always uses the same seed (18655),
CGame should probably set it to time(0) before broadcasting.

edit: it depends on when and in what context (mod or non-mod)
your gadget is initialized. If the gadget is part of a mod, then its
Initialize() function will be called before CGameServer sends out
the actual seed (CGame only broadcasts 18655 as a temporary
number [*after* gadget initialization is done], even though every
client already knows it), so the RNG naturally generates identical
sequences every time. If however you load it via .devlua at some
frame > 0, then the true final seed sent by the server will already
have been set and the sequences are different.
0 x

User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Re: Synced randomness?

Post by KDR_11k »

Can we change the order of those events? I'd hate to have the planets not show up until after all start positions are placed.
0 x

Post Reply

Return to “Lua Scripts”