Synced randomness?
Moderator: Moderators
Synced randomness?
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?
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?
- TheFatController
- Balanced Annihilation Developer
- Posts: 1177
- Joined: 10 Dec 2006, 18:46
Re: Synced randomness?
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?
Have you tested it or it's just a though? Because there is no reason that the synced random number generator behave like thatKDR_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?
.
Re: Synced randomness?
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?
guess the seed isn't used or is always the same. looks like a simple one-line omission.
Re: Synced randomness?
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.
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?
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.