Page 1 of 1
Synced randomness?
Posted: 09 Mar 2008, 11:33
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?
Re: Synced randomness?
Posted: 09 Mar 2008, 12:06
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?
Re: Synced randomness?
Posted: 09 Mar 2008, 12:32
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..

Re: Synced randomness?
Posted: 09 Mar 2008, 13:25
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
.
Re: Synced randomness?
Posted: 09 Mar 2008, 16:15
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.
Re: Synced randomness?
Posted: 09 Mar 2008, 20:15
by imbaczek
guess the seed isn't used or is always the same. looks like a simple one-line omission.
Re: Synced randomness?
Posted: 09 Mar 2008, 21:37
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.
Re: Synced randomness?
Posted: 10 Mar 2008, 18:59
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.