-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom.html
More file actions
47 lines (46 loc) · 1014 Bytes
/
Copy pathRandom.html
File metadata and controls
47 lines (46 loc) · 1014 Bytes
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
<body>
</body>
<script>
function random(a,b){
return Math.floor((Math.random() * (b-a+1))) + a;
}
let p = 0;
for(let i = 0; i < 1000; i++){
p = p + Math.floor(Math.random() * 6 + 1);
}
p = p/1000;
function snakeEyes(flip){
let count = 0;
for(let i = 0; i < flip; i++){
if(Math.floor(Math.random() * 6 +1) == 1 && Math.floor(Math.random() * 6 + 1) == 1){
count = count + 1;
}
}
count = count/flip;
return count;
}
console.log(snakeEyes(100000000));
function flipCoins(c) {
let count = 0;
for(let i = 0; i < c; i++){
if(Math.floor(Math.random() * 2) == 1){
count = count + 1;
}
}
if(count == c){
return 1;
}
return 0;
}
function flips(){
let count = 0;
for(let i = 0; i < 1000; i ++){
count = count + flipCoins(5);
}
return count/1000;
}
function randomNamePick(names){
let index = Math.floor(Math.random() * names.length);
return names[index];
}
</script>