Click to See Complete Forum and Search --> : random image help


esthera
09-05-2003, 07:22 AM
The following is my code for a random image display based on percentages. Can someone help me with what code I need to ad in so that the no image displays twice in row.

<script language='Javascript'>
var count1=90
var count2=60
var count3=70
var count4=50
var tot=count1+count2+count3+count4;
count1=adjust_percentages(tot,count1);
count2=adjust_percentages(tot,count2);
count3=adjust_percentages(tot,count3);
count4=adjust_percentages(tot,count4);
var timer;
window.onload = randomad;
function randomad(){
var randomnumber=Math.floor(Math.random()*101);
bannerpicture.style.display = 'inline';
if (randomnumber <=count1)
bannerpicture.src=pic1.src;
else if ((randomnumber >count1) && (randomnumber <=count2))
bannerpicture.src=pic2.src;
else if ((randomnumber >count2) && (randomnumber <=count3))
bannerpicture.src=pic3.src;
else if ((randomnumber >count3) && (randomnumber <=count4))
bannerpicture.src=pic4.src;
clearTimeout(timer)
timer =setTimeout('randomad()',2000)
}
function adjust_percentages(tot, val) {
return (val/tot)*100;
}</script >



<img id='bannerpicture' style="display:none">


<img id='pic1' src='9_5_2003_72.29034.jpg' style="display:none"><br>


<img id='pic2' src='9_5_2003_47.24577.jpg' style="display:none"><br>


<img id='pic3' src='9_5_2003_98.11892.jpg' style="display:none"><br>


<img id='pic4' src='9_5_2003_80.99.jpg' style="display:none"><br>




</body>

Gollum
09-05-2003, 08:02 AM
all you have to do is set a variable to record what the image is before you change it and you just repeat your random bit until you get a change.