Solved

Random

Posted on 1997-10-18
3
302 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This video teaches users how to migrate an existing Wordpress website to a new domain.
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…

863 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

Need Help in Real-Time?

Connect with top rated Experts

28 Experts available now in Live!

Get 1:1 Help Now