Difference between revisions of "RandKey"

From Second Life Wiki
Jump to navigation Jump to search
(more free code)
 
m (<lsl> tag to <source>)
 
(2 intermediate revisions by 2 users not shown)
Line 10: Line 10:
* LSO: 366 bytes
* LSO: 366 bytes
* MONO: 1536 bytes
* MONO: 1536 bytes
<lsl>key uRandKey(){
<source lang="lsl2">key uRandKey(){
     integer vIntHex;
     integer vIntHex;
     integer vIntChr = 32;
     integer vIntChr = 32;
Line 28: Line 28:
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                --//*/</lsl><!-- Please do not remove license statement -->
/*//--                                                                --//*/</source><!-- Please do not remove license statement -->
}}
 
{{void-box
|title=Caveats
|content=
{{LSL Tip|This function is of limited use since the addition of [[llGenerateKey]]. only use this if you absolutely ''need'' a completely random key, rather than a unique one.}}
}}
}}
[[Category:LSL_User-Defined_Functions]]
[[Category:LSL_User-Defined_Functions]]

Latest revision as of 15:32, 22 January 2015

User-Defined Function: key uRandKey();

Returns a random key.


Code:

  • LSO: 366 bytes
  • MONO: 1536 bytes
key uRandKey(){
    integer vIntHex;
    integer vIntChr = 32;
    string  vStrHex = "0123456789abcdef";
    do{
        vStrHex += llGetSubString( vStrHex, vIntHex = (integer)llFrand( 16.0 ), vIntHex );
    }while (--vIntChr);
    return
      (key)(llGetSubString( vStrHex, 0xFFFFFFE0, 0xFFFFFFE7 ) + //-- (-32, -25)
      "-" + llGetSubString( vStrHex, 0xFFFFFFE8, 0xFFFFFFEB ) + //-- (-24, -21)
      "-" + llGetSubString( vStrHex, 0xFFFFFFEC, 0xFFFFFFEF ) + //-- (-20, -17)
      "-" + llGetSubString( vStrHex, 0xFFFFFFF0, 0xFFFFFFF3 ) + //-- (-16, -13)
      "-" + llGetSubString( vStrHex, 0xFFFFFFF4, 0xFFFFFFFF )); //-- (-12, -1)
}
/*//--                       Anti-License Text                         --//*/
/*//     Contributed Freely to the Public Domain without limitation.     //*/
/*//   2009 (CC0) [ http://creativecommons.org/publicdomain/zero/1.0 ]   //*/
/*//  Void Singer [ https://wiki.secondlife.com/wiki/User:Void_Singer ]  //*/
/*//--                                                                 --//*/

Caveats

KBcaution.png Important: This function is of limited use since the addition of llGenerateKey. only use this if you absolutely need a completely random key, rather than a unique one.