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>