Graal Forums  

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

Reply
 
Thread Tools Search this Thread Display Modes
  #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
  #2  
Old 12-30-2008, 02:01 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Seems like it would be easier & a little safer to do something like:
PHP Code:
temp.source "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz013456789!@#$^&*()_+[]/,?.|;:";
temp.limit 25;
temp.repeat false;
temp.output "";

for (
temp.0temp.limittemp.++) {
  
temp.randomout source.charat(int(random(0source.length())));
  if (!
repeat && output.pos(randomout) >= 0) {
    if (
limit <= source.length()) {
      
temp.--;
      continue;
    }else
      break;
  }
  
temp.output @= randomout;
}

return 
output
Otherwise it's nice
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”

Last edited by Tigairius; 12-30-2008 at 02:13 AM..
Reply With Quote
  #3  
Old 12-30-2008, 02:39 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
Quote:
Originally Posted by Tigairius View Post
Seems like it would be easier & a little safer to do something like:
What's the upside to using a string, rather than an array? I imagine that an array offers the possibility of using multiple-character bits, instead of just single character bits.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #4  
Old 12-30-2008, 02:53 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by LoneAngelIbesu View Post
What's the upside to using a string, rather than an array? I imagine that an array offers the possibility of using multiple-character bits, instead of just single character bits.
No upside to using a string, I just didn't feel like doing temp.source = {"A", "B", "C", etc};
I think it's generally bad practice to use a while() loop where a for() loop can be used, and right now it doesn't look like you have any loop protection, so if you input incorrect parameters you can break the loop limit.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #5  
Old 12-30-2008, 12:14 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Tigairius View Post
No upside to using a string, I just didn't feel like doing temp.source = {"A", "B", "C", etc};
I think it's generally bad practice to use a while() loop where a for() loop can be used, and right now it doesn't look like you have any loop protection, so if you input incorrect parameters you can break the loop limit.
Well... His custom title do say master of infinite loops.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #6  
Old 12-31-2008, 03:35 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
Quote:
Originally Posted by Tigairius View Post
No upside to using a string, I just didn't feel like doing temp.source = {"A", "B", "C", etc};
I think it's generally bad practice to use a while() loop where a for() loop can be used, and right now it doesn't look like you have any loop protection, so if you input incorrect parameters you can break the loop limit.
I did use a for() loop, originally. However, that results in temp.i increasing, even though nothing is added to temp.output. That results in outputs that aren't the length defined by temp.limit.

Also, I have no clue what "loop protection" is. A search leads only to this topic.
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
  #7  
Old 12-31-2008, 04:46 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by LoneAngelIbesu View Post
Also, I have no clue what "loop protection" is. A search leads only to this topic.
Right now your while loop will go in to an infinite loop if your input limit is greater than the array size of the source.
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #8  
Old 12-31-2008, 04:56 AM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by Tigairius View Post
Right now your while loop will go in to an infinite loop if your input limit is greater than the array size of the source.
If repeat is true then it will do that. Easy fix would be to return when output size equals source size
__________________
Reply With Quote
  #9  
Old 12-31-2008, 06:28 AM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Chompy View Post
If repeat is true
Yes, that's what I meant
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #10  
Old 12-31-2008, 03:47 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
There is no reason to make a password longer than 8 chars, is there?
Reply With Quote
  #11  
Old 12-31-2008, 04:17 PM
[email protected] sid.gottlieb@googlemail.com is offline
Banned
Join Date: Mar 2008
Posts: 861
sid.gottlieb@googlemail.com will become famous soon enough
not only for passes i suppose.
however, for password purposes I would prefer if the player was to write a password to remember, nothing generated...
Reply With Quote
  #12  
Old 12-31-2008, 04:58 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by [email protected] View Post
not only for passes i suppose.
however, for password purposes I would prefer if the player was to write a password to remember, nothing generated...
I prefer generated. If I have to choose a password myself, I always use one of my generated ones. Since most of them use lowercase letters, uppercase letters and numbers, and some even use additional special symbols, it takes longer to bruteforce them
Reply With Quote
  #13  
Old 12-31-2008, 05:40 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
bruteforcing a 8 letter password takes about 2-3 years
Reply With Quote
  #14  
Old 12-31-2008, 06:52 PM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
I agree that arrays are terrible for this sort of thing, simply because of the time it takes to set them up. I much prefer strings.
Reply With Quote
  #15  
Old 12-31-2008, 06:56 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
Quote:
Originally Posted by Pelikano View Post
bruteforcing a 8 letter password takes about 2-3 years
Please inform yourself about things you don't know about before posting anything.
Reply With Quote
  #16  
Old 12-31-2008, 08:54 PM
Pelikano Pelikano is offline
Registered User
Pelikano's Avatar
Join Date: Oct 2008
Posts: 1,133
Pelikano has a little shameless behaviour in the past
xD
Reply With Quote
  #17  
Old 12-31-2008, 10:05 PM
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
Quote:
Originally Posted by Tigairius View Post
Right now your while loop will go in to an infinite loop if your input limit is greater than the array size of the source.
Oh, I see. Perhaps something like this?
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;

Quote:
Originally Posted by DustyPorViva View Post
I agree that arrays are terrible for this sort of thing, simply because of the time it takes to set them up. I much prefer strings.
Well, I provided a source array that contains all possible single characters. So, it shouldn't take too much time to edit it, if you're simply looking to generate something from a list of single characters. Arrays offer the possibility of doing something like this:
PHP Code:
function onCreated() {
  
temp.source = {
    
"test",
    
"sources",
    
"foo bar",
    
"foo bar baz",
    
"foo!bar!baz"
  
};
  echo(
randomstring2(temp.source3true));
  echo(
randomstring2(temp.source3false));

Which outputs:
Quote:
foo!bar!bazfoo bar bazsources
sourcestestfoo bar baz
__________________
"We are all in the gutter, but some of us are looking at the stars."
— Oscar Wilde, Lady Windermere's Fan
Reply With Quote
Reply


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 12:59 AM.


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