Your problem is likely that the use of a global my is creating a closure 
(see mod_perl guide). Replace it with use vars qw($rand); and don't declare 
your globals using my.

At 01:07 PM 7/6/2001 -0500, Purcell, Scott wrote:
>Hello,
>
>rand bug with mod_perl?
>"my $rand = int(rand(1000)) always produces '2'" under mod_perl.
>I have noticed that if I ask for the line above, it always puts $rand at a
>'2'? So I did some test below, looping through and the first time through
>with mod_perl, the number is always 2?
>
>
>Under investigation when I run the following code under cgi-bin, it works
>good like it should.
>960 is tmp
>240 is tmp
>193 is tmp
>197 is tmp
>
>
>When I run that same code under mod_perl, it looks like this:
>2 is tmp
>564 is tmp
>194 is tmp
>809 is tmp
>
>So basically if I just need one random number I have to do some excess work?
>
>Does anyone know why this is?
>If anyone wants just drop the following line under cgi-bin and mod_perl and
>you'll see the results.
>
>Please let me know,
>Scott
>
>
>
>#! perl
>use CGI qw/:standard/;
>my $q = CGI->new;
>print $q->header();
>print $q->start_html("hello");
>foreach (my $i=1; $i<5; $i++) {
>     my $tmp = int(rand(1000)+1);
>     print "$tmp is tmp<br>\n";
>}
>
>
>Scott Purcell

__________________________________________________
Gunther Birznieks ([EMAIL PROTECTED])
eXtropia - The Open Web Technology Company
http://www.eXtropia.com/

Reply via email to