Q:

How to make a random number generator and copy it to the clipboard

I am not much of a programmer yet, but I really want to make a text box that uses Javascript to randomly select characters, then output those characters into an HTML text field, with a button on the side to copy the characters in that text field.
Here is a picture of what I am looking for
I found a couple of code snippets on the internet, but I am not sure how to put them all together.  If you could help me, I would appreciate it so much!
And if you are just passing by I hope that you have a fantastic day!
HTML
<input type="text" value="Hello World" id="myInput">
<button onclick="myFunction()">Copy text</button>

CSS
.tooltip {
  position: relative;
  display: inline-block;
}

    .tooltip .tooltiptext {
      visibility: hidden;
      width: 140px;
      background-color: #555;
      color: #fff;
      text-align: center;
      border-radius: 6px;
      padding: 5px;
      position: absolute;
      z-index: 1;
      bottom: 150%;
      left: 50%;
      margin-left: -75px;
      opacity: 0;
      transition: opacity 0.3s;
    }

    .tooltip .tooltiptext::after {
      content: "";
      position: absolute;
      top: 100%;
      left: 50%;
      margin-left: -5px;
      border-width: 5px;
      border-style: solid;
      border-color: #555 transparent transparent transparent;
    }

    .tooltip:hover .tooltiptext {
      visibility: visible;
      opacity: 1;
    }

JAVASCRIPT (For "Copy to Clipboard" button)
function myFunction() {
  var copyText = document.getElementById("myInput");

  copyText.select();

  document.execCommand("Copy");

  alert("Copied the text: " + copyText.value);
}

JAVASCRIPT (For Random Character generator)
(Right now it only displays it in the console log)
var randomString = function(length) {
    var text = "";
    var possible = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890!?";
    for(var i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    }
    return text;
}

var rs = randomString(10);

console.log("Our Random String Is: " + rs);

A:

Make a copyText function that you can send your generated string into:

const input = document.querySelector('input');
function copyText(text) {
  input.value = text;
  input.select();
  document.execCommand("Copy");
  console.log("Copied");
}

const randomString = function(length) {
  let text = "";
  const possible = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890!?";
  for(let i = 0; i < length; i++) {
    text += possible.charAt(Math.floor(Math.random() * possible.length));
  }
  return text;
}

input.addEventListener('click', () => {
  const rs = randomString(10);
  copyText(rs);
});
<input>

(you have to click the input for the event to occur due to browser security)

