[ale] Perl random

Christopher Fowler cfowler at outpostsentinel.com
Fri Apr 16 09:10:14 EDT 2004


This seems to do the trick

#!/usr/bin/perl
my $bits = 1024;
$ITER = ($bits / 8); # number of bytes
my $string = "";
for(my $i = 0; $i != $ITER; $i++) {
        $s = sprintf "%0X", int(rand(256));
        $string = $string.$s;
}


printf $string;

On Fri, 2004-04-16 at 08:48, Christopher Fowler wrote:
> This will gen the number.
> 
> #!/usr/bin/perl
> 
> $ITER = 20;
> my $string = "";
> for(my $i = 0; $i != $ITER; $i++) {
>         $string = $string."".int(rand(9));
> }
> 
> print $string;
> 
> 
> On Fri, 2004-04-16 at 08:34, Christopher Fowler wrote:
> > I want to create session ids to be stored as cookies for use in my PERL
> > CGI programs.  The IDs will be store in SQLlite with a key into a table
> > that lists all the name value pairs for that session.  What I want to do
> > is randomly generate a 64bit number and then convert it into a hex
> > string.  This string will be 128 characters long.  I will then set that
> > string as the session id in the cookie and insert it into the table.
> > 
> > What is the best way to generate the number and convert to hex?
> > 
> > Thanks,
> > Chris
> > 
> > _______________________________________________
> > Ale mailing list
> > Ale at ale.org
> > http://www.ale.org/mailman/listinfo/ale
> 
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale



More information about the Ale mailing list