-
Notifications
You must be signed in to change notification settings - Fork 0
/
randnum.php
45 lines (39 loc) · 1004 Bytes
/
randnum.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!--
程式名稱:亂數抽獎
程式設計:梅問題&男丁格爾
作者網址:http://www.minwt.com
-->
<form id="form1" name="form1" method="post" action="">
總數:
<input type="text" name="total" id="total" />
<br />
筆數:
<input type="text" name="count" id="count" />
<br />
排除:
<input name="except" type="text" id="except" />
<br />
<input type="submit" name="button" id="button" value="送出" />
</form>
<hr>
<?php
if(isset($_POST['total']) && isset($_POST['count'])){
$POST_total = $_POST['total'];
$POST_count = $_POST['count'];
$POST_except = $_POST['except'];
$Rand = Array(); //定義陣列
$count = $POST_count ; //共產生幾筆
if(isset($_POST['except'])){
/*文字轉陣列-排除名單*/
$Rand = explode(",",$POST_except);
}
while($count > 0){
$randval = mt_rand(1,$POST_total); //取亂數
if (!in_array($randval, $Rand)) {
$count--;
$Rand[] = $randval; //若無重復則 將亂數塞入陣列
echo $randval."<br>";
}
}
}
?>