Gossamer Forum
Home : Products : Gossamer Links : Version 1.x :

Random number

Quote Reply
Random number
For those using the random numbers, I've been trying to use standard headers, include files, etc. and have found some oddities with it.

defining the random, random1, etc in the HTML_Templates.pm file in the %GLOBALS hash only goes so far. Many pages are built with the same "random" numbers.

The common output of the all the templates is the &load_template routine in the DB_Utils.pm file (not the Templates.pm).

So, in the sub load_template routine, just after the declared variables at the top, I added:


Code:
$vars->{random1} = int rand (64000);
$vars->{random2} = int rand (64000);
$vars->{random3} = int rand (64000);
.
And that seemed to give a unique random number to each of the <%random1%> etc tags.

To _just_ generate a random number that is used in only ONE place (not in several, the way most banner code requires) you can use a %GLOBALS entry such as:

random => sub { return int rand (64000); },

That will generate a different random number each time -- even in the same template.

So far it's working....

Wonder how I missed this quirk the first 10 times around.

What I was seeing was the same "random" ID in all the "NEW" pages, COOL page, etc. when I used the same <%include banner_top.inc%> file. Putting the random number generation INSIDE the load_template call makes sure fressh random numbers are served up each time.

I wonder how that will affect my display stats now that all the pages _really_ have unique ID's on them!




http://www.postcards.com
FAQ: http://www.postcards.com/FAQ/LinkSQL/