[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

Random

I need a random thing for my page. I need to have like 4 random events that can happen.
For each random event, I need a random picture displayed out of a list of 4 pictures. Can someone explain to me how to do this???
0
devinm
Asked:
devinm
1 Solution
 
clambakeCommented:
Since you are not asking this on the CGI question area I assume you would rather do this on the client side than on the server side (like javascript instead of perl).

Here is how I would do this:

Every n seconds we generate a random number.  If the random number equals 1, 2, 3, or 4 then we will display the appropriate image.  If the random number generated is 5 or higher, then do nothing.  

Since it is a little lengthy, I have posted an example on line instead of pasting it all here.  It is at:

http://www3.onanalysis.com/dev/rand/

View the source... hopefully this is what you are looking for.
0
 
devinmAuthor Commented:
Sorry, need more of an explaination. This is 600 points ya know...
0
 
gabsiCommented:
# Getting the date as number
chop ($dt=`date +"%j%S"`);
        $al=$dt%$nb;
# I get my images directory
open (LISTE,"ls -l mages/*.gif|") || die $!;
@tab=<LISTE>;
close (LISTE);
$nl=$#tab;
#nl = the numbger of images

$rando=$dt%$nl;

$ligne=@tab[$rando];
$ligne=~ s/\n//g;
print "<P><IMG SRC=images/$ligne><P>\n";

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now