-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonline-generate-random-string.html
More file actions
136 lines (123 loc) · 4.69 KB
/
Copy pathonline-generate-random-string.html
File metadata and controls
136 lines (123 loc) · 4.69 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
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
132
133
134
135
136
---
title: "Online Rasgele Sicim Üret (Online Generate Random String)"
date: null
layout: calculate
permalink: null
categories: null
tags: null
---
<script>
function generateRandomString(alphabet, length) {
let result = '';
let alphabetLength = alphabet.length;
for (let i = 0; i < length; i++) {
result += alphabet.charAt(Math.floor(Math.random() * alphabetLength));
}
return result;
}
function calculateProbability(n, r) {
return Math.pow(n, r);
}
</script>
<div class="form-group">
<div class="input-group">
<div class="input-group-prepend">
<label class="input-group-text" for="alphabet">Alfabe</label>
</div>
<input id="alphabet" type="text" class="form-control" placeholder="Karakterler" autocomplete="off" value="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" />
</div>
<div class="input-group mt-3">
<div class="input-group-prepend">
<label class="input-group-text" for="length">Uzunluk</label>
</div>
<input id="length" type="number" class="form-control" placeholder="Uzunluk" autocomplete="off" value="8" />
</div>
<button id="generate" type="button" class="form-control mt-3 mb-3 btn btn-primary"><i class="bi-caret-down-fill"></i></button>
<div class="input-group">
<input id="result" type="text" class="form-control text-monospace" data-clipboard-target="#result" placeholder="Sonuç" readonly="readonly" />
<div class="input-group-append">
<button id="copy" type="button" class="form-control btn btn-warning" data-clipboard-target="#result" disabled="disabled"><i class="bi-clipboard2-plus-fill"></i></button>
</div>
</div>
<div class="input-group mt-3">
<div class="input-group-prepend">
<label class="input-group-text" for="probability">Olasılık Sayısı</label>
</div>
<input id="probability" type="number" class="form-control" autocomplete="off" readonly="readonly" />
</div>
</div>
<script>
function writeRandomString() {
let alphabet = $("#alphabet").val();
let length = $("#length").val();
let result = generateRandomString(alphabet, length);
$("#result").val(result);
$("#copy").prop("disabled", false);
}
function writeProbability() {
let alphabet = $("#alphabet").val();
let alphabetLength = alphabet.length;
let length = $("#length").val();
let result = calculateProbability(alphabetLength, length);
$("#probability").val(result);
}
$(function() {
$("#alphabet").on("change", function (e) {
if ($(this).val().length < 2) {
$(this).val("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789");
}
writeRandomString();
writeProbability();
});
$("#length").on("change", function (e) {
if ($(this).val().length < 1) {
$(this).val("8");
}
writeRandomString();
writeProbability();
});
$("#generate").on("click", function (e) {
writeRandomString();
writeProbability();
});
$("#result").tooltip({
trigger: "manual",
title: "Kopyalandı...",
placement: "top",
customClass: "tooltip-success"
});
$("#copy").on("click", function (e) {
let result = $("#result").val();
if (result.length === 0) {
console.log("Result is empty and it has not been copied");
return;
}
copyToClipboard(result)
.then(function () {
$("#result").tooltip('show');
setTimeout(function() {
$("#result").tooltip('hide');
}, 1500);
}).catch(function () {
console.error('Copying result to clipboard has failed');
});
});
$("#result").on("click", function (e) {
let result = $("#result").val();
if (result.length === 0) {
console.log("Result is empty and it has not been copied");
return;
}
copyToClipboard(result)
.then(function () {
$("#result").tooltip('show');
setTimeout(function() {
$("#result").tooltip('hide');
}, 1500);
}).catch(function () {
console.error('Copying result to clipboard has failed');
});
});
});
</script>
{% include calculate_menu.html %}