RNG tool
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>RNG Tool</title>
</head>
<body>
<div class="stars"></div>
<h1>Random Number Generator</h1>
<p class="description">This tool randomly generates a value from 0-5000000000</p>
<p class="reveal">Your randomly generated number is:</p>
<p class="number"><span id="randomNum"></span></p>
<button onclick="randomNumGen()">Generate</button>
</body>
</html>
CSS
@keyframes moveGradient {
from {
background-position: 0 0;
}
to {
background-position: 400px 0;
}
}
body {
font-family: Arial, sans-serif;
text-align: center;
background: #1b1e24;
color: white;
}
button {
padding: 10px 20px;
border: none;
border-radius: 8px;
color: white;
font-size: 18px;
cursor: pointer;
background: repeating-linear-gradient(
145deg,
#534ed9 0px,
#a4a2e0 100px,
#534ed9 200px
);
background-size: 300% 300%;
animation: gradientMove 1s linear infinite;
}
button:hover {
transform: scale(1.05);
}
.number {
margin-bottom: 20px;
}
#randomNum {
display: none;
padding: 6px 12px;
border: 3px;
border-style: solid;
border-color: red;
border-radius: 8px;
color: white;
font-size: 16px;
background: rgba(245, 0, 0, 0.4);
}
#randomNum.show {
display: inline-block
}
.stars {
position: fixed;
inset: 0;
pointer-events: none;
z-index: -1;
}
.stars span {
position: absolute;
display: block;
background: white;
border-radius: 50%;
animation: twinkle 2s infinite alternate;
}
@keyframes twinkle {
from {
opacity: 0.2;
}
to {
opacity: 1;
}
}
JavaScript
function randomNumGen() {
const randomNum = Math.floor(Math.random() * 5000000001) + 1;
console.log(randomNum);
const output = document.getElementById("randomNum");
output.textContent = randomNum;
output.classList.add("show");
} ;
const stars = document.querySelector(".stars");
for (let i = 0; i < 150; i++) {
const star = document.createElement("span");
star.style.left = Math.random() * 100 + "%";
star.style.top = Math.random() * 100 + "%";
const size = Math.random() * 3 + 1;
star.style.width = size + "px";
star.style.height = size + "px";
star.style.animationDelay = Math.random() * 4 + "s";
stars.appendChild(star);
}