-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path043Math对象.html
64 lines (49 loc) · 1.24 KB
/
043Math对象.html
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<style type="text/css">
</style>
<script src="js/common.js"></script>
<body>
<span id="checkcode"></span><button onclick="createCode(10)">生成验证码</button>
</body>
<script type="text/javascript">
//for(var i=0; i<10; i++) log( randomInt(99,100) );
//log(123);
function createCode(len){
var str = "";
for(var i=0; i<len; i++) {
/*
for( var ascii = randomInt(48,90); ascii >=58 && ascii <=64 ; ascii = randomInt(48,90)) {
}
*/
var ascii = randomInt(48,90);
while(ascii >=58 && ascii <=64) { //随机结果不符合要求
ascii = randomInt(48,90);
}
//console.log(ascii);
str += String.fromCharCode(ascii);
}
console.log(str);
}
var count = 0; //总攻击次数
var pcount = 0; //暴击次数
var fixp = 0.2; //期望概率
var c = 0.0557; //种子
for(var i=0; i<10000; i++) {
var num = Math.random();
if(num <= fixp){
//暴击发生了
pcount++;
fixp = c;
} else {
fixp += c;
}
count++;
}
console.log(pcount/count);
</script>
</html>