Difference between revisions of "RandomString"

From Second Life Wiki
Jump to navigation Jump to search
(Creation of RandomString function)
 
Line 48: Line 48:
|also_articles
|also_articles
|cat1=Examples
|cat1=Examples
|cat2
|cat2=UD Functions
|cat3
|cat3
|cat4
|cat4
}}
}}

Revision as of 16:38, 24 May 2010

Summary

Function: string RandomString( integer length );

Returns a string that is made up of random letters and numbers based on the length given.

• integer length List of Random String

See also: String

Specification

<lsl>//This version provides random numbers and letters string RandomString(integer length) { list characters = ["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; string emp; integer p;

   do{
      emp += llList2String(characters, llRound(llFrand(llGetListLength(characters) - 0 + 1 )));
   }
   while(length > ++p);                                                    
   return emp;

}</lsl>

<lsl>//This version is only strings string RandomString(integer length) { list characters = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]; string emp; integer p;

   do{
      emp += llList2String(characters, llRound(llFrand(llGetListLength(characters) - 0 + 1 )));
   }
   while(length > ++p);                                                    
   return emp;

} </lsl>

Caveats

  • The random String is created using the list, if you want to restrict some letters, or add more characters just add to the list.

Examples

<lsl> default {

   touch_start(integer total_number)
   {
       llSay(0, RandomString(10));
   }

}

//Says something like fvl3d2zv4z</lsl>