<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>
①自JavaScript产生后,好多浏览器中都有内置的随机数发生方法。例如:
var number = Math.random();
该方法产生一个0到1之间的浮点数。
②基于时间,亦可以产生随机数。例如:
var now=new Date();
var number = now.getSeconds();
这将产生一个基于目前时间的0到59的整数。
var now=new Date();
var number = now.getSeconds()%43;
这将产生一个基于目前时间的0到42的整数。
③这里介绍一个相当优秀的的随机数发生器程序,能应用于许多领域。
<script language="JavaScript"><!--
// The Central Randomizer 1.3 (C) 1997 by Paul Houle (houle@msc.cornell.edu)
// See: http://www.msc.cornell.edu/~houle/javascript/randomizer.html
rnd.today=new Date();
rnd.seed=rnd.today.getTime();
function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};
function rand(number) {
return Math.ceil(rnd()*number);
};
// end central randomizer. -->
</script>