Gossamer Forum
Home : General : Perl Programming :

unique string

Quote Reply
unique string
Does anybody now how to generate a string 'at random' like:

"KHGJJKHJkgsahjhvdsjcty78vn4756q8uymnuinbdtynhxjkhdsfhavfgdsjaxh"



Quote Reply
Re: unique string In reply to
Try;

@array = (a-zA-Z);
foreach (20) # Set to the number of random letters you need
{
$rand = int(rand scalar(@array));
print "$array[$rand]";
splice(@array,$rand,1);
}

The above should work...

Andy

http://www.ace-installer.com
webmaster@Ace-installer.com
Quote Reply
Re: unique string In reply to
Andy - double check the code -- it isn't right.


Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: unique string In reply to
Ok, maybe it wasn't exactly right....lol...had a go though...Cool

Andy

http://www.ace-installer.com
webmaster@Ace-installer.com
Quote Reply
Re: unique string In reply to
Had a go with a modified version of the code that I gave you :)

Paul Wilson.
Installations:
http://www.wiredon.net/gt/
Quote Reply
Re: unique string In reply to
no need to splice the array since it doesn't matter if characters are duplicated. not to mention if they want a string greater than 52 characters in your example it won't work.
Code:
$a.= (a..z,A..Z,0..9)[int(rand(62))] for (1..30);
-g


s/(\d{2})/chr($1)/ge + print if $_ = '8284703280698276687967';
Quote Reply
Re: unique string In reply to
Wauw; thanks!

It seems to work perfect.

- Chris