Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2004
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    randomising images in a table

    Hiya

    I have a 4x4 table and i have 16 set images to appear in each of the cells. How do i code a function so that the images appear in a randomise fashion when a button on the website is clicked

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Code:
    Array.prototype.swap = function(index1,index2)
      { var temp = this[index1];
        this[index1] = this[index2];
        this[index2] = temp;
        return;
      }
    
    Array.prototype.shuffle = function()
      { for(var i=0; i<this.length; i++)
          { ind1 = Math.floor(Math.random()*this.length);
            ind2 = Math.floor(Math.random()*this.length);
            this.swap(ind1,ind2);
          }
        return;
      }
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •