Non repeating random images

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Larry Lanscott
    New Member
    • Oct 2010
    • 1

    #1

    Non repeating random images

    I want to display 4 random images but not have duplicates. So if image one is "aceclubs.p ng" 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.

    Code:
    function random_cards(){
    
    	var cardace = new Array(4)
    
    	cardace[0] = "aceclubs.png";
    	cardace[1] = "acediamonds.png";
    	cardace[2] = "acehearts.png";
    	cardace[3] = "acespades.png";
    
    	var randomace = Math.floor(Math.random()*cardace.length);
    
    	var ace = cardace[randomace];
    
    	card1.src=ace
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    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

    Comment

    Working...