0

I am making a Random number generator and it generated by using timestamp mixed with random alphabet letters. below is my code for generating a random number

 var ts = String(new Date().getTime()),
          i = 0,
          out = '';
  
      for (i = 0; i < ts.length; i += 3) {
          out += Number(ts.substr(i, 2)).toString(36);
      }
      
       var ans = Math.random().toString(15).slice(5);
       var para = (out + ans);
       
            
  
      var chassis = (para.slice(0, 15));
      console.log(chassis);
      document.getElementById("output").innerHTML = chassis;
      
     // OUTPUT is like this:- g81x292daaba1ba

with this code generate one unique number every time when i was click on a button. But now I want to make a text field where i can write how many unique random number i want to generate. For Example if I write 10 on the text field then I want 10 unique random number to be generated. This is the code i was trying but it gives me undefined output

  const unit = document.getElementById('unit');
      var ts = String(new Date().getTime()),
      i = 0,
      out = '';
      for( j=0; j<=unit;j++) //unit is the id of input type="text"
      {
      
    for (i = 0; i < ts.length; i += 3) {
        out += Number(ts.substr(i, 2)).toString(36);
    
    
     var ans = Math.random().toString(15).slice(5);
     var para = (out + ans);
     
          

    var chassis = (para.slice(0, 15));
    console.log(chassis);
    
    document.getElementById("output").innerHTML = chassis;
       
    } 
MOHAMMAD ZEESHAN
  • 273
  • 3
  • 15
  • `const unit = document.getElementById('unit');` -> `const unit = document.getElementById('unit').value;` *or* `j<=unit` -> `j<=unit.value`. In either case, you'd get a string and it's a good idea to use numbers. – VLAZ Aug 19 '22 at 09:47
  • @VLAZ still print only one value. I am giving the link of code sand box for your better understanding- https://codesandbox.io/embed/practical-lake-6k7r34?fontsize=14&hidenavigation=1&theme=dark – MOHAMMAD ZEESHAN Aug 19 '22 at 10:53

0 Answers0