View Single Post
Old 06-14-2012, 03:02 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Shuffle the arrat and then grab as many as you need off the front.


Code:
Array.prototype.shuffle = function() {
   var s = [];
   while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
   while (s.length) this.push(s.pop());
   return this;
}; 

function random_imglink(){
  var myimages = []
    myimages[1] = "01.jpg"
    myimages[2] = "02.jpg"
    myimages[3] = "03.jpg"
    myimages[4] = "04.jpg"
    myimages[5] = "05.jpg"
    ...
    myimages[31] = "31.jpg"

myimages.shuffle();
   
    var rq = myimages[0];
    var rr = myimages[1];
// ... etc
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Users who have thanked felgall for this post:
sg123 (06-14-2012)