-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaiym_finalProject.html
131 lines (96 loc) · 3.99 KB
/
aiym_finalProject.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<!DOCTYPE html>
<html>
<head>
<title>FinalProject</title>
</head>
<body>
<h1>Random Numbers Generator</h1>
<form id="randomForm">
<label>От:</label>
<input type="number" id="min" required value="1">
<label>До:</label>
<input type="number" id="max" required value="100">
<input type="submit" value="Сгенерировать">
</form>
<span id="resultNumber"></span>
<script>
class RandomGenerator{
// Date.now() - time in milliseconds. 1 s = 1000 ms
constructor(
seed=42,
a=1664525,
bias=1013904223,
max=Math.pow(2, 32), // 4,294,967,296
isSeedEnhanced=true,
){
console.log({seed, a, bias, max});
this.seed = seed;
this.a = a;
this.bias = bias;
this.max = max;
this.isSeedEnhanced = isSeedEnhanced;
}
next(){
if(this.isSeedEnhanced){
this.seed *= (Date.now() % 1000);
}
// 1,664,525 * 42 + 1,013,904,223 = 1,083,814,273
this.seed = (this.a * this.seed + this.bias) % this.max;
return this.seed;
}
random(){
// this.next(), this.seed < this.max
return this.next() / this.max; // [0; 1)
}
}
function convertRanges(min, max, value){
return min + (value * (max - min));
}
</script>
<script>
(function(){
// const random = new RandomGenerator(0, 1, 1, 10, false);
const random = new RandomGenerator();
for(let i=0; i<20; i++){
console.log(random.random());
}
const randomForm = document.getElementById('randomForm');
randomForm.addEventListener('submit', function (event) {
event.preventDefault(); // Предотвращаем отправку формы по умолчанию
// Получаем значения полей формы
const min = Number(document.getElementById('min').value);
const max = Number(document.getElementById('max').value);
const randomNumber = Math.round(convertRanges(min, max, random.random()));
const resultNumber = document.getElementById('resultNumber');
resultNumber.textContent = `Сгенерированное число: ${randomNumber}`;
});
})()
</script>
<h1>Password Generator</h1>
<form id="randomPasswordForm">
<label>Количество символов</label>
<input type="number" id="symbols" required value="10">
<input type="submit" value="Сгенерировать">
</form>
<span id="resultPassword"></span>
<script>
(function(){
const random = new RandomGenerator();
const randomForm = document.getElementById('randomPasswordForm');
randomForm.addEventListener('submit', function (event) {
event.preventDefault(); // Предотвращаем отправку формы по умолчанию
// Получаем значения полей формы
const symbols = Number(document.getElementById('symbols').value);
let password = "";
for(let i=0; i<symbols; i++){
const randomNumber = Math.round(convertRanges(33, 126, random.random()));
console.log(randomNumber);
password += String.fromCharCode(randomNumber);
}
const resultPassword = document.getElementById('resultPassword');
resultPassword.textContent = `Сгенерированный пароль: ${password}`;
});
})()
</script>
</body>
</html>