I try to add the random button to change the background color automatically, but i got this error. How to develop this code far better.
The specified value "rgb(182,22,242)" does not conform to the required format. The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.
var css = document.querySelector("h3");
var color1 = document.querySelector(".color1");
var color2 = document.querySelector(".color2");
var body = document.getElementById("gradient");
var button = document.getElementById("random");
function gradientcolor() {
    body.style.background =
        "linear-gradient(to right,"
        + color1.value
        + ","
        + color2.value
        + ")";
    css.textContent = body.style.background + ";";
}
function random() {
    var x = Math.floor(Math.random()* 255);
    var y = Math.floor(Math.random()* 255);
    var z = Math.floor(Math.random()* 255);
    color1.value = "rgb(" + x + "," + y + "," + z + ")";
}
button.addEventListener("click",random);
color1.addEventListener("input", gradientcolor);
color2.addEventListener("input", gradientcolor);body{
    background: linear-gradient(to right, red,yellow);
    text-align:center;
    font-family: 'Mukta', sans-serif;
text-transform:uppercase;
}
h1{
    color:rgba(0,0,0,0.5);
    letter-spacing: 1rem;;
    font-size: 100;
    
}
h2{
    color:rgba(0,0,0,0.5);
    letter-spacing:0.3em;
}<html>
    <head>
        <title>background generator</title>
        <link rel="stylesheet" href="style.css">
    </head>
    <body id="gradient">
        <h1> background Generator</h1>
        <input class="color1" type="color" name="color1" value="#FF0000">
        <input class="color2" type="color" name="color1" value="#00FF00">
        <h2>current css background</h2>
        <h3></h3>
        <button id="random">click me</button>
        <script type="text/javascript" src="script.js"></script>
    </body>
</html>i tried to find errors in my code, but still i dont figure it out
 
     
     
     
    