<div class="htmlarea"> <textarea id="runcode13123"> <script language="Javascript"> <!-- //BANNER ROTATOR var tag1 = new Array(); var urlArray = new Array(); //********************************************************// //****START 6-6***// urlArray[urlArray.length]="http://s.jb51.net"; tag1[tag1.length] ="http://img.jb51.net/imgby/server.gif"; urlArray[urlArray.length]="http://www.jb51.net"; tag1[tag1.length] ="http://www.jb51.net/images/logo.gif"; //****END 6-25***// var adsAry_length = tag1.length; var now = new Date(); //MOD 20090522var sec = now.getSeconds(); //MOD 20090522 var ad = sec % adsAry_length; var sec =now.getTime(); var ad = rand(adsAry_length) var url = urlArray[ad-1]; var banner = tag1[ad-1]; //DEL alert("urlArray[" +(ad-1)+"]=" + urlArray[ad-1]) //DEL 20090522 if(ad <= tag1.length){ //DEL 20090522 url=urlArray[ad]; //DEL 20090522 banner=tag1[ad]; //DEL 20090522} //DEL 20090522 document.write('<center>'); document.writeln('<a href="' + url + '" target=\"_blank\">'); document.writeln('<img src="' + banner + '" alt="javascript 随机广告代码(图片广告)_广告代码" >'); //DEL 20090522 document.write('<\center>'); //****************************************************/ //rnd() //****************************************************/ function rnd() { var ia=9301; var ic=49297; var im=233280; sec = (sec*ia+ic) % im; return sec/(im*1.0); }; //****************************************************/ //rand(number) //****************************************************/ function rand(number) { return Math.ceil(rnd()*number); }; // --></script> </textarea><br><input onclick="runEx('runcode13123')" type="button" value="运行代码"> <input onclick="doCopy('runcode13123')" type="button" value="复制代码"> <input onclick="doSave(runcode13123)" type="button" value="保存代码">[Ctrl+A 全选 注:<a href="http://www.jb51.net/article/23421.htm" title="查看具体详情" target="_blank">如需引入外部Js需刷新才能执行</a>]</div> <br>这个里面有个不错的随机函数代码,具体的没看懂。知道的朋友可以回复下。<br><div class="codetitle"> <span><a style="CURSOR: pointer" data="4837" class="copybut" id="copybut4837" onclick="doCopy('code4837')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code4837"> <br>function rnd() { <br>var ia=9301; <br>var ic=49297; <br>var im=233280; <br>sec = (sec*ia+ic) % im; <br>return sec/(im*1.0); <br>}; <br> </div>