473,397 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Non repeating random images

I want to display 4 random images but not have duplicates. So if image one is "aceclubs.png" I don't want image two to be the same thing.
I've been duplicating this script with different function names for all four images, but sometimes they return the same image and I don't want that. Is there a way to put it all in one function?

(sorry for the newbiness of this question and/or bad formatting of the code. I'm new to this)
Any help greatly appreciated.

Expand|Select|Wrap|Line Numbers
  1. function random_cards(){
  2.  
  3.     var cardace = new Array(4)
  4.  
  5.     cardace[0] = "aceclubs.png";
  6.     cardace[1] = "acediamonds.png";
  7.     cardace[2] = "acehearts.png";
  8.     cardace[3] = "acespades.png";
  9.  
  10.     var randomace = Math.floor(Math.random()*cardace.length);
  11.  
  12.     var ace = cardace[randomace];
  13.  
  14.     card1.src=ace
Oct 11 '10 #1
1 1542
RamananKalirajan
608 512MB
Hi,
Your script for generating a rondom number works fine. I want to know about the vaiable card1. Have you defined this variable globally?

Thanks and Regards
Ramanan Kalirajan
Oct 11 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: LRW | last post by:
For an e-commerce site, I'm wanting to have it pull 4 random images for the front page from a select list of items from the DB. I can get it to pull randomly and place the images, but I can't...
2
by: Dr. Lince M. Lawrence | last post by:
In my web site. I am having three set of random images (of three each). I am not able to get the images displayed in certain browsers, running on WINDOWS. Is there any specific reasons for this?...
1
by: rene willemsen | last post by:
hi all, is there sombody who can helpme witht he following, i am ''pretty new'' to php and am looking for a script to show images randomly at a 10/ 15 seconds interval. is there anybody who can...
1
by: Sandy Bremmer | last post by:
I have seen many Javascripts that rotate images with each load or refresh of the page but so far all I've found require hard coding the image filename into the script. Does anyone know of a script...
9
by: Michael Burtenshaw | last post by:
I would like to make a slide show using random images. The problem is my host is 250.com, and they don't support cgi-programs. Is there another way to accomplish random images?
2
by: vbMark | last post by:
Hello, I am trying to set up a page that will show a random image of something on a web page (e.g. cats) taken from a random Google Image. I can't find any sample code to do this. Can someone...
3
by: Simon | last post by:
This problem has been driving me mad for months.... Seen a few posts on forums about it but no answers... No mention on MSDN etc. XP Pro SP1, VS.NET (c#) .Net framework 1.1, IIS 5.1. In a...
8
by: Brian McCabe | last post by:
hello - I am very new to javascript and have a pretty tight deadline (as in, today!) in getting a new version of a page released. The built-in ASP feature that allows for any one of a series of...
1
by: Sahus Pilwal | last post by:
Hi, I hope someone can help me with this. I'm new to .NET and in fact server side programming and have a small query I'm sure... I'm using the System.IO Namespace with a For - each and If then...
0
by: Killer42 | last post by:
This is a simple VB6 function to generate random numbers in the specified range, without repeating any numbers. New, and only briefly tested. Use at your own risk. :) Option Explicit Private...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.