Click to See Complete Forum and Search --> : Random allocation of array content to layers


Pylo
04-29-2004, 09:54 AM
Hi,

I have an array of 10 blocks of text/basic html. I want to allocate these randomly (with no repeats) to 10 layers. Can anyone advise how to go about this please?

The blocks are small adverts with links, the client wants the allocated randomly onLoad to ensure no advertiser consistently gets top spot.

Thanks very much in advance :)

Pylo

neil9999
04-29-2004, 10:57 AM
Maybe you could adapt this:

<body>
<script type="text/javascript">
d=new Array();
e=0;
c=0;
//Enter ads here and remove new lines in the array.
b=["<p><b>Company A</b></p>","<p><b>Company B</b></p>","<p><b>Company C</b></p>","<p><b>Company D</b></p>","<p><b>Company E</b></p>","<p><b>Company F</b></p>"];
while(c<b.length){
f=b[Math.round(Math.random()*b.length-0.5)]
if(d[f]!=1){
document.write(f);
d[f]=1
c++
}
}
</script>
</body>

Hope this helps,

Neil