Difference between revisions of "Random Password Generator"

From Second Life Wiki
Jump to navigation Jump to search
(fixed wrong interpretation of llFrand)
Line 3: Line 3:
// Generate Passwords based on String length
// Generate Passwords based on String length
// Free to use, share and remix.
// Free to use, share and remix.
//
// http://foravatars.com


string randomPassword(integer length)
{
    string characters = "abcdefghijkmnopqrstuvwxyz234567890";
    string passwordToBeReturned;


string randomPass(integer length)  {
     while(llStringLength(rPass) < length)
    string letters = "abcdefghijkmnopqrstuvwxyz234567890";
    {
    string rPass;
        // because llFrand is [0, mag)
     while(llStringLength(rPass) < length)   {
        integer upperLimit = llStringLength(letters) + 1;
         integer rand = llFloor(llFrand(llStringLength(letters)));
         integer rand = llFloor(llFrand(upperLimit));
         rPass += llGetSubString(letters,rand,rand);
 
         passwordToBeReturned += llGetSubString(letters, rand, rand);
     }
     }
     return rPass;
 
     return passwordToBeReturned;
}
}
 
default
default
{
{
     state_entry()
     state_entry()
     {
     {
         llSay(0,randomPass(10));
        // PUBLIC_CHANNEL has the integer value 0
         llSay(PUBLIC_CHANNEL, randomPassword(10));
     }
     }
}
}
</lsl>
</lsl>

Revision as of 13:37, 7 October 2012

Code: <lsl> // Generate Passwords based on String length // Free to use, share and remix.

string randomPassword(integer length) {

   string characters = "abcdefghijkmnopqrstuvwxyz234567890";
   string passwordToBeReturned;
   while(llStringLength(rPass) < length)
   {
       // because llFrand is [0, mag)
       integer upperLimit = llStringLength(letters) + 1;
       integer rand = llFloor(llFrand(upperLimit));
       passwordToBeReturned += llGetSubString(letters, rand, rand);
   }
   return passwordToBeReturned;

}

default {

   state_entry()
   {
       // PUBLIC_CHANNEL has the integer value 0
       llSay(PUBLIC_CHANNEL, randomPassword(10));
   }

} </lsl>