Don't click here unless you want to be banned.

LSL Wiki : Example32BitHash

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl338.us.archive.org
The need often arises that you need to reduce an agent key or other string into a 32 bit hash. This happens a lot because on_rez can only pass the new object an integer as a parameter, and you might need to pass it information on which agent to act on, or respond to.

This function will hash data into an integer so that you can pass it to an object via on_rez. Of course you can't jam 128 bits or more of data into 32 without collisions, but the chances of a collision are usually slim, depending on the application. Beware possible birthday problem implications if you plan to use this to construct a list.

It's actually probably not necessary to MD5 an agent's key before extracting the first 4 bytes, because UUIDs are pretty evenly distributed, but this way is easier to convert to handling arbitrary string data. You will definitely want to MD5 any strings other than UUIDs.

integer keytoint(string inkey)
{
    return (integer)("0x" + llGetSubString(llMD5String(inkey,0), 0, 7));   
}

Examples
There is no comment on this page. [Display comments/form]