<script src="https://cdnjs.cloudflare.com/ajax/libs/react/17.0.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/17.0.2/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.26.0/babel.min.js"></script>
<script type="text/babel">
// Add the import statement for useState hook
const { useState } = React;
// Define the App component
const [generatedNumbers, setGeneratedNumbers] = useState([]);
const generateRandomNumber = () => {
const randomNumber = Math.floor(Math.random() * (maxNumber - minNumber + 1)) + minNumber;
// Check if the generated number already exists in the state
if (generatedNumbers.includes(randomNumber)) {
// If it exists, generate a new number recursively
return generateRandomNumber();
// If the number is unique, add it to the state
setGeneratedNumbers([...generatedNumbers, randomNumber]);
<div className='container'>
<h3>React Js Generate Random Number betwwen 1-100 without Repetation</h3>
<button onClick={generateRandomNumber}>Generate Random Number</button>
{/* Reverse the array to show the latest number first */}
{generatedNumbers.slice().reverse().map((number, index) => (
<p key={index}>{number}</p>
ReactDOM.render(<App />, document.getElementById("app"));
font-family: Arial, sans-serif;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
/* Styles for the button */
background-color: #4caf50;
transition: background-color 0.3s;
.container button:hover {
background-color: #45a049;
/* Styles for the generated number */