Skip to content

Commit

Permalink
rand
Browse files Browse the repository at this point in the history
  • Loading branch information
hatrd committed Jul 18, 2024
1 parent cff0c66 commit 5d07ac2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ <h1>hash</h1>
<p>哈希工具。</p>
</div>

<div class="tool-box" onclick="window.location.href='rand/index.html'">
<h1>rand</h1>
<p>随机字符串生成工具。</p>
</div>

<div class="tool-box" onclick="window.location.href='qr/index.html'">
<h1>qr</h1>
<p>二维码扫码工具。</p>
Expand Down
55 changes: 55 additions & 0 deletions rand/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<!DOCTYPE html>
<html>
<head>
<title>Random Generator</title>

</head>
<body>
<h1>Random Generator</h1>

<div>
<p id="result">result</p>
<button onclick="generateRandomString()">Generate&Copy</button>
<button onclick="setCharacterRangeDigits()">0-9</button>
<button onclick="setCharacterRangeLetters()">A-Za-z</button>
<button onclick="setCharacterRangeDigitsAndLetters()()">A-Za-z0-9</button>
<button onclick="setCharacterRangeAll()">+Special Characters</button>
<br>
<textarea id="characterRange" rows="4" cols="50">abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789</textarea>
<br>
<input type="text" id="characterLength" placeholder="characterLength default 15">
</div>

<script>
function generateRandomString() {
const length = document.getElementById("characterLength").value || 15;
const characterRange = document.getElementById("characterRange").value || 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let result = '';
const charactersLength = characterRange.length;

for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charactersLength);
result += characterRange[randomIndex];
}
navigator.clipboard.writeText(result);
document.getElementById("result").textContent = result;
}
function setCharacterRangeDigits() {
document.getElementById("characterRange").value = '0123456789';
}

function setCharacterRangeLetters() {
document.getElementById("characterRange").value = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
}
function setCharacterRangeDigitsAndLetters() {
document.getElementById("characterRange").value = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
}
function setCharacterRangeAll() {
document.getElementById("characterRange").value = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+-={}[]|:;"<>,.?/~`\'';
}
window.onload = function() {
generateRandomString();
};
</script>
</body>
</html>

0 comments on commit 5d07ac2

Please sign in to comment.