Random Password Generator

From Second Life Wiki
Jump to: navigation, search

Code:

// Generate Passwords based on String length
// Free to use, share and remix.
 
string randomPassword(integer length)
{
    string CharSet = "abcdefghijkmnpqrstuvwxyz23456789";    // omitting confusable characters
    string password;
    integer CharSetLen = llStringLength(CharSet);
    // Note: We do NOT add 1 to the length, because the range we want from llFrand() is 0 to length-1 inclusive
 
    while (length--)
    {     
        integer rand = (integer) llFrand(CharSetLen);
        password += llGetSubString(CharSet, rand, rand);
    }
    return password;
}
 
default
{
    touch_start(integer num)
    {
        llSay(0, randomPassword(10));
    }
}