-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
101 lines (85 loc) · 2.93 KB
/
index.html
File metadata and controls
101 lines (85 loc) · 2.93 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html>
<head>
<title>RandgedNum</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta name="viewport" content="initial-scale=1"/>
<style>
html, body {
height: 100%;
background-color: lightgray;
}
div.module {
background-color: white;
margin: 5px;
padding: 10px;
border-radius: 5px;
}
#contents {
margin: auto;
width: 100%;
height: 100%;
}
#title, #description {
text-align: center;
}
</style>
</head>
<body>
<div id="contents">
<h1 id="title">ランダムな数を生成するだけ</h1>
<div id="description">
<p>
指定された範囲と個数の、重複しない乱数を生成します。
</p>
</div>
<div id="operator" class="module">
<form name="values">
<p>範囲: <input name="range_min" type="text" value="1"/>〜<input id="range_max" type="text" value="16"/></p>
<p>個数: <input name="count" type="text" value="4"/></p>
<input id="calc" type="button" value="実行"/>
</form>
</div>
<div id="display" class="module">
<p id="result">値: </p>
</div>
</div>
<script>
document.getElementById("calc").onclick = function() {
let form = document.forms.values;
const log = console.log;
const min = Number(form.range_min.value);
const max = Number(form.range_max.value);
const count = Number(form.count.value);
log("min / max / count = " + min + " / " + max + " / " + count);
if(min >= max) {
alert("最小値は最大値よりも小さい必要があります。");
return;
}
if(count <= 0 || count - Math.floor(count) != 0) {
alert("個数には1以上の整数を入力してください。");
return;
}
if(max - min + 1 < count) {
alert("範囲に対して個数が多すぎます。");
return;
}
const range = (max - min + 1) / count;
log("range = " + range);
let results = "値: ";
let pmin = min;
let pmax = min + range - 0.0001;
for(let i=0 ; i < count ; ++i) {
log("pmin / pmax = " + pmin + " / " + pmax);
let num = Math.random() * (pmax - pmin) + pmin;
log(">" + num);
results += Math.floor(num) + ", ";
pmin = Math.ceil(num);
pmax = pmax + range;
}
document.getElementById("result").innerHTML = results;
log("_/_/_/_/_/_/_/_/_/_/");
}
</script>
</body>
</html>