点击这里给我发消息 点击这里给我发消息

测试产生随机数字的JS程序

添加时间:2013-12-7
    相关阅读: 程序 JavaScript

  01 <SCRIPT LANGUAGE="JavaScript">

  02 <!-- Begin

  03 function numbers() {

  04 var nummenu = document.lotto.numbercount;

  05 var numbercount = nummenu.options[nummenu.selectedIndex].value*1;

  06 var maxnumbers = document.lotto.maxnum.value*1;

  07 if (numbercount > maxnumbers) {

  08 alert("Be sure to select a max lottery number value!");

  09 }

  10 else {

  11 var ok = 1;

  12 r = new Array (numbercount);

  13 for (var i = 1; i <= numbercount; i++) {

  14 r[i] = Math.round(Math.random() * (maxnumbers-1))+1;

  15 }

  16 for (var i = numbercount; i >= 1; i--) {

  17 for (var j = numbercount; j >= 1; j--) {

  18 if ((i != j)  &&  (r[i] == r[j])) ok = 0;

  19    }

  20 }

  21 if (ok) {

  22 var output = "";

  23 for (var k = 1; k <= numbercount; k++) {

  24 output += "Number " + k + " = " + r[k] + "\n";

  25 }

  26 document.lotto.results.value = output;

  27 }

  28 else numbers();

  29    }

  30 }

  31 //  End -->

  32 </script>

  33 <form name="lotto">

  34 <table width=100% border=0>

  35 <tr>

  36 <td align=center>生成随机数的个数

  37 <select name="numbercount">

  38 <option value="1">1

  39 <option value="2">2

  40 <option value="3">3

  41 <option value="4">4

  42 <option value="5">5

  43 <option value="6">6

  44 <option value="7" selected>7

  45 <option value="8">8

  46 <option value="9">9

  47 <option value="10">10

  48 </select>

  49

  50 产生数字范围<input type=text name=maxnum value="50" size=2 maxlength=2>

  51 <input type=button value="生成随机数" onClick="numbers()">

  52 <textarea name="results" rows=11 cols=15>

咨询热线:020-85648757 85648755 85648616 0755-27912581 客服:020-85648756 0755-27912581 业务传真:020-32579052
广州市网景网络科技有限公司 Copyright◎2003-2008 Veelink.com. All Rights Reserved.
广州商务地址:广东省广州市黄埔大道中203号(海景园区)海景花园C栋501室
= 深圳商务地址:深圳市宝源路华丰宝源大厦606
研发中心:广东广州市天河软件园海景园区 粤ICP备05103322号 工商注册