[Kde-games-devel] Reproducing random numbers

Ian Wadham ianw2 at optusnet.com.au
Tue Apr 14 07:29:19 CEST 2009


On Mon, 13 Apr 2009 6:50:18 pm Kevin Krammer wrote:
> On Monday 13 April 2009, Ian Wadham wrote:
> > ... but how do you get a replayed level to run exactly
> > the same as when it was recorded?  Random number generators
> > appear to have no way to "read out" a seed.  The solution adopted
> > was to generate a random integer when "live" play of a level is about to
> > start, then re-inject that number as the seed and also save it in the
> > "recording".  When playing back the recording, read in and use the
> > same seed.  This seems a bit dodgy, but it works.
>
> I think it is still based on too many assumptions for a reliable replay
> feature.
> While it is true that pseudo random generators such as rand() will generate
> the same sequence when being seeded with the same value, there is AFAIK no
> gurantee that the algorithm stays the same during system upgrades, or
> generates the same sequence on a different device or platform (assuming
> recordings can be copied).
>
That is an excellent point.  Thanks, Kevin.

> In case you are using the same random value to control more than one
> aspect, e.g. to determine the direction of more than one enemy, you might
> want to record the values as you retrieve them.
>
So I will have to do that at least.  I plan to rely on the feature for
(cross-platform and into-the-future) demos and tutorials - plus some
other things.

> If one random value is only used for one decision, you could think about
> recording the decision instead.
>
I was hoping to avoid that (using the KISS principle).  I am trying to get a
reproducible playback from just the player's inputs and the random number
stream.  Another approach might be to record the outputs (sprite moves)
and make the playback a movie, rather than actual play.

Thanks again, Kevin.  All the best, Ian W.





More information about the kde-games-devel mailing list