Random Password Generator

From Second Life Wiki
Revision as of 06:10, 9 August 2013 by Hank Ramos (talk | contribs) (characters variable incorrect on several lines)
Jump to navigation Jump to search

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

string randomPassword(integer length) {

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

}

default {

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

} </lsl>