Solved

Random

Posted on 1997-10-18
3
301 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
Comment Utility
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
Comment Utility
Sorry, need more of an explaination. This is 600 points ya know...
0
 
LVL 1

Accepted Solution

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Why do we like using grid based layouts in website design? Let's look at the live examples of websites and compare them to grid based WordPress themes.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…

762 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

12 Experts available now in Live!

Get 1:1 Help Now