Solved

Random

Posted on 1997-10-18
3
304 Views
Last Modified: 2013-12-25
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
Comment
Question by:devinm
3 Comments
 
LVL 1

Expert Comment

by:clambake
ID: 1855292
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
 

Author Comment

by:devinm
ID: 1855293
Sorry, need more of an explaination. This is 600 points ya know...
0
 
LVL 1

Accepted Solution

by:
gabsi earned 600 total points
ID: 1855294
# 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
The Best Website Creation Tools 14 74
Scientific articles behind a login? 6 32
What does GoogleTagMgr javascripts below do 5 35
Website Question - New Site 3 13
"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
The viewer will learn how to dynamically set the form action using jQuery.
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question