Seedable PRNG

From Second Life Wiki
Revision as of 23:04, 18 March 2007 by Gigs Taggart (talk | contribs) (new PRNG in LSL)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

It's not the fastest thing but it doesn't seem to have much if any output skew, and I couldn't detect any periodicity in the first few thousand outputs. I'm doing extended periodicity testing now.


//new md5 based seedable PRNG
//By: Gigs Taggart
//Released under BSD License.
//http://www.opensource.org/licenses/bsd-license.php

integer gSeed=0; 
string gLastHash;

prng_seed(integer seed)
{
    gSeed=seed;
}


integer prng_get()
{
    gLastHash=llMD5String(gLastHash, gSeed);
    return (integer)("0x" + llGetSubString(gLastHash, 0, 7)) & 0x7FFFFFFF;  //the bitwise thingy gets rid of negative numbers
}