View Single Post
Old 06-14-2012, 02:01 AM   PM User | #1
sg123
New to the CF scene

 
Join Date: Jun 2012
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
sg123 is an unknown quantity at this point
Question Help with multiple random images

Here's the code I slightly modified from the source found on javascriptkit.com:

Code:
<script>
function random_imglink(){
  var myimages = new Array()
    myimages[1] = "01.jpg"
    myimages[2] = "02.jpg"
    myimages[3] = "03.jpg"
    myimages[4] = "04.jpg"
    myimages[5] = "05.jpg"
    ...
    myimages[31] = "31.jpg"
							
  var rq=Math.floor(Math.random()*myimages.length)
  var rr=Math.floor(Math.random()*myimages.length)
  var rs=Math.floor(Math.random()*myimages.length)
  var rt=Math.floor(Math.random()*myimages.length)
  var ru=Math.floor(Math.random()*myimages.length)
  var rv=Math.floor(Math.random()*myimages.length)
  var rw=Math.floor(Math.random()*myimages.length)
  var rx=Math.floor(Math.random()*myimages.length)
  var ry=Math.floor(Math.random()*myimages.length)
  var rz=Math.floor(Math.random()*myimages.length)

  if (ry==0)
    ry=1
    document.write('<img src="'+myimages[rq]+'"> &nbsp;<img src="'+myimages[rr]+'"><br><img src="'+myimages[rs]+'"> &nbsp;<img src="'+myimages[rt]+'"><br><img src="'+myimages[ru]+'"> &nbsp;<img src="'+myimages[rv]+'"><br><img src="'+myimages[rw]+'"> &nbsp;<img src="'+myimages[rx]+'"><br><img src="'+myimages[ry]+'"> &nbsp;<img src="'+myimages[rz]+'">')
}
random_imglink()
</script>
I have 8 IMGs grabbing images randomly from a list of 31 JPGs & here's my dilemma:
1. I don't want the same image appearing in more than 1 spot
2. When I test this, sometimes 1 or more IMG spots return an undefined image

Any help would be greatly appreciated. Thanks in advance!
sg123 is offline   Reply With Quote