lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Sun, 17 Jan 2010 20:59:41 +0100
Wolfgang Pupp <> wrote:

> Btw., is there some decent, "resumable"- RNG for Lua around?
> What I want is essentially a "getrandomseed", which returns the
> current seed and can thus be used for resuming the generation of
> random numbers later, with perfectly predictable output.

You can do this with a cryptographic hash.  For each "number" you want
out, hash together your seed and an index.  Should you ever want the
same index again, just hash the seed and index again.  Want the next
number in the sequence?  Increase the index.  Etc.

Should be easy to implement this in Lua using an off-the-shelf hash
library.  (like lmd5).