七段

无论怎样,请让我先感谢一下国家。

BlogJava 首页 新随笔 联系 聚合 管理
  35 Posts :: 2 Stories :: 7 Comments :: 0 Trackbacks
 1 function buildFunction(productList, productWeight){
 2                 var totalweight = eval(productWeight.join("+"))
 3                 var weighedProducts = new Array()
 4                 var currentProducts = 0
 5                 while (currentProducts < productList.length) {
 6                     for (i = 0; i < productWeight[currentProducts]; i++) {
 7                         weighedProducts.push(productList[currentProducts]);
 8                     }
 9                     currentProducts++
10                 }
11                 return function(){
12                     var randomnumber = Math.floor(Math.random() * totalweight)
13                     return (weighedProducts[randomnumber]);
14                 };
15             };
16             var productList = ["AK-47""Blade""Food""ByondGod"]
17             var productWeight = [2002041];
18             var myFun = buildFunction(productList, productWeight);
19             for (var i = 0; i < 100; i++
20                 document.writeln((i+1)+":"+myFun())
posted on 2009-12-11 13:56 sevenduan 阅读(592) 评论(0)  编辑  收藏 所属分类: JavaScript

只有注册用户登录后才能发表评论。


网站导航: