UID generator v1
by vvv vvvv
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Générateur de chaîne de caractères</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f0f0;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background-color: #ffffff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
max-width: 400px;
width: 100%;
position: relative;
}
h1 {
text-align: center;
color: #333333;
}
label {
display: block;
margin-top: 10px;
font-weight: bold;
color: #555555;
}
input[type="number"] {
width: 100%;
padding: 10px;
margin-top: 5px;
border: 1px solid #cccccc;
border-radius: 5px;
box-sizing: border-box;
}
button {
width: 100%;
padding: 10px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 5px;
font-size: 16px;
margin-top: 20px;
cursor: pointer;
}
button:hover {
background-color: #45a049;
}
p {
text-align: center;
font-size: 18px;
color: #333333;
}
#output {
font-weight: bold;
color: #007BFF;
}
#copiedMessage {
display: none;
position: absolute;
bottom: -30px;
left: 50%;
transform: translateX(-50%);
background-color: #007BFF;
...
JavaScript
document.getElementById('form').addEventListener('submit', function(event) {
event.preventDefault();
const length = parseInt(document.getElementById('length').value);
const numDigits = parseInt(document.getElementById('numbers').value);
const maxDigits = parseInt(document.getElementById('maxDigits').value);
const allowedLetters = 'abcdefghjkmnpqrstuvwxyz'; // Exclut les lettres 'l', 'i', et 'o'
const digits = '123456789'; // Exclut le chiffre '0'
if (numDigits > length) {
alert("Le nombre de chiffres ne peut pas être supérieur à la longueur totale de la chaîne.");
return;
}
// Crée des tableaux séparés pour les chiffres et les lettres
let digitsArray = [];
let letters = [];
// Génère les chiffres nécessaires
for (let i = 0; i < numDigits; i++) {
digitsArray.push(digits[Math.floor(Math.random() * digits.length)]);
}
// Génère les lettres nécessaires
for (let i = 0; i < length - numDigits; i++) {
letters.push(allowedLetters[Math.floor(Math.random() * allowedLetters.length)]);
}
// Fusionne les tableaux
let combinedArray = digitsArray.concat(letters);
// Mélange les caractères avec Fisher-Yates Shuffle
for (let i = combinedArray.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[combinedArray[i], combinedArray[j]] = [combinedArray[j], combinedArray[i]];
}
// Applique la contrainte de chiffres consécutifs
let finalString = '';
let currentDigitCount = 0;
let digitsUsed = 0;
for (const char of combinedArray) {
if (digits.includes(char)) {
currentDigitCount++;
digitsUsed++;
if (currentDigitCount > maxDigits) {
// Remplace le caractère actuel par une lettre si trop de chiffres consécutifs
finalString += allowedLetters[Math.floor(Math.random() * allowedLetters.length)];
...