Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > Code Gallery
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 12-30-2008, 12:56 AM
LoneAngelIbesu LoneAngelIbesu is offline
master of infinite loops
LoneAngelIbesu's Avatar
Join Date: May 2007
Location: Toldeo, Ohio
Posts: 1,049
LoneAngelIbesu has a spectacular aura aboutLoneAngelIbesu has a spectacular aura about
Send a message via AIM to LoneAngelIbesu
randomstring2

randomstring2(source, limit, repeat); - returns a random string with the length of limit, derived from character in the source array, repeating characters if set to true.
- source: an array of single characters
- limit: a positive number, indicating the size of random string output
- repeat: boolean, indicating whether or not to repeat characters
PHP Code:
function randomstring2(sourcelimitrepeat) {
  if(
temp.limit == null) {
    
temp.limit temp.source.size();
  }
  if(
temp.limit temp.source.size()) {
    
temp.limit temp.source.size();
  }
  while(
temp.temp.limit) {
    
temp.trial temp.source[random(0temp.source.size())];
    if(
temp.repeat) {
      
temp.output @= temp.trial;
      
temp.i++;
    }
    else {
      if(
temp.output.pos(temp.trial) < 0) {
        
temp.output @= temp.trial;
        
temp.i++;
      }
    }
  }
  return 
temp.output;

All possible source characters:
PHP Code:
  temp.source = {
    
"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""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""0""1""2""3",
    
"4""5""6""7""8""9""!""@",
    
"#""$""%""^""&""*""("")",
    
"[""]"";"":""'""<"">"".",
    
",""?""/""-""_""=""+""|"
  
}; 
Example:
PHP Code:
function onCreated() {
  
temp.source = {
    
"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""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""0""1""2""3",
    
"4""5""6""7""8""9""!""@",
    
"#""$""%""^""&""*""("")",
    
"[""]"";"":""'""<"">"".",
    
",""?""/""-""_""=""+""|"
  
};
  echo(
randomstring2(temp.source10true));
  echo(
randomstring2(temp.source10false));

Outputs:
Quote:
wcuA7vw,Cr
zeC@-K;QP)
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan

Last edited by Tolnaftate2004; 01-07-2009 at 06:13 PM.. Reason: by request
Reply With Quote
 


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:06 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.