?
Solved

Random

Posted on 1997-10-18
3
Medium Priority
?
309 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

An enjoyable and seamless user experience can go a long way on an eCommerce site. While a cohesive layout and engaging copy play roles in creating a positive user experience, some sites neglect aspects that seem marginal but in actuality prove very …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Suggested Courses

770 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