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

LSL Wiki : LibraryUUIDChannelUnique

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are ia360925.us.archive.org

Library Unique Channel per UUID

I wanted to create a random channel for a UUID. A channel that could be generated over and over by the same object that would remain the same. Though I'm not sure if this is fool-proof, I've come up with this.

//
// randomKeyPerUUID();
//
// This creates a random channel for any given UUID, for example used in this script is the Object's UUID.
// This script may be modified, improved, whatever. Just keep this in the credits to show that I created the original script.
// Written: Zachary Carter (18 December 2007)
//

integer randomChannelUUID()
{
    llResetTime();
    list characters = ["NULL", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f", "-"];
    string uuid = (string)llGetKey();
    
    float genChannel = -2147483647.0 / 4;
    
    string mathOp = "+";
    integer x;
    
    for(x = 0; x < llStringLength(uuid); x++)
    {
        float where = (float)llListFindList(characters, [llGetSubString(uuid, x, x)]);
        
        if(mathOp == "+")
        {
            genChannel += where;
            mathOp = "*";
        }
        else if(mathOp == "-")
        {
            genChannel -= where;
            mathOp = "-";
        }
        else if(mathOp == "*")
        {
            genChannel *= where;
            mathOp = "/";
        }
        else if(mathOp == "/")
        {
            genChannel /= where;
            mathOp = "+";
        }
    }
    
    do
    { 
        genChannel /= 2.0;
    }
    while(genChannel > 2147483647.0 || genChannel < -2147483647.0);
    
    return llRound(genChannel);
}

default
{
    state_entry()
    {
        llSay(0, "I generated the channel (" + (string)randomChannelUUID() + ") from the UUID (" + (string)llGetKey() + ") in " + (string)llGetTime() + " seconds!");
    }
}
There is no comment on this page. [Display comments/form]