Javascript random strings script, random number

Javascript random strings script, javascript random number script, random character

1

javascript random string and number

vc9uVH6qaSuLPBWJAUid
<input type="button" onclick="get_random_chars(10)" value="random text">
<div id="random-char-text"></div>

<script>
  function random_chars(length = 0) {
      let result = "";
      let chars = "1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
      for (var i = 0; i < length; i++) {
          result += chars[Math.floor(Math.random() * chars.length)];
      }
      return result;
  }

  function get_random_chars(length) {
      let result = random_chars(length);
      document.getElementById("random-char-text").innerText = result;
  }
</script>
2

javascript random number

06038139811258919436
<input type="button" onclick="get_random_number(10)" value="random number">
<div id="random-number-text"></div>

<script>
 function random_number(length = 0) {
     let result = "";
     let chars = "1234567890";
     for (let i = 0; i < length; i++) {
         result += chars[Math.floor(Math.random() * chars.length)];
     }
     return result;
 }

 function get_random_number(length) {
     let result = random_number(length);
     document.getElementById("random-number-text").innerText = result;
 }
</script>
3

random letters lowercase only

kwilwrugqxosyztnzawg
<input type="button" onclick="get_random_lowercase(10)" value="random text">
<div id="random-lower-text"></div>

<script>
  function random_lowercase(length = 0) {
      let result = "";
      let chars = "abcdefghijklmnopqrstuvwxyz";
      for (var i = 0; i < length; i++) {
          result += chars[Math.floor(Math.random() * chars.length)];
      }
      return result;
  }

  function get_random_lowercase(length) {
      let result = random_lowercase(length);
      document.getElementById("random-lower-text").innerText = result;
  }
</script>
4

random letter uppercase only

ZPZXMVZDJCBROJAYRIPN
<input type="button" onclick="get_random_uppercase(10)" value="random text">
<div id="random-upper-text"></div>

<script>
function random_uppercase(length = 0) {
    let result = "";
    let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (let i = 0; i < length; i++) {
        result += chars[Math.floor(Math.random() * chars.length)];
    }
    return result;
}

function get_random_uppercase(length) {
    let result = random_uppercase(length);
    document.getElementById("random-upper-text").innerText = result;
}
</script>
5

random number between (1000 2000)

1500
<input type="button" onclick="get_number_between(10, 20)" value="Number between">
<div id="number-btwn-text"></div>

<script>
  function number_between(min_number, max_number) {
      let min = Math.ceil(min_number);
      let max = Math.floor(max_number + 1);
      let result = Math.floor(Math.random() * (max - min)) + min;
      return result;
  }

  function get_number_between(min, max) {
      let result = number_between(min, max);
      document.getElementById("number-btwn-text").innerText = result;
  }
</script>
6

Javascript generate random password

knHTY78*$#
<input type="button" onclick="get_random_password(10)" value="Random Password">
<div id="random-password"></div>

<script>
  function random_password(length = 8) {
      let result = "";
      let chars = "1234567890";
      chars += "abcdefghijklmnopqrstuvwxyz";
      chars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      chars += "~!@#$%^&*()_+}{></[]|-,:;'\".?";
      for (var i = 0; i < length; i++) {
          result += chars[Math.floor(Math.random() * chars.length)];
      }
      return result;
  }

  function get_random_password(length) {
      let result = random_password(length);
      document.getElementById("random-password").innerText = result;
  }
</script>