Channel Number Generator

Written by: Headmaster

Creates rancom channels

 

//
// generateChannel(): Given a text string, generate a (relatively) unique channel number.
// This conversion is repeatable, so you can use it to easily communicate with a script by
// remembering a text string instead of a channel number.
//
// You can copy or modify this script if you give me credit.
// Petre Lamar, 2006-07-31
//
integer generateChannel(string text)
{
    list hexDigits = ["dummy", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"];
    string md5 = llMD5String(text, 0);
    integer length = llStringLength(md5);
    integer channelNumber = 1; // zero makes a bad multiplier :-)
    integer hexValue;
    string character;
        
    for (length--; length >= 0; length--)
    {
        character = llGetSubString(md5, length, length);
        hexValue = llListFindList(hexDigits, [ character ]);
        channelNumber *= hexValue;
        if (channelNumber == 0)
        {
            // zero times anything remains zero, so force it to one
            channelNumber++;
        }
    }

    return channelNumber;
}

default
{
    state_entry()
    {
        llWhisper(0, "Type something and I'll convert that into a channel number!");
        llListen(0, "", llGetOwner(), "");
    }

    listen(integer channel, string name, key id, string message)
    {
        integer result = generateChannel(message);
        llWhisper(0, "'" + message + "' yields '" + (string)result + "'");
    }
}

 

Category: