Results 1 to 6 of 6

Thread: including randomizer

  1. #1
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default including randomizer

    hello everyone
    i'm using this javascript on my homepage
    http://www.dynamicdrive.com/dynamici...nslideshow.htm
    and i'm wondering if anyone knows how to include a randomizer (Math.floor(Math.random()" ) something like this i suppose.
    really hope you can help me out with this

    rgds,
    chris

  2. #2
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Please search for previous posts before asking questions:

    Fade-in Slideshow: random display of images how-to

    It save you, and everyone else, time.

    Mike

  3. #3
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    well, thanks for the link
    the first two pictures are choosen randomly, but than it sets it on the 4th picture and continues in line down the last one....

    chris

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,070
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    I've used mwinter's excellant randomizing unit on more than several scripts to randomize their arrays, either onload or each time an image is requested by the script. Keep in mind that random means random and can look ordered at times. If something else is at work here, we need to see your code to figure out the problem. Just to be clear, it is post number 6 from the above thread mentioned by Mike that contains the fully formed randomizing unit and it must be used as he describes in that post.

    PLEASE: Include the URL to your problematic webpage that you want help with.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Sep 2005
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    hello together
    well here's the test page with the randomizer
    http://chrisgalliker.lucienschranz.com/index.htm
    it randomizes the first two but than continues with then continues in row with the Singapore 747, america west 757, and so on....

    rgds,
    chris

  6. #6
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,070
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Replace:
    Code:
    var randomizeimage="yes" //randomize dislay order of images? "yes" or "no"
    
    function shuffleit(){ 
    return Math.floor((Math.random()*fadeimages.length-1)) 
    }
    
    if (randomizeimage=="yes")
    fadeimages.sort(shuffleit)
    with:
    Code:
    var randomizeimage="yes" //randomize display order of images? "yes" or "no"
    
    function random(n) {
      return Math.floor((Math.random() % 1) * n);
    }
    
    Array.prototype.shuffle = function() {var i = this.length;
      while(i--) {this.swap(i, random(i + 1));}
    };
    Array.prototype.swap = function(x, y) {
      var t = this[x]; this[x] = this[y]; this[y] = t;
    };
    
    if (randomizeimage=="yes")
    fadeimages.shuffle()
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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