Sorry to be confused, but I believe I did not create a global variable. In
the code below that I showed, I used a my to localize the $tmp variable
inside the for loop.?

Anyway, I changed the simple code and added the use strict and use vars
qw($rand), but now I get no random activity at all. Each time a user hits
it, they of course receive the same 4 numbers. Not very random ....

I am sure I am screwing this up somehow, was anyone able to get this to
work, or able to get 4 random numbers each time they run the snippet of
code?

Thanks
Scott

-----Original Message-----
From: Gunther Birznieks [mailto:[EMAIL PROTECTED]]
Sent: Friday, July 06, 2001 6:22 PM
To: Purcell, Scott; '[EMAIL PROTECTED]'
Subject: Re: rand bug?


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