Talk:Seedable PRNG

From Second Life Wiki
Revision as of 12:32, 19 March 2007 by Gigs Taggart (talk | contribs) (stuff)
Jump to navigation Jump to search

Shouldn't prng_get update the seed? This works on the same principal as a script i wrote (Pseudo-Random Number Generator). Strife Onizuka 00:51, 19 March 2007 (PDT)

I don't think so, though it is interesting how similar mine came out to be to yours. I swear I wasn't looking at yours when I wrote this. :P Yours doesn't seem to generate random numbers, at least not in any way I'm used to calling random!
integer pseudo_random(string text, integer nonce, integer start, integer end)
{//(c)(cc-by) Strife Onizuka, http://creativecommons.org/licenses/by/2.5/
    return (integer)("0x"+llGetSubString(llMD5String(text, nonce), start, end));
}

string feed = "How much wood would a wood chuck chuck if a wood chuck could chuck wood?";

default
{
    state_entry()
    {
    }

    touch_start(integer next)
    {
        integer x;
        next = pseudo_random(feed, 30 * ((integer)llGetGMTclock() / 30), 0, 7);
        
        for (x=0;x<10;x++)
            llSay(0, (string)next);
    }
}

Output:

[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825
[12:19]  Object: 120920825


Mine has something yours doesn't have, it basically runs the MD5 in OFB mode by rehashing the previous hash over again. Gigs Taggart 12:32, 19 March 2007 (PDT)